aboutsummaryrefslogtreecommitdiff
path: root/libc/src
diff options
context:
space:
mode:
authorMuhammad Bassiouni <60100307+bassiounix@users.noreply.github.com>2025-07-21 20:48:57 +0300
committerGitHub <noreply@github.com>2025-07-21 20:48:57 +0300
commit2865f1ba966c21d4ebff610875394ce9c7a5ff38 (patch)
treec92b6f4e6c71872a831dbbc2e2e2300394e28e57 /libc/src
parentf7347e9f784860d9482ad8fe757761514cceff31 (diff)
downloadllvm-2865f1ba966c21d4ebff610875394ce9c7a5ff38.zip
llvm-2865f1ba966c21d4ebff610875394ce9c7a5ff38.tar.gz
llvm-2865f1ba966c21d4ebff610875394ce9c7a5ff38.tar.bz2
[libc][math] add smoke tests to shared/math.h (#149741)
Adding smoke tests for shared math header. part of #147386
Diffstat (limited to 'libc/src')
-rw-r--r--libc/src/__support/math/acos.h6
-rw-r--r--libc/src/__support/math/acosf.h8
-rw-r--r--libc/src/__support/math/asin_utils.h4
-rw-r--r--libc/src/__support/math/inv_trigf_utils.h4
-rw-r--r--libc/src/math/generic/asin.cpp1
-rw-r--r--libc/src/math/generic/asinf.cpp1
-rw-r--r--libc/src/math/generic/atan2f.cpp1
-rw-r--r--libc/src/math/generic/atanf.cpp1
8 files changed, 21 insertions, 5 deletions
diff --git a/libc/src/__support/math/acos.h b/libc/src/__support/math/acos.h
index a7287f1..7c9fc76 100644
--- a/libc/src/__support/math/acos.h
+++ b/libc/src/__support/math/acos.h
@@ -24,10 +24,10 @@ namespace LIBC_NAMESPACE_DECL {
namespace math {
-using DoubleDouble = fputil::DoubleDouble;
-using Float128 = fputil::DyadicFloat<128>;
-
static constexpr double acos(double x) {
+ using DoubleDouble = fputil::DoubleDouble;
+ using Float128 = fputil::DyadicFloat<128>;
+ using namespace asin_internal;
using FPBits = fputil::FPBits<double>;
FPBits xbits(x);
diff --git a/libc/src/__support/math/acosf.h b/libc/src/__support/math/acosf.h
index 941c39f..153087e 100644
--- a/libc/src/__support/math/acosf.h
+++ b/libc/src/__support/math/acosf.h
@@ -22,7 +22,10 @@ namespace LIBC_NAMESPACE_DECL {
namespace math {
+namespace acosf_internal {
+
#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+
static constexpr size_t N_EXCEPTS = 4;
// Exceptional values when |x| <= 0.5
@@ -37,9 +40,14 @@ static constexpr fputil::ExceptValues<float, N_EXCEPTS> ACOSF_EXCEPTS = {{
// x = -0x1.04c444p-12, acosf(x) = 0x1.923p0 (RZ)
{0xb9826222, 0x3fc91800, 1, 0, 1},
}};
+
#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
+} // namespace acosf_internal
+
static constexpr float acosf(float x) {
+ using namespace acosf_internal;
+ using namespace inv_trigf_utils_internal;
using FPBits = typename fputil::FPBits<float>;
FPBits xbits(x);
diff --git a/libc/src/__support/math/asin_utils.h b/libc/src/__support/math/asin_utils.h
index 3146444..e0c9096 100644
--- a/libc/src/__support/math/asin_utils.h
+++ b/libc/src/__support/math/asin_utils.h
@@ -19,7 +19,7 @@
namespace LIBC_NAMESPACE_DECL {
-namespace {
+namespace asin_internal {
using DoubleDouble = fputil::DoubleDouble;
using Float128 = fputil::DyadicFloat<128>;
@@ -567,7 +567,7 @@ LIBC_INLINE static constexpr Float128 asin_eval(const Float128 &u,
#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-} // anonymous namespace
+} // namespace asin_internal
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/__support/math/inv_trigf_utils.h b/libc/src/__support/math/inv_trigf_utils.h
index b8f4914..4a8fbec 100644
--- a/libc/src/__support/math/inv_trigf_utils.h
+++ b/libc/src/__support/math/inv_trigf_utils.h
@@ -16,6 +16,8 @@
namespace LIBC_NAMESPACE_DECL {
+namespace inv_trigf_utils_internal {
+
// PI and PI / 2
static constexpr double M_MATH_PI = 0x1.921fb54442d18p+1;
static constexpr double M_MATH_PI_2 = 0x1.921fb54442d18p+0;
@@ -175,6 +177,8 @@ LIBC_INLINE static double asin_eval(double xsq) {
return fputil::multiply_add(xsq, r2, r1);
}
+} // namespace inv_trigf_utils_internal
+
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC___SUPPORT_MATH_INV_TRIGF_UTILS_H
diff --git a/libc/src/math/generic/asin.cpp b/libc/src/math/generic/asin.cpp
index c033597..d286fce 100644
--- a/libc/src/math/generic/asin.cpp
+++ b/libc/src/math/generic/asin.cpp
@@ -25,6 +25,7 @@ using DoubleDouble = fputil::DoubleDouble;
using Float128 = fputil::DyadicFloat<128>;
LLVM_LIBC_FUNCTION(double, asin, (double x)) {
+ using namespace asin_internal;
using FPBits = fputil::FPBits<double>;
FPBits xbits(x);
diff --git a/libc/src/math/generic/asinf.cpp b/libc/src/math/generic/asinf.cpp
index c8d6b38..77d6de9 100644
--- a/libc/src/math/generic/asinf.cpp
+++ b/libc/src/math/generic/asinf.cpp
@@ -44,6 +44,7 @@ static constexpr fputil::ExceptValues<float, N_EXCEPTS> ASINF_EXCEPTS_HI = {{
#endif // !LIBC_MATH_HAS_SKIP_ACCURATE_PASS
LLVM_LIBC_FUNCTION(float, asinf, (float x)) {
+ using namespace inv_trigf_utils_internal;
using FPBits = typename fputil::FPBits<float>;
FPBits xbits(x);
diff --git a/libc/src/math/generic/atan2f.cpp b/libc/src/math/generic/atan2f.cpp
index 0a768494..32b977f 100644
--- a/libc/src/math/generic/atan2f.cpp
+++ b/libc/src/math/generic/atan2f.cpp
@@ -236,6 +236,7 @@ float atan2f_double_double(double num_d, double den_d, double q_d, int idx,
// which is about rounding errors of double-double (2^-104).
LLVM_LIBC_FUNCTION(float, atan2f, (float y, float x)) {
+ using namespace inv_trigf_utils_internal;
using FPBits = typename fputil::FPBits<float>;
constexpr double IS_NEG[2] = {1.0, -1.0};
constexpr double PI = 0x1.921fb54442d18p1;
diff --git a/libc/src/math/generic/atanf.cpp b/libc/src/math/generic/atanf.cpp
index d12456c..22f962e 100644
--- a/libc/src/math/generic/atanf.cpp
+++ b/libc/src/math/generic/atanf.cpp
@@ -20,6 +20,7 @@
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(float, atanf, (float x)) {
+ using namespace inv_trigf_utils_internal;
using FPBits = typename fputil::FPBits<float>;
constexpr double FINAL_SIGN[2] = {1.0, -1.0};