[libc-commits] [libc] [llvm] [libc] Fix math smoke powf_test's tolerance settings (PR #229390)

Victor Campos via libc-commits libc-commits at lists.llvm.org
Tue Oct 6 05:07:36 PDT 2026


https://github.com/vhscampos created https://github.com/llvm/llvm-project/pull/229390

The `LIST_POWF_TESTS` macro takes a `tolerance` integer argument. According to the `powf` implementation, single-precision FP evaluation ought to have a tolerance of 1, where it ought to be 0 with double-precision.

If no particular evaluation precision is requested, then libc chooses one depending on the `LIBC_MATH` fields. This is called the Default path by the test. However, the test assumes that the Default is always double-precision evaluation.

This is not the case in baremetal targets.
`libc/config/baremetal/config.json` sets `LIBC_MATH` fields so that `powf` ends up going with single-precision eval. Therefore the tolerance for the Default case has to peek at which implementation was chosen.

Assisted-by: Codex.

>From b916eb3b83280170a90175b6bef6cfece96bf221 Mon Sep 17 00:00:00 2001
From: Victor Campos <victor.campos at arm.com>
Date: Tue, 6 Oct 2026 11:50:42 +0100
Subject: [PATCH] [libc] Fix math smoke powf_test's tolerance settings

The `LIST_POWF_TESTS` macro takes a `tolerance` integer argument.
According to the `powf` implementation, single-precision FP evaluation
ought to have a tolerance of 1, where it ought to be 0 with
double-precision.

If no particular evaluation precision is requested, then libc chooses
one depending on the `LIBC_MATH` fields. This is called the Default path
by the test. However, the test assumes that the Default is always
double-precision evaluation.

This is not the case in baremetal targets.
`libc/config/baremetal/config.json` sets `LIBC_MATH` fields so that
`powf` ends up going with single-precision eval. Therefore the tolerance
for the Default case has to peek at which implementation was chosen.

Assisted-by: Codex.
---
 libc/test/src/math/smoke/CMakeLists.txt                    | 1 +
 libc/test/src/math/smoke/powf_test.cpp                     | 7 ++++++-
 .../libc/test/src/math/smoke/BUILD.bazel                   | 1 +
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 6037e373fad14..758129434de7a 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -5363,6 +5363,7 @@ add_fp_unittest(
     powf_test.cpp
   DEPENDS
     libc.src.math.powf
+    libc.src.__support.math.powf
     libc.src.__support.math.powf_double_eval
     libc.src.__support.math.powf_float_eval
     libc.src.__support.FPUtil.fp_bits
diff --git a/libc/test/src/math/smoke/powf_test.cpp b/libc/test/src/math/smoke/powf_test.cpp
index c20c02ddd8957..bd852926cd647 100644
--- a/libc/test/src/math/smoke/powf_test.cpp
+++ b/libc/test/src/math/smoke/powf_test.cpp
@@ -15,6 +15,7 @@
 #include "hdr/math_macros.h"
 #include "hdr/stdint_proxy.h"
 #include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/math/powf.h"
 #include "src/__support/math/powf_double_eval.h"
 #include "src/__support/math/powf_float_eval.h"
 #include "src/math/powf.h"
@@ -294,7 +295,11 @@ class PowfTest : public LIBC_NAMESPACE::testing::FPTest<float> {
   LIST_POWF_FTZ_DAZ_TESTS(suffix, func)                                        \
   static_assert(true, "Require semicolon.")
 
-LIST_POWF_TESTS(Default, LIBC_NAMESPACE::powf, /*tolerance=*/0);
+LIST_POWF_TESTS(Default, LIBC_NAMESPACE::powf,
+                /*tolerance=*/LIBC_NAMESPACE::math::powf ==
+                        LIBC_NAMESPACE::math::float_eval::powf
+                    ? 1
+                    : 0);
 LIST_POWF_TESTS(DoubleEval, LIBC_NAMESPACE::math::double_eval::powf,
                 /*tolerance=*/0);
 LIST_POWF_TESTS(FloatEval, LIBC_NAMESPACE::math::float_eval::powf,
diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
index d7492346e08cf..06e43a622edef 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
@@ -1813,6 +1813,7 @@ math_test(name = "pow")
 math_test(
     name = "powf",
     deps = [
+        "//libc:__support_math_powf",
         "//libc:__support_math_powf_double_eval",
         "//libc:__support_math_powf_float_eval",
     ],



More information about the libc-commits mailing list