JDK-8324212 : Improve tests for Float.floatToFloat16?
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • Submitted: 2024-01-19
  • Updated: 2024-01-22
  • Resolved: 2024-01-22
Related Reports
Relates :  
Relates :  
Relates :  
Description
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?
Comments
By design, the exact handling of NaN bits for the float <-> float16 method is *not* specified. The software implementation shown is one valid implementation. See note in the email thread: https://mail.openjdk.org/pipermail/riscv-port-dev/2022-December/000706.html Closing as not a bug.
22-01-2024

https://mail.openjdk.org/pipermail/riscv-port-dev/2022-December/000701.html
22-01-2024