Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4660849

Float.floatToRawIntBits misses bit 22 if input is NaN

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.1
    • 1.4.0
    • core-libs
    • hopper
    • x86
    • windows_2000
    • Verified



      Name: gm110360 Date: 04/01/2002


      FULL PRODUCT VERSION :
      java version "1.3.1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
      Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)

      FULL OPERATING SYSTEM VERSION :
      Microsoft Windows 2000 [Version 5.00.2195]

      A DESCRIPTION OF THE PROBLEM :
      When this program runs...

      class TestFloatToInt {
          public static void main(String args[]) {
              int myInt = -7132611;
              System.out.println("Start value: " + myInt + " in
      hex: " + Integer.toHexString(myInt));

              float convertToFlt = Float.intBitsToFloat(myInt);
              System.out.println("Converted, using
      Float.intBitsToFloat: " + convertToFlt);

              int anotherInt = Float.floatToRawIntBits
      (convertToFlt);
              System.out.println("After
      Float.floatToRawIntBits: " + anotherInt +
                  " in hex: " + Integer.toHexString(anotherInt));
          }
      }

      it produces the following output...

      Start value: -7132611 in hex: ff932a3d
      Converted, using Float.intBitsToFloat: NaN
      After Float.floatToRawIntBits: -2938307 in hex: ffd32a3d

      indicating that bit number 22 is incorrectly set during the
      conversion.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Run the program


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      Expected output:

      Start value: -7132611 in hex: ff932a3d
      Converted, using Float.intBitsToFloat: NaN
      After Float.floatToRawIntBits: -2938307 in hex: ff932a3d

      Actual output:

      Start value: -7132611 in hex: ff932a3d
      Converted, using Float.intBitsToFloat: NaN
      After Float.floatToRawIntBits: -2938307 in hex: ffd32a3d

      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      class TestFloatToInt {
          public static void main(String args[]) {
              int myInt = -7132611;
              System.out.println("Start value: " + myInt + " in hex: " +
                  Integer.toHexString(myInt));

              float convertToFlt = Float.intBitsToFloat(myInt);
              System.out.println("Converted, using Float.intBitsToFloat: " +
                  convertToFlt);

              int anotherInt = Float.floatToRawIntBits(convertToFlt);
              System.out.println("After Float.floatToRawIntBits: " + anotherInt +
                  " in hex: " + Integer.toHexString(anotherInt));
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER WORKAROUND :
      I was using this method when trying to byte swap floats
      before writing to disk. I can find other ways to do this.
      (Review ID: 144670)
      ======================================================================

            darcy Joe Darcy
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: