[libc-commits] [PATCH] D115408: [libc] Implement correctly rounded logf based on RLIBM library.

Christoph Lauter via Phabricator via libc-commits libc-commits at lists.llvm.org
Fri Dec 17 12:19:37 PST 2021


cqlauter added inline comments.


================
Comment at: libc/src/math/generic/logf.cpp:21
+// Step 1 - Range reduction:
+//   For x = 2^m * 1.mant, log(x) = m * log(2) + log(1.m)
+//   If x is denormal, we normalize it by multiplying x by 2^23 and subtracting
----------------
I think that this addition will burn a lot of accuracy in the case when the exponent m = -1 and 1.mant is close to 2. This is catastrophic cancellation.

There is a trick to avoid the cancellation, typically by bringing 1.mant into the range 0.75 <= 1.mant <= 1.5, which can be done by adding in a 1 into the IEEE754 representation at the right place.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115408



More information about the libc-commits mailing list