[libc][math] Implement log10 function correctly rounded for all rounding modes
authorTue Ly <lntue@google.com>
Sun, 8 Jan 2023 22:19:13 +0000 (17:19 -0500)
committerTue Ly <lntue@google.com>
Sun, 8 Jan 2023 22:41:54 +0000 (17:41 -0500)
commit5814b7b27963229ea78b2092990d72158da748a3
treeeab6c6a36fb346a46c442cc23a5ea5bc79559759
parentacd22b275131a965f4a6006dfa0b237ed6b6572e
[libc][math] Implement log10 function correctly rounded for all rounding modes

Implement double precision log10 function correctly rounded for all
rounding modes.  This implementation currently needs FMA instructions for
correctness.

Use 2 passes:
Fast pass:
- 1 step range reduction with a lookup table of `2^7 = 128` elements to reduce the ranges to `[-2^-7, 2^-7]`.
- Use a degree-7 minimax polynomial generated by Sollya, evaluated using a mixed of double-double and double precisions.
- Apply Ziv's test for accuracy.
Accurate pass:
- Apply 5 more range reduction steps to reduce the ranges further to [-2^-27, 2^-27].
- Use a degree-4 minimax polynomial generated by Sollya, evaluated using 192-bit precisions.
- By the result of Lefevre (add quote), this is more than enough for correct rounding to all rounding modes.

In progress: Adding detail documentations about the algorithm.

Depend on: https://reviews.llvm.org/D136799

Reviewed By: zimmermann6

Differential Revision: https://reviews.llvm.org/D139846
17 files changed:
libc/config/darwin/arm/entrypoints.txt
libc/config/linux/aarch64/entrypoints.txt
libc/config/linux/x86_64/entrypoints.txt
libc/config/windows/entrypoints.txt
libc/docs/math.rst
libc/docs/math/log.rst [new file with mode: 0644]
libc/spec/stdc.td
libc/src/__support/FPUtil/CMakeLists.txt
libc/src/__support/FPUtil/double_double.h [new file with mode: 0644]
libc/src/__support/FPUtil/dyadic_float.h
libc/src/__support/number_pair.h
libc/src/math/CMakeLists.txt
libc/src/math/generic/CMakeLists.txt
libc/src/math/generic/log10.cpp [new file with mode: 0644]
libc/src/math/log10.h [new file with mode: 0644]
libc/test/src/math/CMakeLists.txt
libc/test/src/math/log10_test.cpp [new file with mode: 0644]