[libc-commits] [libc] [llvm] [libc][math][c23] implement `asinpif` function (PR #181511)
Mohamed Emad via libc-commits
libc-commits at lists.llvm.org
Sun Feb 15 14:29:07 PST 2026
https://github.com/hulxv updated https://github.com/llvm/llvm-project/pull/181511
>From 455abef8449b6226af58806de2c898463685a6bc Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Sat, 14 Feb 2026 22:17:14 +0200
Subject: [PATCH] [libc][math][c23] implement `asinpif` function
---
libc/config/linux/aarch64/entrypoints.txt | 1 +
libc/config/linux/x86_64/entrypoints.txt | 1 +
libc/docs/headers/math/index.rst | 2 +-
libc/shared/math.h | 1 +
libc/shared/math/asinpif.h | 23 ++
libc/src/__support/math/CMakeLists.txt | 14 ++
libc/src/__support/math/asinpif.h | 199 ++++++++++++++++++
libc/src/math/CMakeLists.txt | 1 +
libc/src/math/asinpif.h | 20 ++
libc/src/math/generic/CMakeLists.txt | 10 +
libc/src/math/generic/asinpif.cpp | 16 ++
libc/test/shared/CMakeLists.txt | 1 +
libc/test/shared/shared_math_test.cpp | 1 +
libc/test/src/math/CMakeLists.txt | 11 +
libc/test/src/math/asinpif_test.cpp | 38 ++++
libc/test/src/math/exhaustive/CMakeLists.txt | 16 ++
.../test/src/math/exhaustive/asinpif_test.cpp | 33 +++
libc/test/src/math/smoke/CMakeLists.txt | 12 ++
libc/test/src/math/smoke/asinpif_test.cpp | 44 ++++
.../llvm-project-overlay/libc/BUILD.bazel | 24 +++
20 files changed, 467 insertions(+), 1 deletion(-)
create mode 100644 libc/shared/math/asinpif.h
create mode 100644 libc/src/__support/math/asinpif.h
create mode 100644 libc/src/math/asinpif.h
create mode 100644 libc/src/math/generic/asinpif.cpp
create mode 100644 libc/test/src/math/asinpif_test.cpp
create mode 100644 libc/test/src/math/exhaustive/asinpif_test.cpp
create mode 100644 libc/test/src/math/smoke/asinpif_test.cpp
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 970c825bbfc96..7534d3d3d2db2 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -664,6 +664,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
list(APPEND TARGET_LIBM_ENTRYPOINTS
# math.h C23 _Float16 entrypoints
libc.src.math.acoshf16
+ libc.src.math.asinpif
libc.src.math.asinpif16
libc.src.math.canonicalizef16
libc.src.math.ceilf16
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 9399b284fa2da..12acd2658c219 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -719,6 +719,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
libc.src.math.acospif16
libc.src.math.asinf16
libc.src.math.asinhf16
+ libc.src.math.asinpif
libc.src.math.asinpif16
libc.src.math.atanf16
libc.src.math.atanhf16
diff --git a/libc/docs/headers/math/index.rst b/libc/docs/headers/math/index.rst
index 51bb17ff8dab6..93144f513fd2d 100644
--- a/libc/docs/headers/math/index.rst
+++ b/libc/docs/headers/math/index.rst
@@ -269,7 +269,7 @@ Higher Math Functions
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| asinh | |check| | | | |check| | | | 7.12.5.2 | F.10.2.2 |
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
-| asinpi | | | | |check| | | | 7.12.4.9 | F.10.1.9 |
+| asinpi | |check| | | | |check| | | | 7.12.4.9 | F.10.1.9 |
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
| atan | |check| | 1 ULP | | |check| | | | 7.12.4.3 | F.10.1.3 |
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 66132326c2257..d0b054ea47540 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -22,6 +22,7 @@
#include "math/asinf16.h"
#include "math/asinhf.h"
#include "math/asinhf16.h"
+#include "math/asinpif.h"
#include "math/atan.h"
#include "math/atan2.h"
#include "math/atan2f.h"
diff --git a/libc/shared/math/asinpif.h b/libc/shared/math/asinpif.h
new file mode 100644
index 0000000000000..f0baece26d2ee
--- /dev/null
+++ b/libc/shared/math/asinpif.h
@@ -0,0 +1,23 @@
+//===-- Shared asinpif header -----------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_ASINPIF_H
+#define LLVM_LIBC_SHARED_MATH_ASINPIF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/asinpif.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::asinpif;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_ASINPIF_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index c0293c0969217..5a148d1deaedc 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -172,6 +172,20 @@ add_header_library(
libc.src.__support.macros.optimization
)
+add_header_library(
+ asinpif
+ HDRS
+ asinpif.h
+ DEPENDS
+ libc.src.__support.FPUtil.fenv_impl
+ libc.src.__support.FPUtil.fp_bits
+ libc.src.__support.FPUtil.polyeval
+ libc.src.__support.FPUtil.cast
+ libc.src.__support.FPUtil.multiply_add
+ libc.src.__support.FPUtil.sqrt
+ libc.src.__support.macros.optimization
+)
+
add_header_library(
atan_utils
HDRS
diff --git a/libc/src/__support/math/asinpif.h b/libc/src/__support/math/asinpif.h
new file mode 100644
index 0000000000000..f4fe45fcb8e4a
--- /dev/null
+++ b/libc/src/__support/math/asinpif.h
@@ -0,0 +1,199 @@
+//===-- Implementation header for asinpif -----------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_ASINPIF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_ASINPIF_H
+
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/PolyEval.h"
+#include "src/__support/FPUtil/cast.h"
+#include "src/__support/FPUtil/multiply_add.h"
+#include "src/__support/FPUtil/sqrt.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/optimization.h"
+#include "src/__support/macros/properties/types.h"
+
+#include "hdr/errno_macros.h"
+#include "hdr/fenv_macros.h"
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/except_value_utils.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr float asinpif(float x) {
+ using FPBits = fputil::FPBits<float>;
+
+ FPBits xbits(x);
+ bool is_neg = xbits.is_neg();
+ double x_abs = fputil::cast<double>(xbits.abs().get_val());
+
+ auto signed_result = [is_neg](auto r) -> auto { return is_neg ? -r : r; };
+
+ if (LIBC_UNLIKELY(x_abs > 1.0)) {
+ if (xbits.is_nan()) {
+ if (xbits.is_signaling_nan()) {
+ fputil::raise_except_if_required(FE_INVALID);
+ return FPBits::quiet_nan().get_val();
+ }
+ return x;
+ }
+
+ fputil::raise_except_if_required(FE_INVALID);
+ fputil::set_errno_if_required(EDOM);
+ return FPBits::quiet_nan().get_val();
+ }
+
+ // the coefficients for the polynomial approximation of asin(x)/pi in the
+ // range [0, 0.5] extracted using Sollya
+ //
+ // Sollya code:
+ // prec = 200;
+ // display = hexadecimal;
+ //
+ // g = asin(sqrt(x)) / (pi * sqrt(x));
+ // P = fpminimax(g, [|0,1,2,3,4,5,6,7,8,9,10,11,12,13|], [|D...|], [1e-30;
+ // 0.25]);
+ //
+ // for i from 0 to degree(P) do {
+ // if (i < degree(P)) then
+ // print(coeff(P, i))
+ // else
+ // print(coeff(P, i));
+ // };
+ //
+ // OUTPUT:
+ // 0x1.45f306dc9c883p-2
+ // 0x1.b2995e7b7b0ccp-5
+ // 0x1.8723a1d5e3397p-6
+ // 0x1.d1a452c4985d2p-7
+ // 0x1.3ce5309393d12p-7
+ // 0x1.d2b226cde1b71p-8
+ // 0x1.6a0d7274a2995p-8
+ // 0x1.22beb6d533d2fp-8
+ // 0x1.e905390792fc8p-9
+ // 0x1.7c84982aec05ap-9
+ // 0x1.8d9c5583cbaffp-9
+ // 0x1.5feeeacc6c4a6p-9
+ // -0x1.1237966112762p-10
+ // 0x1.cd80e8b6681dp-8
+ constexpr double ASINPI_POLY_COEFFS[] = {
+ 0x1.45f306dc9c883p-2, // c1
+ 0x1.b2995e7b7b0ccp-5, // c3
+ 0x1.8723a1d5e3397p-6, // c5
+ 0x1.d1a452c4985d2p-7, // c7
+ 0x1.3ce5309393d12p-7, // c9
+ 0x1.d2b226cde1b71p-8, // c11
+ 0x1.6a0d7274a2995p-8, // c13
+ 0x1.22beb6d533d2fp-8, // c15
+ 0x1.e905390792fc8p-9, // c17
+ 0x1.7c84982aec05ap-9, // c19
+ 0x1.8d9c5583cbaffp-9, // c21
+ 0x1.5feeeacc6c4a6p-9, // c23
+ -0x1.1237966112762p-10, // c25
+ 0x1.cd80e8b6681dp-8 // c27
+ };
+
+ // polynomial evaluation using horner's method
+ // work only for |x| in [0, 0.5]
+ // Returns v * P(v2) where P(v2) = c0 + c1*v2 + c2*v2^2 + ...
+ auto asinpi_polyeval = [&](double v, double v2) -> double {
+ return v * fputil::polyeval(v2, ASINPI_POLY_COEFFS[0],
+ ASINPI_POLY_COEFFS[1], ASINPI_POLY_COEFFS[2],
+ ASINPI_POLY_COEFFS[3], ASINPI_POLY_COEFFS[4],
+ ASINPI_POLY_COEFFS[5], ASINPI_POLY_COEFFS[6],
+ ASINPI_POLY_COEFFS[7], ASINPI_POLY_COEFFS[8],
+ ASINPI_POLY_COEFFS[9], ASINPI_POLY_COEFFS[10],
+ ASINPI_POLY_COEFFS[11], ASINPI_POLY_COEFFS[12],
+ ASINPI_POLY_COEFFS[13]);
+ };
+
+ // Returns P(v2) - c0 = c1*v2 + c2*v2^2 + ...
+ // This is the "tail" of the polynomial, used to avoid cancellation
+ // in the range reduction path.
+ auto asinpi_polyeval_tail = [&](double v2) -> double {
+ return v2 * fputil::polyeval(v2, ASINPI_POLY_COEFFS[1],
+ ASINPI_POLY_COEFFS[2], ASINPI_POLY_COEFFS[3],
+ ASINPI_POLY_COEFFS[4], ASINPI_POLY_COEFFS[5],
+ ASINPI_POLY_COEFFS[6], ASINPI_POLY_COEFFS[7],
+ ASINPI_POLY_COEFFS[8], ASINPI_POLY_COEFFS[9],
+ ASINPI_POLY_COEFFS[10], ASINPI_POLY_COEFFS[11],
+ ASINPI_POLY_COEFFS[12],
+ ASINPI_POLY_COEFFS[13]);
+ };
+
+ // if |x| <= 0.5:
+ if (LIBC_UNLIKELY(x_abs <= 0.5)) {
+ double x_d = fputil::cast<double>(x);
+ double result = asinpi_polyeval(x_d, x_d * x_d);
+ return fputil::cast<float>(result);
+ }
+
+ // If |x| > 0.5, we need to use the range reduction method:
+ // y = asin(x) => x = sin(y)
+ // because: sin(a) = cos(pi/2 - a)
+ // therefore:
+ // x = cos(pi/2 - y)
+ // let z = pi/2 - y,
+ // x = cos(z)
+ // because: cos(2a) = 1 - 2 * sin^2(a), z = 2a, a = z/2
+ // therefore:
+ // cos(z) = 1 - 2 * sin^2(z/2)
+ // sin(z/2) = sqrt((1 - cos(z))/2)
+ // sin(z/2) = sqrt((1 - x)/2)
+ // let u = (1 - x)/2
+ // then:
+ // sin(z/2) = sqrt(u)
+ // z/2 = asin(sqrt(u))
+ // z = 2 * asin(sqrt(u))
+ // pi/2 - y = 2 * asin(sqrt(u))
+ // y = pi/2 - 2 * asin(sqrt(u))
+ // y/pi = 1/2 - 2 * asin(sqrt(u))/pi
+ //
+ // Finally, we can write:
+ // asinpi(x) = 1/2 - 2 * asinpi(sqrt(u))
+ // where u = (1 - x) /2
+ // = 0.5 - 0.5 * x
+ // = multiply_add(-0.5, x, 0.5)
+ //
+ // asinpi(x) = 1/2 - 2 * sqrt(u) * P(u)
+ // = 1/2 - 2 * sqrt(u) * (c0 + (P(u) - c0))
+ // = 1/2 - 2 * sqrt(u) * c0 - 2 * sqrt(u) * (P(u) - c0)
+ // = (1/2 - 2 * sqrt(u) / pi) - 2 * sqrt(u) * tail(u)
+ //
+ // We use the high-precision constant 1/pi split into two parts:
+ // ONE_OVER_PI_HI + ONE_OVER_PI_LO ≈ 1/π
+ // so that:
+ // 1/2 - 2*sqrt(u)*c0 = 1/2 - 2*sqrt(u)*ONE_OVER_PI_HI
+ // - 2*sqrt(u)*ONE_OVER_PI_LO
+ // The first two terms are computed exactly via multiply_add.
+
+ constexpr double ONE_OVER_PI_HI = ASINPI_POLY_COEFFS[0];
+ constexpr double ONE_OVER_PI_LO = -0x1.6b01ec5417056p-56;
+
+ double u = fputil::multiply_add(-0.5, x_abs, 0.5);
+ double sqrt_u = fputil::sqrt<double>(u);
+
+ // compute the tail: P(u) - c0
+ double tail = asinpi_polyeval_tail(u);
+
+ // compute: 0.5 - 2*sqrt(u)/pi - 2*sqrt(u)*tail
+ // = 0.5 - 2*sqrt(u)*(1/pi + tail)
+ double neg2_sqrt_u = -2.0 * sqrt_u;
+ // 0.5 + neg2_sqrt_u * ONE_OVER_PI_HI
+ double result_hi = fputil::multiply_add(neg2_sqrt_u, ONE_OVER_PI_HI, 0.5);
+ // Add the low part of 1/pi and the tail
+ double result = result_hi + neg2_sqrt_u * (ONE_OVER_PI_LO + tail);
+
+ return fputil::cast<float>(signed_result(result));
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_ASINPIF_H
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index e37e22fdb58e6..7a9370fe487e2 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -58,6 +58,7 @@ add_math_entrypoint_object(asinh)
add_math_entrypoint_object(asinhf)
add_math_entrypoint_object(asinhf16)
+add_math_entrypoint_object(asinpif)
add_math_entrypoint_object(asinpif16)
add_math_entrypoint_object(atan)
diff --git a/libc/src/math/asinpif.h b/libc/src/math/asinpif.h
new file mode 100644
index 0000000000000..b66bdcb16e4c9
--- /dev/null
+++ b/libc/src/math/asinpif.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for asinpif -----------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_MATH_ASINPIF_H
+#define LLVM_LIBC_SRC_MATH_ASINPIF_H
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+float asinpif(float x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_ASINPIF_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 96dc0e7ca4851..0d36bc09e5a66 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -4180,6 +4180,16 @@ add_entrypoint_object(
libc.src.__support.math.asinhf16
)
+add_entrypoint_object(
+ asinpif
+ SRCS
+ asinpif.cpp
+ HDRS
+ ../asinpif.h
+ DEPENDS
+ libc.src.__support.math.asinpif
+)
+
add_entrypoint_object(
asinpif16
SRCS
diff --git a/libc/src/math/generic/asinpif.cpp b/libc/src/math/generic/asinpif.cpp
new file mode 100644
index 0000000000000..f302ecf4e2861
--- /dev/null
+++ b/libc/src/math/generic/asinpif.cpp
@@ -0,0 +1,16 @@
+//===-- Single-precision asinpif(x) function ------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception.
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/asinpif.h"
+#include "src/__support/math/asinpif.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(float, asinpif, (float x)) { return math::asinpif(x); }
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 7d72ced3e057c..36b9d2cead85f 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -18,6 +18,7 @@ add_fp_unittest(
libc.src.__support.math.asinf16
libc.src.__support.math.asinhf
libc.src.__support.math.asinhf16
+ libc.src.__support.math.asinpif
libc.src.__support.math.atan
libc.src.__support.math.atan2
libc.src.__support.math.atan2f
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 9e024387efbfa..8baeaaccc3908 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -80,6 +80,7 @@ TEST(LlvmLibcSharedMathTest, AllFloat) {
EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::acoshf(1.0f));
EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::asinf(0.0f));
EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::asinhf(0.0f));
+ EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::asinpif(0.0f));
EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::atan2f(0.0f, 0.0f));
EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::atanf(0.0f));
EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::atanhf(0.0f));
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index ff5c511922171..28e806ffc3730 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -2461,6 +2461,17 @@ add_fp_unittest(
libc.src.math.asinf16
)
+add_fp_unittest(
+ asinpif_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ asinpif_test.cpp
+ DEPENDS
+ libc.src.math.asinpif
+)
+
add_fp_unittest(
asinpif16_test
NEED_MPFR
diff --git a/libc/test/src/math/asinpif_test.cpp b/libc/test/src/math/asinpif_test.cpp
new file mode 100644
index 0000000000000..073d11bc53f21
--- /dev/null
+++ b/libc/test/src/math/asinpif_test.cpp
@@ -0,0 +1,38 @@
+//===-- Unittests for asinpif (MPFR) --------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/asinpif.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
+
+namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
+
+using LlvmLibcAsinpifTest = LIBC_NAMESPACE::testing::FPTest<float>;
+
+static constexpr mpfr::RoundingMode ROUNDING_MODES[] = {
+ mpfr::RoundingMode::Nearest,
+ mpfr::RoundingMode::Upward,
+ mpfr::RoundingMode::Downward,
+ mpfr::RoundingMode::TowardZero,
+};
+
+TEST_F(LlvmLibcAsinpifTest, InFloatRange) {
+ constexpr uint32_t COUNT = 100'000;
+ // Test in [-1, 1]
+ const uint32_t STEP = 0x3F800000 / COUNT; // step through [0, 1.0f] in bits
+ for (mpfr::RoundingMode rm : ROUNDING_MODES) {
+ for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
+ float x = FPBits(v).get_val();
+ ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asinpi, x,
+ LIBC_NAMESPACE::asinpif(x), 0.5);
+ ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asinpi, -x,
+ LIBC_NAMESPACE::asinpif(-x), 0.5);
+ }
+ }
+}
diff --git a/libc/test/src/math/exhaustive/CMakeLists.txt b/libc/test/src/math/exhaustive/CMakeLists.txt
index 9ca4f93e6c411..877d653a26291 100644
--- a/libc/test/src/math/exhaustive/CMakeLists.txt
+++ b/libc/test/src/math/exhaustive/CMakeLists.txt
@@ -518,6 +518,22 @@ add_fp_unittest(
-lpthread
)
+add_fp_unittest(
+ asinpif_test
+ NO_RUN_POSTBUILD
+ NEED_MPFR
+ SUITE
+ libc_math_exhaustive_tests
+ SRCS
+ asinpif_test.cpp
+ DEPENDS
+ .exhaustive_test
+ libc.src.math.asinpif
+ libc.src.__support.FPUtil.fp_bits
+ LINK_LIBRARIES
+ -lpthread
+)
+
add_fp_unittest(
atanhf_test
NO_RUN_POSTBUILD
diff --git a/libc/test/src/math/exhaustive/asinpif_test.cpp b/libc/test/src/math/exhaustive/asinpif_test.cpp
new file mode 100644
index 0000000000000..b327e350a0563
--- /dev/null
+++ b/libc/test/src/math/exhaustive/asinpif_test.cpp
@@ -0,0 +1,33 @@
+//===-- Exhaustive test for asinpif ---------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "exhaustive_test.h"
+#include "src/math/asinpif.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
+
+namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
+
+using LlvmLibcAsinfExhaustiveTest =
+ LlvmLibcUnaryOpExhaustiveMathTest<float, mpfr::Operation::Asinpi,
+ LIBC_NAMESPACE::asinpif>;
+
+// Range: [0, Inf];
+static constexpr uint32_t POS_START = 0x0000'0000U;
+static constexpr uint32_t POS_STOP = 0x7f80'0000U;
+
+TEST_F(LlvmLibcAsinfExhaustiveTest, PostiveRange) {
+ test_full_range_all_roundings(POS_START, POS_STOP);
+}
+
+// Range: [-Inf, 0];
+static constexpr uint32_t NEG_START = 0xb000'0000U;
+static constexpr uint32_t NEG_STOP = 0xff80'0000U;
+
+TEST_F(LlvmLibcAsinfExhaustiveTest, NegativeRange) {
+ test_full_range_all_roundings(NEG_START, NEG_STOP);
+}
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 5afd3a9f22967..a4e7481be5c96 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -4703,6 +4703,18 @@ add_fp_unittest(
libc.src.math.asinhf16
)
+add_fp_unittest(
+ asinpif_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ asinpif_test.cpp
+ DEPENDS
+ libc.hdr.errno_macros
+ libc.src.math.asinpif
+ libc.src.__support.FPUtil.fp_bits
+)
+
add_fp_unittest(
asinpif16_test
NEED_MPFR
diff --git a/libc/test/src/math/smoke/asinpif_test.cpp b/libc/test/src/math/smoke/asinpif_test.cpp
new file mode 100644
index 0000000000000..87ea7259f6300
--- /dev/null
+++ b/libc/test/src/math/smoke/asinpif_test.cpp
@@ -0,0 +1,44 @@
+//===-- Unittests for asinpif ---------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "hdr/errno_macros.h"
+#include "hdr/math_macros.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/math/asinpif.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+
+#include "hdr/stdint_proxy.h"
+
+using LlvmLibcAsinpifTest = LIBC_NAMESPACE::testing::FPTest<float>;
+
+TEST_F(LlvmLibcAsinpifTest, SpecialNumbers) {
+ EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, LIBC_NAMESPACE::asinpif(sNaN), FE_INVALID);
+ EXPECT_MATH_ERRNO(0);
+
+ EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::asinpif(aNaN));
+ EXPECT_MATH_ERRNO(0);
+
+ EXPECT_FP_EQ_ALL_ROUNDING(0.0f, LIBC_NAMESPACE::asinpif(0.0f));
+ EXPECT_MATH_ERRNO(0);
+
+ EXPECT_FP_EQ_ALL_ROUNDING(-0.0f, LIBC_NAMESPACE::asinpif(-0.0f));
+ EXPECT_MATH_ERRNO(0);
+
+ EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::asinpif(inf));
+ EXPECT_MATH_ERRNO(EDOM);
+
+ EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::asinpif(neg_inf));
+ EXPECT_MATH_ERRNO(EDOM);
+
+ EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::asinpif(2.0f));
+ EXPECT_MATH_ERRNO(EDOM);
+
+ EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::asinpif(-2.0f));
+ EXPECT_MATH_ERRNO(EDOM);
+}
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index ae7228c52d3c0..52685f180de54 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2500,6 +2500,23 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_math_asinpif",
+ hdrs = ["src/__support/math/asinpif.h"],
+ deps = [
+ ":__support_fputil_cast",
+ ":__support_fputil_except_value_utils",
+ ":__support_fputil_fenv_impl",
+ ":__support_fputil_fp_bits",
+ ":__support_fputil_multiply_add",
+ ":__support_fputil_polyeval",
+ ":__support_fputil_rounding_mode",
+ ":__support_fputil_sqrt",
+ ":__support_macros_config",
+ ":__support_macros_optimization",
+ ],
+)
+
libc_support_library(
name = "__support_math_atan_utils",
hdrs = ["src/__support/math/atan_utils.h"],
@@ -4123,6 +4140,13 @@ libc_math_function(
],
)
+libc_math_function(
+ name = "asinpif",
+ additional_deps = [
+ ":__support_math_asinpif",
+ ],
+)
+
libc_math_function(
name = "atanf",
additional_deps = [
More information about the libc-commits
mailing list