Merge "Quiet SNaN inputs in Half.toFloat()"

This commit is contained in:
Treehugger Robot
2019-01-18 23:18:15 +00:00
committed by Gerrit Code Review

View File

@@ -162,6 +162,7 @@ public final class Half extends Number implements Comparable<Half> {
private static final int FP32_EXPONENT_MASK = 0xff;
private static final int FP32_SIGNIFICAND_MASK = 0x7fffff;
private static final int FP32_EXPONENT_BIAS = 127;
private static final int FP32_QNAN_MASK = 0x400000;
private static final int FP32_DENORMAL_MAGIC = 126 << 23;
private static final float FP32_DENORMAL_FLOAT = Float.intBitsToFloat(FP32_DENORMAL_MAGIC);
@@ -903,6 +904,9 @@ public final class Half extends Number implements Comparable<Half> {
outM = m << 13;
if (e == 0x1f) { // Infinite or NaN
outE = 0xff;
if (outM != 0) { // SNaNs are quieted
outM |= FP32_QNAN_MASK;
}
} else {
outE = e - FP16_EXPONENT_BIAS + FP32_EXPONENT_BIAS;
}