[libc-commits] [libc] [libc][math] Adding constexpr to tests for Double-type math functions (PR #200681)
via libc-commits
libc-commits at lists.llvm.org
Sun May 31 12:04:40 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Zorojuro (Sukumarsawant)
<details>
<summary>Changes</summary>
Similar to
```CPP
constexpr uint64_t X_COUNT = 123;
constexpr uint64_t X_START = FPBits(0.25).uintval();
constexpr uint64_t X_STOP = FPBits(4.0).uintval();
constexpr uint64_t X_STEP = (X_STOP - X_START) / X_COUNT;
constexpr uint64_t Y_COUNT = 137;
constexpr uint64_t Y_START = FPBits(0.25).uintval();
constexpr uint64_t Y_STOP = FPBits(4.0).uintval();
constexpr uint64_t Y_STEP = (Y_STOP - Y_START) / Y_COUNT;
```
in [atan2_test.cpp](https://github.com/llvm/llvm-project/blob/main/libc/test/src/math/atan2_test.cpp)
This PR tends to add constexpr to all double function tests-only
Assisted using Copilot.
---
Full diff: https://github.com/llvm/llvm-project/pull/200681.diff
10 Files Affected:
- (modified) libc/test/src/math/acos_test.cpp (+3-3)
- (modified) libc/test/src/math/asin_test.cpp (+3-3)
- (modified) libc/test/src/math/atan_test.cpp (+3-3)
- (modified) libc/test/src/math/cbrt_test.cpp (+3-3)
- (modified) libc/test/src/math/exp10_test.cpp (+3-3)
- (modified) libc/test/src/math/exp2_test.cpp (+3-3)
- (modified) libc/test/src/math/exp_test.cpp (+3-3)
- (modified) libc/test/src/math/expm1_test.cpp (+3-3)
- (modified) libc/test/src/math/sin_test.cpp (+3-3)
- (modified) libc/test/src/math/sincos_test.cpp (+3-3)
``````````diff
diff --git a/libc/test/src/math/acos_test.cpp b/libc/test/src/math/acos_test.cpp
index 843a43ee52440..48b88892b8248 100644
--- a/libc/test/src/math/acos_test.cpp
+++ b/libc/test/src/math/acos_test.cpp
@@ -26,9 +26,9 @@ using LIBC_NAMESPACE::testing::tlog;
TEST_F(LlvmLibcAcosTest, InDoubleRange) {
constexpr uint64_t COUNT = 1'231;
- uint64_t START = FPBits(0x1.0p-60).uintval();
- uint64_t STOP = FPBits(1.0).uintval();
- uint64_t STEP = (STOP - START) / COUNT;
+ constexpr uint64_t START = FPBits(0x1.0p-60).uintval();
+ constexpr uint64_t STOP = FPBits(1.0).uintval();
+ constexpr uint64_t STEP = (STOP - START) / COUNT;
auto test = [&](mpfr::RoundingMode rounding_mode) {
mpfr::ForceRoundingMode __r(rounding_mode);
diff --git a/libc/test/src/math/asin_test.cpp b/libc/test/src/math/asin_test.cpp
index 0ac891cd09439..2f3028e19388a 100644
--- a/libc/test/src/math/asin_test.cpp
+++ b/libc/test/src/math/asin_test.cpp
@@ -26,9 +26,9 @@ using LIBC_NAMESPACE::testing::tlog;
TEST_F(LlvmLibcAsinTest, InDoubleRange) {
constexpr uint64_t COUNT = 1'231;
- uint64_t START = FPBits(0x1.0p-60).uintval();
- uint64_t STOP = FPBits(1.0).uintval();
- uint64_t STEP = (STOP - START) / COUNT;
+ constexpr uint64_t START = FPBits(0x1.0p-60).uintval();
+ constexpr uint64_t STOP = FPBits(1.0).uintval();
+ constexpr uint64_t STEP = (STOP - START) / COUNT;
auto test = [&](mpfr::RoundingMode rounding_mode) {
mpfr::ForceRoundingMode __r(rounding_mode);
diff --git a/libc/test/src/math/atan_test.cpp b/libc/test/src/math/atan_test.cpp
index 9622d3f9687e8..ff50c4c3ad052 100644
--- a/libc/test/src/math/atan_test.cpp
+++ b/libc/test/src/math/atan_test.cpp
@@ -20,9 +20,9 @@ using LIBC_NAMESPACE::testing::tlog;
TEST_F(LlvmLibcAtanTest, InDoubleRange) {
constexpr uint64_t COUNT = 1'231;
- uint64_t START = LIBC_NAMESPACE::fputil::FPBits<double>(0x1.0p-60).uintval();
- uint64_t STOP = LIBC_NAMESPACE::fputil::FPBits<double>(0x1.0p60).uintval();
- uint64_t STEP = (STOP - START) / COUNT;
+ constexpr uint64_t START = FPBits(0x1.0p-60).uintval();
+ constexpr uint64_t STOP = FPBits(0x1.0p60).uintval();
+ constexpr uint64_t STEP = (STOP - START) / COUNT;
auto test = [&](mpfr::RoundingMode rounding_mode) {
mpfr::ForceRoundingMode __r(rounding_mode);
diff --git a/libc/test/src/math/cbrt_test.cpp b/libc/test/src/math/cbrt_test.cpp
index 553f0a8104342..da3db424d2423 100644
--- a/libc/test/src/math/cbrt_test.cpp
+++ b/libc/test/src/math/cbrt_test.cpp
@@ -28,9 +28,9 @@ using LIBC_NAMESPACE::testing::tlog;
TEST_F(LlvmLibcCbrtTest, InDoubleRange) {
constexpr uint64_t COUNT = 1'231;
- uint64_t START = FPBits(1.0).uintval();
- uint64_t STOP = FPBits(8.0).uintval();
- uint64_t STEP = (STOP - START) / COUNT;
+ constexpr uint64_t START = FPBits(1.0).uintval();
+ constexpr uint64_t STOP = FPBits(8.0).uintval();
+ constexpr uint64_t STEP = (STOP - START) / COUNT;
auto test = [&](mpfr::RoundingMode rounding_mode) {
mpfr::ForceRoundingMode force_rounding(rounding_mode);
diff --git a/libc/test/src/math/exp10_test.cpp b/libc/test/src/math/exp10_test.cpp
index 4257dd0d1458b..f31b3b2957853 100644
--- a/libc/test/src/math/exp10_test.cpp
+++ b/libc/test/src/math/exp10_test.cpp
@@ -91,9 +91,9 @@ TEST_F(LlvmLibcExp10Test, TrickyInputs) {
TEST_F(LlvmLibcExp10Test, InDoubleRange) {
constexpr uint64_t COUNT = 1'231;
- uint64_t START = LIBC_NAMESPACE::fputil::FPBits<double>(0.25).uintval();
- uint64_t STOP = LIBC_NAMESPACE::fputil::FPBits<double>(4.0).uintval();
- uint64_t STEP = (STOP - START) / COUNT;
+ constexpr uint64_t START = FPBits(0.25).uintval();
+ constexpr uint64_t STOP = FPBits(4.0).uintval();
+ constexpr uint64_t STEP = (STOP - START) / COUNT;
auto test = [&](mpfr::RoundingMode rounding_mode) {
mpfr::ForceRoundingMode __r(rounding_mode);
diff --git a/libc/test/src/math/exp2_test.cpp b/libc/test/src/math/exp2_test.cpp
index 324cafd926756..f388a1b57fa4a 100644
--- a/libc/test/src/math/exp2_test.cpp
+++ b/libc/test/src/math/exp2_test.cpp
@@ -60,9 +60,9 @@ TEST_F(LlvmLibcExp2Test, TrickyInputs) {
TEST_F(LlvmLibcExp2Test, InDoubleRange) {
constexpr uint64_t COUNT = 1'231;
- uint64_t START = LIBC_NAMESPACE::fputil::FPBits<double>(0.25).uintval();
- uint64_t STOP = LIBC_NAMESPACE::fputil::FPBits<double>(4.0).uintval();
- uint64_t STEP = (STOP - START) / COUNT;
+ constexpr uint64_t START = FPBits(0.25).uintval();
+ constexpr uint64_t STOP = FPBits(4.0).uintval();
+ constexpr uint64_t STEP = (STOP - START) / COUNT;
auto test = [&](mpfr::RoundingMode rounding_mode) {
mpfr::ForceRoundingMode __r(rounding_mode);
diff --git a/libc/test/src/math/exp_test.cpp b/libc/test/src/math/exp_test.cpp
index 5a785fbaee4fd..fb4646f790e98 100644
--- a/libc/test/src/math/exp_test.cpp
+++ b/libc/test/src/math/exp_test.cpp
@@ -64,9 +64,9 @@ TEST_F(LlvmLibcExpTest, TrickyInputs) {
TEST_F(LlvmLibcExpTest, InDoubleRange) {
constexpr uint64_t COUNT = 1'231;
- uint64_t START = LIBC_NAMESPACE::fputil::FPBits<double>(0.25).uintval();
- uint64_t STOP = LIBC_NAMESPACE::fputil::FPBits<double>(4.0).uintval();
- uint64_t STEP = (STOP - START) / COUNT;
+ constexpr uint64_t START = FPBits(0.25).uintval();
+ constexpr uint64_t STOP = FPBits(4.0).uintval();
+ constexpr uint64_t STEP = (STOP - START) / COUNT;
auto test = [&](mpfr::RoundingMode rounding_mode) {
mpfr::ForceRoundingMode __r(rounding_mode);
diff --git a/libc/test/src/math/expm1_test.cpp b/libc/test/src/math/expm1_test.cpp
index 8ca9b7710427b..a8c3df471417e 100644
--- a/libc/test/src/math/expm1_test.cpp
+++ b/libc/test/src/math/expm1_test.cpp
@@ -50,9 +50,9 @@ TEST_F(LlvmLibcExpm1Test, TrickyInputs) {
TEST_F(LlvmLibcExpm1Test, InDoubleRange) {
constexpr uint64_t COUNT = 1'231;
- uint64_t START = LIBC_NAMESPACE::fputil::FPBits<double>(0.25).uintval();
- uint64_t STOP = LIBC_NAMESPACE::fputil::FPBits<double>(4.0).uintval();
- uint64_t STEP = (STOP - START) / COUNT;
+ constexpr uint64_t START = FPBits(0.25).uintval();
+ constexpr uint64_t STOP = FPBits(4.0).uintval();
+ constexpr uint64_t STEP = (STOP - START) / COUNT;
auto test = [&](mpfr::RoundingMode rounding_mode) {
mpfr::ForceRoundingMode __r(rounding_mode);
diff --git a/libc/test/src/math/sin_test.cpp b/libc/test/src/math/sin_test.cpp
index 79c803887b34f..40c16fe86801c 100644
--- a/libc/test/src/math/sin_test.cpp
+++ b/libc/test/src/math/sin_test.cpp
@@ -59,9 +59,9 @@ TEST_F(LlvmLibcSinTest, TrickyInputs) {
TEST_F(LlvmLibcSinTest, InDoubleRange) {
constexpr uint64_t COUNT = 1'231;
- uint64_t START = LIBC_NAMESPACE::fputil::FPBits<double>(0x1.0p-50).uintval();
- uint64_t STOP = LIBC_NAMESPACE::fputil::FPBits<double>(0x1.0p200).uintval();
- uint64_t STEP = (STOP - START) / COUNT;
+ constexpr uint64_t START = FPBits(0x1.0p-50).uintval();
+ constexpr uint64_t STOP = FPBits(0x1.0p200).uintval();
+ constexpr uint64_t STEP = (STOP - START) / COUNT;
auto test = [&](mpfr::RoundingMode rounding_mode) {
mpfr::ForceRoundingMode __r(rounding_mode);
diff --git a/libc/test/src/math/sincos_test.cpp b/libc/test/src/math/sincos_test.cpp
index 343afaae5f340..ee633acfe5147 100644
--- a/libc/test/src/math/sincos_test.cpp
+++ b/libc/test/src/math/sincos_test.cpp
@@ -111,9 +111,9 @@ TEST_F(LlvmLibcSincosTest, TrickyInputs) {
TEST_F(LlvmLibcSincosTest, InDoubleRange) {
constexpr uint64_t COUNT = 1'231;
- uint64_t START = LIBC_NAMESPACE::fputil::FPBits<double>(0x1.0p-50).uintval();
- uint64_t STOP = LIBC_NAMESPACE::fputil::FPBits<double>(0x1.0p200).uintval();
- uint64_t STEP = (STOP - START) / COUNT;
+ constexpr uint64_t START = FPBits(0x1.0p-50).uintval();
+ constexpr uint64_t STOP = FPBits(0x1.0p200).uintval();
+ constexpr uint64_t STEP = (STOP - START) / COUNT;
for (uint64_t i = 0, v = START; i <= COUNT; ++i, v += STEP) {
double x = FPBits(v).get_val();
``````````
</details>
https://github.com/llvm/llvm-project/pull/200681
More information about the libc-commits
mailing list