db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel John Debrunner <...@apache.org>
Subject Re: Double.NaN in table?
Date Wed, 19 Dec 2007 16:27:05 GMT
David wrote:
>  For an application I am writing I need to store doubles in a table. I 
> thought I could use the DOUBLE type when creating the columns in my tables. 
> Unfortunately the insert fails when the value of the double is Double.NaN. 
> We use NaN a lot in our analysis. Is there a way to make this work, or 
> should we just convert everything to a string?

> 
> Any ideas?

One possible alternative is to use a BIGINT column.

Use the java method Double.doubleToLongBits() when storing the value in 
the database, e.g.

     double myDouble = ...;

     ps.setLong(1, Double.doubleToLongBits(myDouble));

and Double.longBitsToDouble() when reading values, e.g.

    double myDouble = Double.longBitsToDouble(rs.getLong(1));

I haven't tried this, and you should probably read the descriptions for 
those methods, they have some detailed info on Nans. There is also the 
doubleToRawLongBits() method that could be used.

No idea on how indexing on the BIGINT column would work with this 
approach, ie. if the index order would be useful.

HTH,
Dan.


Mime
View raw message