summaryrefslogtreecommitdiff
path: root/libc/src/math/generic
AgeCommit message (Collapse)Author
2025-11-05[libc][math] Refactor exp2m1f16 implementation to header-only in ↵Muhammad Bassiouni
src/__support/math folder. (#162019) 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-10-30[libc] Remove optimization flags on entrypoints (#165782)Michael Jones
Optimization flags are now handled through a common flag. These are no longer necessary. Fixes #112409
2025-10-21[libc][math] Add float-only implementation for sinf / cosf. (#161680)lntue
Based on the double precision's sin/cos fast path algorithm: Step 1: Perform range reduction `y = x mod pi/8` with target errors < 2^-54. This is because the worst case mod pi/8 for single precision is ~2^-31, so to have up to 1 ULP errors from the range reduction, the targeted errors should `be 2^(-31 - 23) = 2^-54`. Step 2: Polynomial approximation We use degree-5 and degree-4 polynomials to approximate sin and cos of the reduced angle respectively. Step 3: Combine the results using trig identities ```math \begin{align*} \sin(x) &= \sin(y) \cdot \cos(k \cdot \frac{\pi}{8}) + \cos(y) \cdot \sin(k \cdot \frac{\pi}{8}) \\ \cos(x) &= \cos(y) \cdot \cos(k \cdot \frac{\pi}{8}) - \sin(y) \cdot \sin(k \cdot \frac{\pi}{8}) \end{align*} ``` Overall errors: <= 3 ULPs for default rounding modes (tested exhaustively). Current limitation: large range reduction requires FMA instructions for binary32. This restriction will be removed in the followup PR. --------- Co-authored-by: Petr Hosek <phosek@google.com>
2025-10-21[libc] Capture 'POLY_COEFFS' by reference in asinpi_polyeval lambda. (#164404)Ren Hiyama
Closes #164403 GCC fails to compile libc currently. This PR fixes this by capturing 'POLY_COEFFS' by reference.
2025-10-17[libc][math] Refactor exp2m1f implementation to header-only in ↵Muhammad Bassiouni
src/__support/math folder. (#162017) 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-10-11[libc][math] Refactor exp2f16 implementation to header-only in ↵Muhammad Bassiouni
src/__support/math folder. (#161993) 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-10-08[libc][math][c23] Add rsqrtf() function (#159615)Anton Shepelev
Closes #159614 **Changes:** - Initial implementation of rsqrt for single precision float **Some small unrelated style changes to this PR (that I missed in my rsqrtf16 PR):** - Added extra - to the top comments to make it look nicer in libc/shared/math/rsqrtf16.h - Put rsqrtf16 inside of libc/src/__support/math/CMakeLists.txt in sorted order - Rearanged libc_math_function rsqrtf16 in Bazel to match alphabetical order
2025-10-06[libc][math] Refactor exp2f implementation to header-only in ↵Muhammad Bassiouni
src/__support/math folder. (#161992) 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-10-05[libc][math] Refactor exp2 implementation to header-only in ↵Muhammad Bassiouni
src/__support/math folder. (#161297) 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-10-01[libc][math] Refactor exp10m1f16 implementation to header-only in ↵Muhammad Bassiouni
src/__support/math folder. (#161119) 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-09-29[libc][math] Refactor exp10m1f implementation to header-only in ↵Muhammad Bassiouni
src/__support/math folder. (#159897) 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-09-24[libc][math][c++23] Add log_bf16 math function (#157811)Krishna Pandey
This PR adds log_bf16 higher math function for BFloat16 type along with the tests. --------- Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-09-20[libc][math] Refactor dsqrtl implementation to header-only in ↵Muhammad Bassiouni
src/__support/math folder. (#154868) 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-09-17[libc][math][c23] Add rsqrtf16() function (#137545)Anton Shepelev
Addresses #132818 Part of #95250
2025-09-06[libc][math][c++23] Add sqrtbf16 math function (#156654)Krishna Pandey
This PR adds sqrtbf16 higher math function for BFloat16 type along with the tests. --------- Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-09-03[libc][math][c++23] Add fmodbf16 math function (#155575)Krishna Pandey
This PR adds fmodbf16 basic math function for BFloat16 type along with the tests. --------- Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-09-02[libc][math][c23] Implement C23 math function atanpif16 (#150400)Mohamed Emad
This PR implements `atanpif16(x)` which computes $\frac{\arctan(x)}{\pi}$ for half-precision floating-point numbers using polynomial approximation with domain reduction. ## Mathematical Implementation The implementation uses a 15th-degree Taylor polynomial expansion of $\frac{\arctan(x)}{\pi}$ that's computed using [`python-sympy`](https://www.sympy.org/en/index.html) and it's accurate in $|x| \in [0, 0.5)$: $$ g(x) = \frac{\arctan(x)}{\pi} \approx \begin{aligned}[t] & 0.318309886183791x \\ & - 0.106103295394597x^3 \\ & + 0.0636619772367581x^5 \\ & - 0.0454728408833987x^7 \\ & + 0.0353677651315323x^9 \\ & - 0.0289372623803446x^{11} \\ & + 0.0244853758602916x^{13} \\ & - 0.0212206590789194x^{15} + O(x^{17}) \end{aligned} $$ --- To ensure accuracy across all real inputs, the domain is divided into three cases with appropriate transformations: **Case 1: $|x| \leq 0.5$** Direct polynomial evaluation: $$\text{atanpi}(x) = \text{sign}(x) \cdot g(|x|)$$ **Case 2: $0.5 < |x| \leq 1$** Double-angle reduction using: $$\arctan(x) = 2\arctan\left(\frac{x}{1 + \sqrt{1 + x^2}}\right)$$ $$\text{atanpi}(x) = \text{sign}(x) \cdot 2g\left(\frac{|x|}{1 + \sqrt{1 + x^2}}\right)$$ **Case 3: $|x| > 1$** Reciprocal transformation using $$\arctan(x) = \frac{\pi}{2} - \arctan\left(\frac{1}{x}\right) \ \text{for} \ x \gt 0$$ $$\text{atanpi}(x) = \text{sign}(x) \cdot \left(\frac{1}{2} - g\left(\frac{1}{|x|}\right)\right)$$ Closes #132212
2025-08-28[libc][math][c++23] Add scalb{,l}nbf16 math functions (#155569)Krishna Pandey
This PR adds the following basic math functions for BFloat16 type along with the tests: - scalbnbf16 - scalblnbf16 --------- Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-28[libc][math][c++23] Add totalorder{,mag}bf16 math functions (#155568)Krishna Pandey
This PR adds the following basic math functions for BFloat16 type along with the tests: - totalorderbf16 - totalordermagbf16 --------- Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-27[libc][math][c++23] Add ↵Krishna Pandey
{canonicalize,iscanonical,fdim,copysign,issignaling}bf16 math functions (#155567) This PR adds the following basic math functions for BFloat16 type along with the tests: - canonicalizebf16 - iscanonicalbf16 - fdimbf16 - copysignbf16 - issignalingbf16 --------- Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-27[libc][math][c++23] Add {modf,remainder,remquo}bf16 math functions (#154652)Krishna Pandey
This PR adds the following basic math functions for BFloat16 type along with the tests: - modfbf16 - remainderbf16 - remquobf16 --------- Signed-off-by: Krishna Pandey <kpandey81930@gmail.com> Co-authored-by: OverMighty <its.overmighty@gmail.com>
2025-08-25[libc][math][c++23] Add {frexp,ilogb,ldexp,llogb,logb}bf16 math functions ↵Krishna Pandey
(#154427) This PR adds the following basic math functions for BFloat16 type along with the tests: - frexpbf16 - ilobbf16 - ldexpbf16 - llogbbf16 - logbbf16 --------- Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-24[libc][math] Do not use float16 basic operations in hypotf16. (#155177)lntue
Compiler runtimes for float16 basic operations might not be correctly rounded for all rounding modes.
2025-08-24[libc][math][c++23] Add {nearbyint,rint,lrint,llrint,lround,llround}bf16 ↵Krishna Pandey
math functions (#153882) This PR adds the following basic math functions for BFloat16 type along with the tests: - nearbyintbf16 - rintbf16 - lrintbf16 - llrintbf16 - lroundbf16 - llroundbf16 --------- Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-23[libc][math][c++23] Add nanbf16 math function (#153995)Krishna Pandey
This PR adds the nanbf16 basic math function for BFloat16 type along with the tests. --------- Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-23[libc][math][c++23] Add {get,set}payloadbf16 and setpayloadsigbf16 math ↵Krishna Pandey
functions (#153994) This PR adds the following basic math functions for BFloat16 type along with the tests: - getpayloadbf16 - setpayloadbf16 - setpayloadsigbf16 --------- Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-22[libc][math][c++23] Add next{after,down,toward,up}bf16 math functions (#153993)Krishna Pandey
This PR adds the following basic math functions for BFloat16 type along with the tests: - nextafterbf16 - nextdownbf16 - nexttowardbf16 - nextupbf16 --------- Signed-off-by: Krishna Pandey <kpandey81930@gmail.com> Co-authored-by: OverMighty <its.overmighty@gmail.com>
2025-08-22[libc][math] Refactor cospif16 implementation to header-only in ↵Muhammad Bassiouni
src/__support/math folder. (#154222) 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-08-22[libc][math] Refactor cospif implementation to header-only in ↵Muhammad Bassiouni
src/__support/math folder. (#154215) 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-08-19[libc][math][c++23] Add {,u}fromfp{,x}bf16 math functions (#153992)Krishna Pandey
This PR adds the following basic math functions for BFloat16 type along with the tests: - fromfpbf16 - fromfpxbf16 - ufromfpbf16 - ufromfpxbf16 --------- Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-19[libc][math] Refactor coshf16 implementation to header-only in ↵Muhammad Bassiouni
src/__support/math folder. (#153582) 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-08-18Reland "[libc][math][c23] Implement C23 math function asinpif16" (#152690)Mohamed Emad
#146226 with fixing asinpi MPFR number function and make it work when mpfr < `4.2.0`
2025-08-14[libc][math] Refactor coshf implementation to header-only in ↵Muhammad Bassiouni
src/__support/math folder. (#153427) 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-08-13[libc][math][c++23] Add bf16fma{,f,l,f128} math functions (#153231)Krishna Pandey
This PR adds the following basic math functions for BFloat16 type along with the tests: - bf16fma - bf16fmaf - bf16fmal - bf16fmaf128 --------- Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-13[libc][math] Refactor cosf16 implementation to header-only in ↵Muhammad Bassiouni
src/__support/math folder. (#152871) 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-08-12[libc][math][c++23] Add bf16div{,f,l,f128} math functions (#153191)Krishna Pandey
This PR adds the following basic math functions for BFloat16 type along with the tests: - bf16div - bf16divf - bf16divl - bf16divf128 --------- Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-12[libc][math][c++23] Add f{max,min}imum{,_mag,_mag_num,_num}bf16 math ↵Krishna Pandey
functions (#152881) This PR adds the following basic math functions for BFloat16 type along with the tests: - fmaximumbf16 - fmaximum_magbf16 - fmaximum_mag_numbf16 - fmaximum_numbf16 - fminimumbf16 - fminimum_magbf16 - fminimum_mag_numbf16 - fminimum_numbf16 --------- Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-11[libc][math] Refactor cosf implementation to header-only in ↵Muhammad Bassiouni
src/__support/math folder. (#152069) 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-08-10[libc][math][c++23] Add bf16mul{,f,l,f128} math functions (#152847)Krishna Pandey
This PR adds the following basic math functions for BFloat16 type along with the tests: - bf16mul - bf16mulf - bf16mull - bf16mulf128 --------- Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-09[libc][math] Refactor cos implementation to header-only in ↵Muhammad Bassiouni
src/__support/math folder. (#151883) 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-08-08[libc][math][c++23] Add f{max,min}bf16 math functions (#152782)Krishna Pandey
Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-08[libc][math][c++23] Add bf16{add,sub}{,f,l,f128} math functions (#152774)Krishna Pandey
This PR adds implements following basic math functions for BFloat16 type along with the tests: - bf16add - bf16addf - bf16addl - bf16addf128 - bf16sub - bf16subf - bf16subl - bf16subf128 --------- Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-08[libc][math] Refactor cbrtf implementation to header-only in ↵Muhammad Bassiouni
src/__support/math folder. (#151846) 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-08-08[libc][math][c++23] Add {ceil,floor,round,roundeven,trunc}bf16 math ↵Krishna Pandey
functions (#152352) This PR implements the following basic math functions for BFloat16 type along with the tests: - ceilbf16 - floorbf16 - roundbf16 - roundevenbf16 - truncbf16 --------- Signed-off-by: Krishna Pandey <kpandey81930@gmail.com>
2025-08-03[libc][math] Refactor cbrt implementation to header-only in ↵Muhammad Bassiouni
src/__support/math folder. (#151837) 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-08-02[libc][math] Refactor atanhf16 implementation to header-only in ↵Muhammad Bassiouni
src/__support/math folder. (#151779) 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-08-02[libc][math] Refactor atanhf implementation to header-only in ↵Muhammad Bassiouni
src/__support/math folder. (#151399) 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-08-02[libc][math] Refactor atan2f128 implementation to header-only in ↵Muhammad Bassiouni
src/__support/math folder. (#151012) 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-08-01[libc][math] Refactor atan2f implementation to header-only in ↵Muhammad Bassiouni
src/__support/math folder. (#150993) 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-31[libc][math] fix atan2l build failure. (#151413)Muhammad Bassiouni