mirror of
https://github.com/RPCSX/llvm.git
synced 2025-01-21 03:37:47 +00:00
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:
parent
54f7128a27
commit
b883372896
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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)));
|
||||
|
Loading…
x
Reference in New Issue
Block a user