diff options
author | lntue <lntue@google.com> | 2025-04-25 09:55:21 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-25 09:55:21 -0400 |
commit | ade502a8c46b8393e022b4eabcdd445af91a451c (patch) | |
tree | 36f27e69e927c7b1ad953e317ba91aaed7dcca3c /clang/lib/Frontend/ASTMerge.cpp | |
parent | 1ff931ea5bf80be82f65c2f0df2ccbb610f6728c (diff) | |
download | llvm-ade502a8c46b8393e022b4eabcdd445af91a451c.zip llvm-ade502a8c46b8393e022b4eabcdd445af91a451c.tar.gz llvm-ade502a8c46b8393e022b4eabcdd445af91a451c.tar.bz2 |
[libc][math] Implement double precision asin correctly rounded for all rounding modes. (#134401)
Main algorithm:
The Taylor series expansion of `asin(x)` is:
```math
\begin{align*}
asin(x) &= x + x^3 / 6 + 3x^5 / 40 + ... \\
&= x \cdot P(x^2) \\
&= x \cdot P(u) &\text{, where } u = x^2.
\end{align*}
```
For the fast path, we perform range reduction mod 1/64 and use degree-7
(minimax + Taylor) polynomials to approximate `P(x^2)`.
When `|x| >= 0.5`, we use the transformation:
```math
u = \frac{1 + x}{2}
```
and apply half-angle formula to reduce `asin(x)` to:
```math
\begin{align*}
asin(x) &= sign(x) \cdot \left( \frac{\pi}{2} - 2 \cdot asin(\sqrt{u}) \right) \\
&= sign(x) \cdot \left( \frac{\pi}{2} - 2 \cdot \sqrt{u} \cdot P(u) \right).
\end{align*}
```
Since `0.5 <= |x| <= 1`, `|u| <= 0.5`. So we can reuse the polynomial
evaluation of `P(u)` when `|x| < 0.5`.
For the accurate path, we redo the computations in 128-bit precision
with degree-15 (minimax + Taylor) polynomials to approximate `P(u)`.
Diffstat (limited to 'clang/lib/Frontend/ASTMerge.cpp')
0 files changed, 0 insertions, 0 deletions