summaryrefslogtreecommitdiff
path: root/lib/Support/APFloat.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 /lib/Support/APFloat.cpp
parentc97eda2c9e34f4c491f59bbac81af2fd63fef49d (diff)
downloadllvm-c82cc587a468d44e5cfabfa8f8a639667127845d.tar.gz
llvm-c82cc587a468d44e5cfabfa8f8a639667127845d.tar.bz2
llvm-c82cc587a468d44e5cfabfa8f8a639667127845d.tar.xz
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 'lib/Support/APFloat.cpp')
-rw-r--r--lib/Support/APFloat.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/Support/APFloat.cpp b/lib/Support/APFloat.cpp
index b42a168bae..ed261a4194 100644
--- a/lib/Support/APFloat.cpp
+++ b/lib/Support/APFloat.cpp
@@ -1770,6 +1770,12 @@ APFloat::opStatus APFloat::roundToIntegral(roundingMode rounding_mode) {
opStatus fs;
assertArithmeticOK(*semantics);
+ // If the exponent is large enough, we know that this value is already
+ // integral, and the arithmetic below would potentially cause it to saturate
+ // to +/-Inf. Bail out early instead.
+ if (exponent+1 >= (int)semanticsPrecision(*semantics))
+ return opOK;
+
// The algorithm here is quite simple: we add 2^(p-1), where p is the
// precision of our format, and then subtract it back off again. The choice
// of rounding modes for the addition/subtraction determines the rounding mode