src/share/classes/java/lang/Double.java

Print this page
rev 9077 : 6667086: Double.doubleToLongBits(final double value) contains inefficient test for NaN
Summary: Use isNaN() to test the parameter.
Reviewed-by: darcy, psandoz

@@ -831,18 +831,14 @@
      *
      * @param   value   a {@code double} precision floating-point number.
      * @return the bits that represent the floating-point number.
      */
     public static long doubleToLongBits(double value) {
-        long result = doubleToRawLongBits(value);
-        // Check for NaN based on values of bit fields, maximum
-        // exponent and nonzero significand.
-        if ( ((result & DoubleConsts.EXP_BIT_MASK) ==
-              DoubleConsts.EXP_BIT_MASK) &&
-             (result & DoubleConsts.SIGNIF_BIT_MASK) != 0L)
-            result = 0x7ff8000000000000L;
-        return result;
+        if (!isNaN(value)) {
+            return doubleToRawLongBits(value);
+        }
+        return 0x7ff8000000000000L;
     }
 
     /**
      * Returns a representation of the specified floating-point value
      * according to the IEEE 754 floating-point "double