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
This commit is contained in:
Benjamin Kramer
2012-09-26 14:06:58 +00:00
parent 50b7d70707
commit 3e7735fe1c
2 changed files with 18 additions and 1 deletions
+1 -1
View File
@@ -1775,7 +1775,7 @@ APFloat::opStatus APFloat::roundToIntegral(roundingMode rounding_mode) {
// 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))
if (category == fcNormal && exponent+1 >= (int)semanticsPrecision(*semantics))
return opOK;
// The algorithm here is quite simple: we add 2^(p-1), where p is the