[libc-commits] [PATCH] D113036: [libc] refactor atof string parsing

Siva Chandra via Phabricator via libc-commits libc-commits at lists.llvm.org
Thu Nov 4 23:58:51 PDT 2021


sivachandra added inline comments.


================
Comment at: libc/src/__support/str_to_float.h:459
+static inline void
+binaryExpToFloat(typename fputil::FPBits<T>::UIntType mantissa, int32_t exp2,
+                 typename fputil::FPBits<T>::UIntType *outputMantissa,
----------------
This function is mostly `NormalFloat::operator T`. It would be nice if we can extend it as required and avoid the mostly duplicated logic. AFAICT, setting of  `errno` is the difference? Input exponent needs to be corrected of course like on line 480, which can be done as a preprocessing step. You can do it as a cleanup later if it can be done.


================
Comment at: libc/src/__support/str_to_float.h:500
+    }
+    mantissa = shiftRightAndRound(mantissa, amountToShift);
+    if (mantissa == 0) {
----------------
Can the shift and round operation here lead to an overflow? See this for why it can happen: https://github.com/llvm/llvm-project/blob/main/libc/src/__support/FPUtil/NormalFloat.h#L124


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113036



More information about the libc-commits mailing list