[llvm] r264219 - APFloat: Fix signalling nans for scalbn
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 23 16:51:45 PDT 2016
Author: arsenm
Date: Wed Mar 23 18:51:45 2016
New Revision: 264219
URL: http://llvm.org/viewvc/llvm-project?rev=264219&view=rev
Log:
APFloat: Fix signalling nans for scalbn
Modified:
llvm/trunk/lib/Support/APFloat.cpp
llvm/trunk/unittests/ADT/APFloatTest.cpp
Modified: llvm/trunk/lib/Support/APFloat.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APFloat.cpp?rev=264219&r1=264218&r2=264219&view=diff
==============================================================================
--- llvm/trunk/lib/Support/APFloat.cpp (original)
+++ llvm/trunk/lib/Support/APFloat.cpp Wed Mar 23 18:51:45 2016
@@ -3984,6 +3984,8 @@ APFloat llvm::scalbn(APFloat X, int Exp,
// 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;
}
Modified: llvm/trunk/unittests/ADT/APFloatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/APFloatTest.cpp?rev=264219&r1=264218&r2=264219&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/APFloatTest.cpp (original)
+++ llvm/trunk/unittests/ADT/APFloatTest.cpp Wed Mar 23 18:51:45 2016
@@ -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)));
More information about the llvm-commits
mailing list