diff options
author | Michael Gottesman <mgottesman@apple.com> | 2013-07-27 21:49:25 +0000 |
---|---|---|
committer | Michael Gottesman <mgottesman@apple.com> | 2013-07-27 21:49:25 +0000 |
commit | ca4d2e60ea36bd4f532ab5d52f5b4394a33be819 (patch) | |
tree | 73ef5bba6021cf78f8b7149eb5219108d4b214b6 /lib/Support | |
parent | 060d34b1cf9a1185b24db95925f23d9fbadce078 (diff) | |
download | external_llvm-ca4d2e60ea36bd4f532ab5d52f5b4394a33be819.zip external_llvm-ca4d2e60ea36bd4f532ab5d52f5b4394a33be819.tar.gz external_llvm-ca4d2e60ea36bd4f532ab5d52f5b4394a33be819.tar.bz2 |
[APFloat] Make all arithmetic operations with NaN produce positive NaNs.
IEEE-754R 1.4 Exclusions states that IEEE-754R does not specify the
interpretation of the sign of NaNs. In order to remove an irrelevant
variable that most floating point implementations do not use,
standardize add, sub, mul, div, mod so that operating anything with
NaN always yields a positive NaN.
In a later commit I am going to update the APIs for creating NaNs so
that one can not even create a negative NaN.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187314 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support')
-rw-r--r-- | lib/Support/APFloat.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/lib/Support/APFloat.cpp b/lib/Support/APFloat.cpp index bc8e1d0..34bc6b6 100644 --- a/lib/Support/APFloat.cpp +++ b/lib/Support/APFloat.cpp @@ -1354,6 +1354,7 @@ APFloat::addOrSubtractSpecials(const APFloat &rhs, bool subtract) case PackCategoriesIntoKey(fcZero, fcNaN): case PackCategoriesIntoKey(fcNormal, fcNaN): case PackCategoriesIntoKey(fcInfinity, fcNaN): + sign = false; category = fcNaN; copySignificand(rhs); return opOK; @@ -1472,11 +1473,13 @@ APFloat::multiplySpecials(const APFloat &rhs) case PackCategoriesIntoKey(fcNaN, fcNormal): case PackCategoriesIntoKey(fcNaN, fcInfinity): case PackCategoriesIntoKey(fcNaN, fcNaN): + sign = false; return opOK; case PackCategoriesIntoKey(fcZero, fcNaN): case PackCategoriesIntoKey(fcNormal, fcNaN): case PackCategoriesIntoKey(fcInfinity, fcNaN): + sign = false; category = fcNaN; copySignificand(rhs); return opOK; @@ -1510,23 +1513,22 @@ APFloat::divideSpecials(const APFloat &rhs) default: llvm_unreachable(0); + case PackCategoriesIntoKey(fcZero, fcNaN): + case PackCategoriesIntoKey(fcNormal, fcNaN): + case PackCategoriesIntoKey(fcInfinity, fcNaN): + category = fcNaN; + copySignificand(rhs); case PackCategoriesIntoKey(fcNaN, fcZero): case PackCategoriesIntoKey(fcNaN, fcNormal): case PackCategoriesIntoKey(fcNaN, fcInfinity): case PackCategoriesIntoKey(fcNaN, fcNaN): + sign = false; case PackCategoriesIntoKey(fcInfinity, fcZero): case PackCategoriesIntoKey(fcInfinity, fcNormal): case PackCategoriesIntoKey(fcZero, fcInfinity): case PackCategoriesIntoKey(fcZero, fcNormal): return opOK; - case PackCategoriesIntoKey(fcZero, fcNaN): - case PackCategoriesIntoKey(fcNormal, fcNaN): - case PackCategoriesIntoKey(fcInfinity, fcNaN): - category = fcNaN; - copySignificand(rhs); - return opOK; - case PackCategoriesIntoKey(fcNormal, fcInfinity): category = fcZero; return opOK; @@ -1564,6 +1566,7 @@ APFloat::modSpecials(const APFloat &rhs) case PackCategoriesIntoKey(fcZero, fcNaN): case PackCategoriesIntoKey(fcNormal, fcNaN): case PackCategoriesIntoKey(fcInfinity, fcNaN): + sign = false; category = fcNaN; copySignificand(rhs); return opOK; |