APFloat: Make sure that we get a well-formed x87 NaN when converting from a smaller type.

Fixes PR15054.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@173459 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Benjamin Kramer 2013-01-25 17:01:00 +00:00
parent 5b7c057167
commit bd7561ea29
2 changed files with 32 additions and 0 deletions

View File

@ -1913,6 +1913,12 @@ APFloat::convert(const fltSemantics &toSemantics,
*losesInfo = (fs != opOK);
} else if (category == fcNaN) {
*losesInfo = lostFraction != lfExactlyZero || X86SpecialNan;
// For x87 extended precision, we want to make a NaN, not a special NaN if
// the input wasn't special either.
if (!X86SpecialNan && semantics == &APFloat::x87DoubleExtended)
APInt::tcSetBit(significandParts(), semantics->precision - 1);
// gcc forces the Quiet bit on, which means (float)(double)(float_sNan)
// does not give you back the same bits. This is dubious, and we
// don't currently do it. You're really supposed to get

View File

@ -794,6 +794,32 @@ TEST(APFloatTest, convert) {
test.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven, &losesInfo);
EXPECT_EQ(4294967295.0, test.convertToDouble());
EXPECT_FALSE(losesInfo);
test = APFloat::getSNaN(APFloat::IEEEsingle);
APFloat X87SNaN = APFloat::getSNaN(APFloat::x87DoubleExtended);
test.convert(APFloat::x87DoubleExtended, APFloat::rmNearestTiesToEven,
&losesInfo);
EXPECT_TRUE(test.bitwiseIsEqual(X87SNaN));
EXPECT_FALSE(losesInfo);
test = APFloat::getQNaN(APFloat::IEEEsingle);
APFloat X87QNaN = APFloat::getQNaN(APFloat::x87DoubleExtended);
test.convert(APFloat::x87DoubleExtended, APFloat::rmNearestTiesToEven,
&losesInfo);
EXPECT_TRUE(test.bitwiseIsEqual(X87QNaN));
EXPECT_FALSE(losesInfo);
test = APFloat::getSNaN(APFloat::x87DoubleExtended);
test.convert(APFloat::x87DoubleExtended, APFloat::rmNearestTiesToEven,
&losesInfo);
EXPECT_TRUE(test.bitwiseIsEqual(X87SNaN));
EXPECT_FALSE(losesInfo);
test = APFloat::getQNaN(APFloat::x87DoubleExtended);
test.convert(APFloat::x87DoubleExtended, APFloat::rmNearestTiesToEven,
&losesInfo);
EXPECT_TRUE(test.bitwiseIsEqual(X87QNaN));
EXPECT_FALSE(losesInfo);
}
TEST(APFloatTest, PPCDoubleDouble) {