The final, noncanonical change in the value of the double value of NaN at run time

I am writing Java code that interacts with R, where the "NA" values ​​are different from the NaN values. NA indicates that the value is "statistically absent", that is, it cannot be collected or otherwise inaccessible.

class DoubleVector {
     public static final double NA = Double.longBitsToDouble(0x7ff0000000001954L);

     public static boolean isNA(double input) {
         return Double.doubleToRawLongBits(input) == Double.doubleToRawLongBits(NA);
     }

     /// ... 
}

The following unit test demonstrates the relationship between NaN and NA and works fine on my Windows laptop, but "isNA (NA) # 2" sometimes doesn't work on my ubuntu workstation.

@Test
public void test() {

    assertFalse("isNA(NaN) #1", DoubleVector.isNA(DoubleVector.NaN));
    assertTrue("isNaN(NaN)", Double.isNaN(DoubleVector.NaN));
    assertTrue("isNaN(NA)", Double.isNaN(DoubleVector.NA));
    assertTrue("isNA(NA) #2", DoubleVector.isNA(DoubleVector.NA));
    assertFalse("isNA(NaN)", DoubleVector.isNA(DoubleVector.NaN));
}

From debugging, it seems that DoubleVector.NA is changed to the canonical value NaN 7ff8000000000000L, but it's hard to say because printing it to stdout gives different values ​​than the debugger.

, , ; , .

JVM? ?

:

java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) Client VM (build 19.1-b02, mixed mode, sharing)

:

java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02, mixed mode)
+5
1

, , Java VM .

JVM double " NaN". NaN.

longBitsToDouble() :

, , , double NaN , . IEEE 754 NaN, NaN NaN. NaN Java. NaN NaN , . , NaN . , NaN, , . , longBitsToDouble, , NaN. , doubleToRawLongBits(longBitsToDouble(start)) start. , NaN, ; NaN, , NaN, .

, , double NaN, .

cleanest long double . , .

, strictfp . , , () , JVM , . , .

+6

All Articles