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

Improve tests for Float.floatToFloat16?

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • None
    • core-libs
    • None

      By applying the below patch, both tests (`test/jdk/java/lang/Float/Binary16ConversionNaN.java test/jdk/java/lang/Float/Binary16Conversion.java`) still passed.
      Either we need to improve the tests, or we could simplify the logic as this patch.

      Seems we need to improve the tests, but I'm not sure, so file this bug to discuss it.
      Please help to share your points. Thanks!


      diff --git a/src/java.base/share/classes/java/lang/Float.java b/src/java.base/share/classes/java/lang/Float.java
      index 7508c22d7f4..f96e23b568e 100644
      --- a/src/java.base/share/classes/java/lang/Float.java
      +++ b/src/java.base/share/classes/java/lang/Float.java
      @@ -1108,9 +1108,7 @@ public static short floatToFloat16(float f) {
                           // Preserve high order bit of float NaN in the
                           // binary16 result NaN (tenth bit); OR in remaining
                           // bits into lower 9 bits of binary 16 significand.
      - | (doppel & 0x007f_e000) >> 13 // 10 bits
      - | (doppel & 0x0000_1ff0) >> 4 // 9 bits
      - | (doppel & 0x0000_000f)); // 4 bits
      + | (doppel & 0x007f_e000) >> 13); // 10 bits
               }
       
               float abs_f = Math.abs(f);



      BTW, I did not find the specific content about this conversion in https://iremi.univ-reunion.fr/IMG/pdf/ieee-754-2008.pdf.
      Or maybe I missed the information?

            darcy Joe Darcy
            mli Hamlin Li
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: