Consolidate logic for creating NaNs. Silence compiler warning.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42966 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Support/APFloat.cpp b/lib/Support/APFloat.cpp
index e6f6b50..8f07bd5 100644
--- a/lib/Support/APFloat.cpp
+++ b/lib/Support/APFloat.cpp
@@ -586,6 +586,15 @@
partCount());
}
+/* Make this number a NaN, with an arbitrary but deterministic value
+ for the significand. */
+void
+APFloat::makeNaN(void)
+{
+ category = fcNaN;
+ APInt::tcSet(significandParts(), ~0U, partCount());
+}
+
APFloat &
APFloat::operator=(const APFloat &rhs)
{
@@ -650,6 +659,8 @@
sign = negative;
if(category == fcNormal)
category = fcZero;
+ else if (ourCategory == fcNaN)
+ makeNaN();
}
APFloat::APFloat(const fltSemantics &ourSemantics, const char *text)
@@ -1210,9 +1221,7 @@
/* Differently signed infinities can only be validly
subtracted. */
if(sign ^ rhs.sign != subtract) {
- category = fcNaN;
- // Arbitrary but deterministic value for significand
- APInt::tcSet(significandParts(), ~0U, partCount());
+ makeNaN();
return opInvalidOp;
}
@@ -1328,9 +1337,7 @@
case convolve(fcZero, fcInfinity):
case convolve(fcInfinity, fcZero):
- category = fcNaN;
- // Arbitrary but deterministic value for significand
- APInt::tcSet(significandParts(), ~0U, partCount());
+ makeNaN();
return opInvalidOp;
case convolve(fcNormal, fcNormal):
@@ -1372,9 +1379,7 @@
case convolve(fcInfinity, fcInfinity):
case convolve(fcZero, fcZero):
- category = fcNaN;
- // Arbitrary but deterministic value for significand
- APInt::tcSet(significandParts(), ~0U, partCount());
+ makeNaN();
return opInvalidOp;
case convolve(fcNormal, fcNormal):
@@ -1769,7 +1774,7 @@
if(bits > 0) {
lost_fraction = tmp.shiftSignificandRight(bits);
} else {
- if (-bits >= semantics->precision) {
+ if ((unsigned) -bits >= semantics->precision) {
// Unrepresentably large.
if (!sign && isSigned)
APInt::tcSetLeastSignificantBits(parts, partsCount, width-1);