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

Joe Darcy darcy at openjdk.org
Thu Jul 14 21:04:20 UTC 2022


On Wed, 13 Jul 2022 14:33:49 GMT, Raffaello Giulietti <duke at openjdk.org> wrote:

>> Initial implementation.
>
> test/jdk/java/lang/Float/SixteenBitFormats.java line 239:
> 
>> 237:         public static boolean isNaN(short binary16) {
>> 238:             return ((binary16 & 0x7c00) == 0x7c00) // Max exponent and...
>> 239:                 && ((binary16 & 0x03ff) != 0 );    // significand nonzero.
> 
> return (binary16 & 0x7fff) > 0x7c00;
> 
> is more concise

In this case, I think the more verbose coding pattern is clearer.

> test/jdk/java/lang/Float/SixteenBitFormats.java line 244:
> 
>> 242:         public static short negate(short binary16) {
>> 243:             return (short)(((binary16 & 0x8000) ^ 0x8000) | // Isolate and flip sign bit
>> 244:                            (binary16 & 0x7fff));
> 
> return (short)(binary16 ^ 0x8000);
> 
> is shorter

Good suggestion.

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

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


More information about the core-libs-dev mailing list