summaryrefslogtreecommitdiff
path: root/libc/src/math/generic/asin.cpp
AgeCommit message (Collapse)Author
2025-07-25[libc][math] Refactor asin implementation to header-only in ↵Muhammad Bassiouni
src/__support/math folder. (#148578) Part of #147386 in preparation for: https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450
2025-07-21[libc][math] add smoke tests to shared/math.h (#149741)Muhammad Bassiouni
Adding smoke tests for shared math header. part of #147386
2025-07-19[libc][math] Refactor acos implementation to header-only in ↵Muhammad Bassiouni
src/__support/math folder. (#148409) Part of #147386 in preparation for: https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450
2025-05-08[libc][math] Implement double precision acos correctly rounded for all ↵lntue
rounding modes. (#138308) We reduce computation of `acos` to `asin` as follow: When `|x| < 0.5`: ```math acos(x) = \frac{\pi}{2} - asin(x). ``` For `0.5 <= |x| < 1`, let ```math u = \frac{1 - \left| x \right|}{2}, ``` then ```math acos(x) = \begin{cases} 2 \cdot asin \left( \sqrt{u} \right) &, 0.5 \leq x < 1 \\ \pi - 2 \cdot asin \left( \sqrt{u} \right) &, -1 < x \leq 0.5 \end{cases} ```
2025-04-25[libc][math] Implement double precision asin correctly rounded for all ↵lntue
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)`.
2023-04-20[libc][math] Remove placeholder implementations of asin and pow.Tue Ly
Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D148781
2022-10-31[libc][math] Add place-holder implementation for asin to unblock demo examples.Tue Ly
Add a place-holder implementation for asin to unblock libc demo examples. Reviewed By: michaelrj Differential Revision: https://reviews.llvm.org/D137105