[llvm-commits] [llvm] r42966 - in /llvm/trunk: include/llvm/ADT/APFloat.h lib/Support/APFloat.cpp

Neil Booth neil at daikokuya.co.uk
Sun Oct 14 03:39:53 PDT 2007


Author: neil
Date: Sun Oct 14 05:39:51 2007
New Revision: 42966

URL: http://llvm.org/viewvc/llvm-project?rev=42966&view=rev
Log:
Consolidate logic for creating NaNs.  Silence compiler warning.

Modified:
    llvm/trunk/include/llvm/ADT/APFloat.h
    llvm/trunk/lib/Support/APFloat.cpp

Modified: llvm/trunk/include/llvm/ADT/APFloat.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APFloat.h?rev=42966&r1=42965&r2=42966&view=diff

==============================================================================
--- llvm/trunk/include/llvm/ADT/APFloat.h (original)
+++ llvm/trunk/include/llvm/ADT/APFloat.h Sun Oct 14 05:39:51 2007
@@ -268,6 +268,7 @@
     opStatus multiplySpecials(const APFloat &);
 
     /* Miscellany.  */
+    void makeNaN(void);
     opStatus normalize(roundingMode, lostFraction);
     opStatus addOrSubtract(const APFloat &, roundingMode, bool subtract);
     cmpResult compareAbsoluteValue(const APFloat &) const;

Modified: llvm/trunk/lib/Support/APFloat.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APFloat.cpp?rev=42966&r1=42965&r2=42966&view=diff

==============================================================================
--- llvm/trunk/lib/Support/APFloat.cpp (original)
+++ llvm/trunk/lib/Support/APFloat.cpp Sun Oct 14 05:39:51 2007
@@ -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);





More information about the llvm-commits mailing list