[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: mauve results posted nightly

From: Eric Blake
Subject: Re: mauve results posted nightly
Date: Thu, 14 Nov 2002 20:40:56 -0700
User-agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.0.1) Gecko/20020823 Netscape/7.0

Stephen Crawley wrote:
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.

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.

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).

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!!

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 (, 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.

This signature intentionally left boring.

Eric Blake             address@hidden
  BYU student, free software programmer

reply via email to

[Prev in Thread] Current Thread [Next in Thread]