Stephen Crawley wrote:
Double.doubleToLongBits is specified to flatten all doubles to the canonical version of NaN, 0x7ff8000000000000L. You're thinking of Double.doubleToRawLongBits where NaN can be from a range of values. Mauve tests whether an implementation actually obeys this rule.Perhaps japize should use Double.doubleToLongBits() to compare the bitwise value of double constants (likewise Float.floatToIntBits()).That would be a bit safer, considering that even JDK 1.4.x has minor
bugs in its implementations of double -> string translation! However,
even comparing the bits returned Double.doubleToLongBits() is not
strictly correct, because the Java VM spec says that VMs are allowed to
use a range of bit patterns to represent NaN values.
Of all the compilers and VMs I have seen for Java, the only one that currently gets double->String and float->String conversion 100% correct is jikes, version 1.16 or later. There are several tests in the Jacks test suite for corner cases of string conversion; but I ought to port them to Mauve as well, to have runtime as well as compile-time tests.
(BTW, Sun JDK 1.4.x also has bugs in the string -> double translation, and I know at least one string which sends Sun's Double.parseDouble, and thus javac, into an infinite loop).
Not just the JVM - IEEE 754 also specified this relation! But your test above does not work for 0.0 vs. -0.0. The best comparison is (Double.compare(d1, d2) == 0), added in JDK 1.4; or (new Double(d1).compareTo(new Double(d2)) == 0) in JDK 1.2. If you want japize to work with JDK 1.1, just copy the implementation of these methods from Classpath or libgcj. These methods are tested by mauve.
The safest way for for japize to compare Java doubles (and floats) is to do the following:
double d1, d2;
...
boolean sameValue = (Double.isNaN(d1) && Double.isNaN(d2)) || (d1 == d2)
Note: you have to test NaNs separately because the Java VM spec says that
(NaN == NaN) always gives false!!
--
This signature intentionally left boring.
Eric Blake [EMAIL PROTECTED]
BYU student, free software programmer
_______________________________________________
Classpath mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/classpath