diff options
author | Owen Anderson <resistor@mac.com> | 2012-08-15 05:39:46 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2012-08-15 05:39:46 +0000 |
commit | f7a5dfcb3b68b782543d25ba3151893111ff008f (patch) | |
tree | b90574a5d05d8eb8d2dc60ee2ee8f0421d3be6a5 /unittests/ADT/APFloatTest.cpp | |
parent | 9441ad0b6e02ee9558168b37a9620ef1afe79388 (diff) |
Fix a problem with APFloat::roundToIntegral where it would return incorrect results for negative inputs to trunc. Add unit tests to verify this behavior.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@161929 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/ADT/APFloatTest.cpp')
-rw-r--r-- | unittests/ADT/APFloatTest.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/unittests/ADT/APFloatTest.cpp b/unittests/ADT/APFloatTest.cpp index cc207f764d..caa288afaf 100644 --- a/unittests/ADT/APFloatTest.cpp +++ b/unittests/ADT/APFloatTest.cpp @@ -648,6 +648,36 @@ TEST(APFloatTest, exactInverse) { EXPECT_FALSE(APFloat(1.40129846e-45f).getExactInverse(0)); } +TEST(APFloatTest, roundToIntegral) { + APFloat T(-0.5), S(3.14), P(0.0); + + P = T; + P.roundToIntegral(APFloat::rmTowardZero); + EXPECT_EQ(-0.0, P.convertToDouble()); + P = T; + P.roundToIntegral(APFloat::rmTowardNegative); + EXPECT_EQ(-1.0, P.convertToDouble()); + P = T; + P.roundToIntegral(APFloat::rmTowardPositive); + EXPECT_EQ(-0.0, P.convertToDouble()); + P = T; + P.roundToIntegral(APFloat::rmNearestTiesToEven); + EXPECT_EQ(-0.0, P.convertToDouble()); + + P = S; + P.roundToIntegral(APFloat::rmTowardZero); + EXPECT_EQ(3.0, P.convertToDouble()); + P = S; + P.roundToIntegral(APFloat::rmTowardNegative); + EXPECT_EQ(3.0, P.convertToDouble()); + P = S; + P.roundToIntegral(APFloat::rmTowardPositive); + EXPECT_EQ(4.0, P.convertToDouble()); + P = S; + P.roundToIntegral(APFloat::rmNearestTiesToEven); + EXPECT_EQ(3.0, P.convertToDouble()); +} + TEST(APFloatTest, getLargest) { EXPECT_EQ(3.402823466e+38f, APFloat::getLargest(APFloat::IEEEsingle).convertToFloat()); EXPECT_EQ(1.7976931348623158e+308, APFloat::getLargest(APFloat::IEEEdouble).convertToDouble()); |