RFR: JDK-8289551: Conversions between bit representations of half precision values and floats
Raffaello Giulietti
duke at openjdk.org
Wed Jul 13 15:21:15 UTC 2022
On Fri, 8 Jul 2022 06:11:22 GMT, Joe Darcy <darcy 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
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
test/jdk/java/lang/Float/SixteenBitFormats.java line 263:
> 261: }
> 262: }
> 263: }
The last invocation to `Integer.compare()` is not correct.
For example, if `bin16_1 = -1 `and `bin16_2 = 1`, the invocation returns 1, which is incorrect.
-------------
PR: https://git.openjdk.org/jdk/pull/9422
More information about the core-libs-dev
mailing list