RFR: JDK-8289551: Conversions between bit representations of half precision values and floats

Joe Darcy darcy at openjdk.org
Thu Jul 14 21:01:18 UTC 2022


On Wed, 13 Jul 2022 12:38:23 GMT, Raffaello Giulietti <duke at openjdk.org> wrote:

>> Initial implementation.
>
> src/java.base/share/classes/java/lang/Float.java line 1100:
> 
>> 1098: 
>> 1099:         // The overflow threshold is binary16 MAX_VALUE + 1/2 ulp
>> 1100:         if (abs_f > (65504.0f + 16.0f) ) {
> 
> if (abs_f >= (65504.0f + 16.0f) ) {
> 
> Value exactly halfway must round to infinity.

Good catch. The rest of the code computed the right value, but the condition should be changed as suggested.

> src/java.base/share/classes/java/lang/Float.java line 1141:
> 
>> 1139: 
>> 1140:                 // Significand bits as if using rounding to zero (truncation).
>> 1141:                 signif_bits = (short)((doppel & 0x0007f_e000) >>
> 
> signif_bits = (short)((doppel & 0x007f_e000) >>
> 
> or even
> 
>                signif_bits = (short)((doppel & 0x007f_ffff) >>
> 
> 32 bit hex are more readable when they have 8 hex digits

Oops; yes, I intended for the int hex constants to have at most 8 hex digits.

-------------

PR: https://git.openjdk.org/jdk/pull/9422


More information about the core-libs-dev mailing list