Summary
The thresholds to select plain versus scientific notation in Float16 are currently the same as for double and float, namely 1e-3 and 1e7. Given the narrow range of Flaot16 values, the upper threshold should be lowered to 1e3.
Problem
All Float16 values greater than or equal to 1024 are integers, and are currently formatted in plain notation. However, since these integers spread out more and more over the Float16 range, it can happen that converting an integer like 65519 to Float16 and converting this back to a decimal that is formatted as a visually different integer, here 65500. This can cause confusion to users not too familiar with the intricacies of binary-to-decimal conversions.
Solution
The solution consists of using 1e3 as the upper threshold, thus forcing scientific notation for decimal values greater than or equal to 1000. Scientific notation is usually associated with imprecision, so "reading" 65519 and outputting it as 6.55E4 is arguably less confusing to most users.
Specification
--- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Float16.java
+++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Float16.java
@@ -260,6 +260,9 @@ private Float16(short bits) {
* Float#toString(float)} in the handling of special values
* (signed zeros, infinities, and NaN) and the generation of a
* decimal string that will convert back to the argument value.
+ * However, the range for plain notation is defined to be the interval
+ * [10<sup>-3</sup>, 10<sup>3</sup>) rather than the interval used
+ * for {@code float} and {@code double}.
*
* @param f16 the {@code Float16} to be converted.
* @return a string representation of the argument.
- csr of
-
JDK-8373068 Revisit details of Float16 to decimal conversion algorithm
-
- Resolved
-