[PATCH] D69771: [APFloat] Handle exponent underflow correctly

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 6 09:22:33 PST 2019


efriedma added inline comments.


================
Comment at: llvm/lib/Support/APFloat.cpp:1014
   omsb = APInt::tcMSB(fullSignificand, newPartsCount) + 1;
-  exponent += rhs.exponent;
+  newExponent = static_cast<int>(exponent) + static_cast<int>(rhs.exponent);
 
----------------
These static_casts don't do anything.


================
Comment at: llvm/lib/Support/APFloat.cpp:1218
+  // Make sure the new exponent fits into ExponentType.
+  if (newExponent < EXPONENT_MIN) {
+    unsigned int omsb, significantParts;
----------------
EXPONENT_MIN is -32768, which is more than twice as small as the smallest exponent in any format we support, right?  If the exponent is smaller than that, can we "cheat", and pretend the result came out to -32768?  The result is essentially zero anyway.

Do we need to handle EXPONENT_MAX?


================
Comment at: llvm/unittests/ADT/APFloatTest.cpp:2902
+
+    APFloat zero = APFloat::getZero(APFloat::x87DoubleExtended());
+
----------------
Maybe check what happens with other rounding modes, where the result isn't zero?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69771/new/

https://reviews.llvm.org/D69771





More information about the llvm-commits mailing list