APFloat: Fix signalling nans for scalbn

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@264219 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Matt Arsenault 2016-03-23 23:51:45 +00:00
parent 54f7128a27
commit b883372896
2 changed files with 18 additions and 1 deletions

View File

@ -3984,6 +3984,8 @@ APFloat llvm::scalbn(APFloat X, int Exp, APFloat::roundingMode RoundingMode) {
// Clamp to one past the range ends to let normalize handle overlflow.
X.exponent += std::min(std::max(Exp, -MaxIncrement - 1), MaxIncrement);
X.normalize(RoundingMode, lfExactlyZero);
if (X.isNaN())
X.makeQuiet();
return X;
}

View File

@ -2890,7 +2890,22 @@ TEST(APFloatTest, scalbn) {
EXPECT_TRUE(MZero.bitwiseIsEqual(scalbn(MZero, 0, RM)));
EXPECT_TRUE(QPNaN.bitwiseIsEqual(scalbn(QPNaN, 0, RM)));
EXPECT_TRUE(QMNaN.bitwiseIsEqual(scalbn(QMNaN, 0, RM)));
EXPECT_TRUE(SNaN.bitwiseIsEqual(scalbn(SNaN, 0, RM)));
EXPECT_FALSE(scalbn(SNaN, 0, RM).isSignaling());
APFloat ScalbnSNaN = scalbn(SNaN, 1, RM);
EXPECT_TRUE(ScalbnSNaN.isNaN() && !ScalbnSNaN.isSignaling());
// Make sure highest bit of payload is preserved.
const APInt Payload(64, (UINT64_C(1) << 50) |
(UINT64_C(1) << 49) |
(UINT64_C(1234) << 32) |
1);
APFloat SNaNWithPayload = APFloat::getSNaN(APFloat::IEEEdouble, false,
&Payload);
APFloat QuietPayload = scalbn(SNaNWithPayload, 1, RM);
EXPECT_TRUE(QuietPayload.isNaN() && !QuietPayload.isSignaling());
EXPECT_EQ(Payload, QuietPayload.bitcastToAPInt().getLoBits(51));
EXPECT_TRUE(PInf.bitwiseIsEqual(
scalbn(APFloat(APFloat::IEEEsingle, "0x1p+0"), 128, RM)));