src/share/classes/java/lang/Float.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

@@ -739,18 +739,14 @@
      *
      * @param   value   a floating-point number.
      * @return the bits that represent the floating-point number.
      */
     public static int floatToIntBits(float value) {
-        int result = floatToRawIntBits(value);
-        // Check for NaN based on values of bit fields, maximum
-        // exponent and nonzero significand.
-        if ( ((result & FloatConsts.EXP_BIT_MASK) ==
-              FloatConsts.EXP_BIT_MASK) &&
-             (result & FloatConsts.SIGNIF_BIT_MASK) != 0)
-            result = 0x7fc00000;
-        return result;
+        if (!isNaN(value)) {
+            return floatToRawIntBits(value);
+        }
+        return 0x7fc00000;
     }
 
     /**
      * Returns a representation of the specified floating-point value
      * according to the IEEE 754 floating-point "single format" bit