llvm.org GIT mirror llvm / bd7561e
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 Benjamin Kramer 6 years ago
2 changed file(s) with 32 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
19121912 *losesInfo = (fs != opOK);
19131913 } else if (category == fcNaN) {
19141914 *losesInfo = lostFraction != lfExactlyZero || X86SpecialNan;
1915
1916 // For x87 extended precision, we want to make a NaN, not a special NaN if
1917 // the input wasn't special either.
1918 if (!X86SpecialNan && semantics == &APFloat::x87DoubleExtended)
1919 APInt::tcSetBit(significandParts(), semantics->precision - 1);
1920
19151921 // gcc forces the Quiet bit on, which means (float)(double)(float_sNan)
19161922 // does not give you back the same bits. This is dubious, and we
19171923 // don't currently do it. You're really supposed to get
793793 test.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven, &losesInfo);
794794 EXPECT_EQ(4294967295.0, test.convertToDouble());
795795 EXPECT_FALSE(losesInfo);
796
797 test = APFloat::getSNaN(APFloat::IEEEsingle);
798 APFloat X87SNaN = APFloat::getSNaN(APFloat::x87DoubleExtended);
799 test.convert(APFloat::x87DoubleExtended, APFloat::rmNearestTiesToEven,
800 &losesInfo);
801 EXPECT_TRUE(test.bitwiseIsEqual(X87SNaN));
802 EXPECT_FALSE(losesInfo);
803
804 test = APFloat::getQNaN(APFloat::IEEEsingle);
805 APFloat X87QNaN = APFloat::getQNaN(APFloat::x87DoubleExtended);
806 test.convert(APFloat::x87DoubleExtended, APFloat::rmNearestTiesToEven,
807 &losesInfo);
808 EXPECT_TRUE(test.bitwiseIsEqual(X87QNaN));
809 EXPECT_FALSE(losesInfo);
810
811 test = APFloat::getSNaN(APFloat::x87DoubleExtended);
812 test.convert(APFloat::x87DoubleExtended, APFloat::rmNearestTiesToEven,
813 &losesInfo);
814 EXPECT_TRUE(test.bitwiseIsEqual(X87SNaN));
815 EXPECT_FALSE(losesInfo);
816
817 test = APFloat::getQNaN(APFloat::x87DoubleExtended);
818 test.convert(APFloat::x87DoubleExtended, APFloat::rmNearestTiesToEven,
819 &losesInfo);
820 EXPECT_TRUE(test.bitwiseIsEqual(X87QNaN));
821 EXPECT_FALSE(losesInfo);
796822 }
797823
798824 TEST(APFloatTest, PPCDoubleDouble) {