From 4455142a95bb3d0f6e6cbb336d6558919cb59bb8 Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Sat, 26 Nov 2011 03:38:02 +0000 Subject: Fix APFloat::convert so that it handles narrowing conversions correctly; it was returning incorrect values in rare cases, and incorrectly marking exact conversions as inexact in some more common cases. Fixes PR11406, and a missed optimization in test/CodeGen/X86/fp-stack-O0.ll. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@145141 91177308-0d34-0410-b5e6-96231b3b80d8 --- unittests/ADT/APFloatTest.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'unittests/ADT/APFloatTest.cpp') diff --git a/unittests/ADT/APFloatTest.cpp b/unittests/ADT/APFloatTest.cpp index b6e02e3a9a..cc207f764d 100644 --- a/unittests/ADT/APFloatTest.cpp +++ b/unittests/ADT/APFloatTest.cpp @@ -653,4 +653,28 @@ TEST(APFloatTest, getLargest) { EXPECT_EQ(1.7976931348623158e+308, APFloat::getLargest(APFloat::IEEEdouble).convertToDouble()); } +TEST(APFloatTest, convert) { + bool losesInfo; + APFloat test(APFloat::IEEEdouble, "1.0"); + test.convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven, &losesInfo); + EXPECT_EQ(1.0f, test.convertToFloat()); + EXPECT_FALSE(losesInfo); + + test = APFloat(APFloat::x87DoubleExtended, "0x1p-53"); + test.add(APFloat(APFloat::x87DoubleExtended, "1.0"), APFloat::rmNearestTiesToEven); + test.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven, &losesInfo); + EXPECT_EQ(1.0, test.convertToDouble()); + EXPECT_TRUE(losesInfo); + + test = APFloat(APFloat::IEEEquad, "0x1p-53"); + test.add(APFloat(APFloat::IEEEquad, "1.0"), APFloat::rmNearestTiesToEven); + test.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven, &losesInfo); + EXPECT_EQ(1.0, test.convertToDouble()); + EXPECT_TRUE(losesInfo); + + test = APFloat(APFloat::x87DoubleExtended, "0xf.fffffffp+28"); + test.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven, &losesInfo); + EXPECT_EQ(4294967295.0, test.convertToDouble()); + EXPECT_FALSE(losesInfo); +} } -- cgit v1.2.3-18-g5258