From 3e7735fe1c9e8f1cbad1bac02fbb998017fd0cbb Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Wed, 26 Sep 2012 14:06:58 +0000 Subject: APFloat::roundToIntegral: Special values don't keep the exponent value up to date, don't rely on it. Add a couple of unit tests for special floats. Fixes 13929, found by MemorySanitizer. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@164698 91177308-0d34-0410-b5e6-96231b3b80d8 --- unittests/ADT/APFloatTest.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'unittests/ADT') diff --git a/unittests/ADT/APFloatTest.cpp b/unittests/ADT/APFloatTest.cpp index 00b62fe..c8d7177 100644 --- a/unittests/ADT/APFloatTest.cpp +++ b/unittests/ADT/APFloatTest.cpp @@ -689,6 +689,23 @@ TEST(APFloatTest, roundToIntegral) { P = R; P.roundToIntegral(APFloat::rmNearestTiesToEven); EXPECT_EQ(R.convertToDouble(), P.convertToDouble()); + + P = APFloat::getZero(APFloat::IEEEdouble); + P.roundToIntegral(APFloat::rmTowardZero); + EXPECT_EQ(0.0, P.convertToDouble()); + P = APFloat::getZero(APFloat::IEEEdouble, true); + P.roundToIntegral(APFloat::rmTowardZero); + EXPECT_EQ(-0.0, P.convertToDouble()); + P = APFloat::getNaN(APFloat::IEEEdouble); + P.roundToIntegral(APFloat::rmTowardZero); + EXPECT_TRUE(IsNAN(P.convertToDouble())); + P = APFloat::getInf(APFloat::IEEEdouble); + P.roundToIntegral(APFloat::rmTowardZero); + EXPECT_TRUE(IsInf(P.convertToDouble()) && P.convertToDouble() > 0.0); + P = APFloat::getInf(APFloat::IEEEdouble, true); + P.roundToIntegral(APFloat::rmTowardZero); + EXPECT_TRUE(IsInf(P.convertToDouble()) && P.convertToDouble() < 0.0); + } TEST(APFloatTest, getLargest) { -- cgit v1.1