aboutsummaryrefslogtreecommitdiffstats
path: root/unittests/ADT/APFloatTest.cpp
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2012-08-15 18:28:45 +0000
committerOwen Anderson <resistor@mac.com>2012-08-15 18:28:45 +0000
commitc82cc587a468d44e5cfabfa8f8a639667127845d (patch)
tree05e458aa3ea8daf0d4dcdadcdabc918473cc38df /unittests/ADT/APFloatTest.cpp
parentc97eda2c9e34f4c491f59bbac81af2fd63fef49d (diff)
downloadexternal_llvm-c82cc587a468d44e5cfabfa8f8a639667127845d.zip
external_llvm-c82cc587a468d44e5cfabfa8f8a639667127845d.tar.gz
external_llvm-c82cc587a468d44e5cfabfa8f8a639667127845d.tar.bz2
Fix another roundToIntegral bug where very large values could become infinity. Problem and solution identified by Steve Canon.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@161969 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/ADT/APFloatTest.cpp')
-rw-r--r--unittests/ADT/APFloatTest.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/unittests/ADT/APFloatTest.cpp b/unittests/ADT/APFloatTest.cpp
index caa288a..00b62fe 100644
--- a/unittests/ADT/APFloatTest.cpp
+++ b/unittests/ADT/APFloatTest.cpp
@@ -649,7 +649,7 @@ TEST(APFloatTest, exactInverse) {
}
TEST(APFloatTest, roundToIntegral) {
- APFloat T(-0.5), S(3.14), P(0.0);
+ APFloat T(-0.5), S(3.14), R(APFloat::getLargest(APFloat::IEEEdouble)), P(0.0);
P = T;
P.roundToIntegral(APFloat::rmTowardZero);
@@ -676,6 +676,19 @@ TEST(APFloatTest, roundToIntegral) {
P = S;
P.roundToIntegral(APFloat::rmNearestTiesToEven);
EXPECT_EQ(3.0, P.convertToDouble());
+
+ P = R;
+ P.roundToIntegral(APFloat::rmTowardZero);
+ EXPECT_EQ(R.convertToDouble(), P.convertToDouble());
+ P = R;
+ P.roundToIntegral(APFloat::rmTowardNegative);
+ EXPECT_EQ(R.convertToDouble(), P.convertToDouble());
+ P = R;
+ P.roundToIntegral(APFloat::rmTowardPositive);
+ EXPECT_EQ(R.convertToDouble(), P.convertToDouble());
+ P = R;
+ P.roundToIntegral(APFloat::rmNearestTiesToEven);
+ EXPECT_EQ(R.convertToDouble(), P.convertToDouble());
}
TEST(APFloatTest, getLargest) {