[libc-commits] [PATCH] D113815: [libc] Correct rounding for hexadecimalStringToFloat with long inputs.

Michael Jones via Phabricator via libc-commits libc-commits at lists.llvm.org
Mon Nov 15 10:04:32 PST 2021


michaelrj added inline comments.


================
Comment at: libc/src/__support/str_to_float.h:522
+
+  *outputMantissa = mantissa & fputil::FloatProperties<T>::mantissaMask;
   *outputExp2 = biasedExponent;
----------------
This is unnecessary, since the FloatBits type will do it when setting the mantissa of the final value. It also doesn't really hurt anything to have it, but I generally prefer to get the full output bits for testing.


================
Comment at: libc/src/__support/str_to_float.h:663-664
       if (digit >= BASE) {
-        seenDigit = false;
+        if (*src != EXPONENT_MARKER)
+          seenDigit = false;
         break;
----------------
setting `seenDigit` to false isn't recommended, since it should just be a flag for if any digit has been seen. This particular if would cause numbers that end with alphanumeric characters that aren't in base to return as zero, for example `0x1z`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113815



More information about the libc-commits mailing list