Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a879fd8b authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

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

parents 44631dfc ea652eac
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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;
            }