Hi Thomas,
 

> As I wrote before, H2 uses Double.compare(x, y), which first checks the 
> sign.
>

Well, I am strongly questioning that choice. You should probably do the 
following instead: "x == y? 0: Double.compare(x, y)".
This could lead to a discussion on the NaN, but I think either choice is 
right from an SQL point of view. My suggestion does not change anything for 
NaN but fixes the -0.0 issue.
 

> H2 does not seem to behave properly when comparing negative zeros to zeros.
>>
>
> Well it depends on what you think is "proper"...
>

I think proper means as described in the JLS:
http://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.2.3

"Positive zero and negative zero compare equal; thus the result of the 
expression 0.0==-0.0 is true and the result of 0.0>-0.0 is false. But other 
operations can distinguish positive and negative zero; for example, 1.0/0.0 
has the value positive infinity, while the value of 1.0/-0.0 is negative 
infinity."

I understand you use Double objects, that is the object wrapper. But it 
should behave like the primitive type, or else we get into troubles when we 
run simple arithmetic operations.
 

> I would probably avoid using negative zeroes. I don't know why they are 
> even supported in Java.
>

We cannot avoid using them. Try this:
SELECT CAST(-1 AS DOUBLE) * CAST(0 AS DOUBLE)

So, you have a column with a -1, which you need to multiply with a column 
containing a zero. Then you are doomed for the rest of your SQL code, 
because you have to test whether data is zero and negative zero. All this 
because H2 does not use doubles and floats like primitive types, but like 
objects.

I found a post about Derby, and it seems they also had to fix the negative 
zero:
http://bryanpendleton.blogspot.fr/2009/04/negative-zero-in-java.html

Cheers,
-Christopher

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.

Reply via email to