[libc-commits] [libc] [libc][math] Return a floating NaN from the cbrtf16 signaling path (PR #236478)

via libc-commits libc-commits at lists.llvm.org
Wed Oct 28 20:25:12 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: sriramshastry

<details>
<summary>Changes</summary>

Return a floating quiet NaN from the cbrtf16 signaling NaN branch instead of numerically
converting its integer encoding. Use conditional invalid reporting and add a regression
that checks NaN classification and FE_INVALID.

## Validation

Tested independently at ea08830d976fbe61384695d33e0acafee8d88737 on x86-64 Linux,
Release, GCC 13 and Clang 18. Both baseline smoke target configurations fail per
compiler; both patched configurations pass. The regression checks NaN classification,
explicit quietness, FE_INVALID, and errno.  Changed-hunk formatting and whitespace
checks pass. The ordinary cube-root polynomial is untouched.

## Scope and Review

PR #<!-- -->199982's complete libc head tree at b1cf1d1c6ad9b0831ce2a1fa0a1ce3519b219af9
contains only include/math.yaml, not a competing implementation or regression. Its
overall diff is abnormal and deletion-heavy, not a clean registration-only patch. This
resolves that specific suspected behavioral duplicate; submission-time duplicate checks
remain required. NaN payload/sign preservation is not claimed.

## Updated submission base

Submission base: 10c142fa799e258285b6cfb8fce153864586152d.
The standalone baseline/patched results above remain recorded at their original
tested snapshot. At this newer base, the fourteen-only combined suite passes
150 native configurations per compiler and twelve four-mode numerical runs,
with zero value or scoped-reporting mismatches.

Signed-off-by: sriramshastry <sriramshastry@<!-- -->gmail.com>


---
Full diff: https://github.com/llvm/llvm-project/pull/236478.diff


2 Files Affected:

- (modified) libc/src/__support/math/cbrtf16.h (+2-2) 
- (modified) libc/test/src/math/smoke/cbrtf16_test.cpp (+8) 


``````````diff
diff --git a/libc/src/__support/math/cbrtf16.h b/libc/src/__support/math/cbrtf16.h
index 86fe985e75a74d..0ad2a4f7bd8cab 100644
--- a/libc/src/__support/math/cbrtf16.h
+++ b/libc/src/__support/math/cbrtf16.h
@@ -89,8 +89,8 @@ LIBC_INLINE constexpr float16 cbrtf16(float16 x) {
   // cbrtf16(0) = 0, cbrtf16(NaN) = NaN
   if (LIBC_UNLIKELY(x_abs == 0 || x_abs >= 0x7C00)) {
     if (x_bits.is_signaling_nan()) {
-      fputil::raise_except(FE_INVALID);
-      return FPBits::quiet_nan().uintval();
+      fputil::raise_except_if_required(FE_INVALID);
+      return FPBits::quiet_nan().get_val();
     }
     return x;
   }
diff --git a/libc/test/src/math/smoke/cbrtf16_test.cpp b/libc/test/src/math/smoke/cbrtf16_test.cpp
index 2caf1e6beacb25..269c87218ca8a7 100644
--- a/libc/test/src/math/smoke/cbrtf16_test.cpp
+++ b/libc/test/src/math/smoke/cbrtf16_test.cpp
@@ -31,3 +31,11 @@ TEST_F(LlvmLibcCbrtf16Test, SpecialNumbers) {
   EXPECT_FP_EQ_ALL_ROUNDING(40.0f, LIBC_NAMESPACE::cbrtf16(0x1.f4p15));
   EXPECT_FP_EQ_ALL_ROUNDING(-40.0f, LIBC_NAMESPACE::cbrtf16(-0x1.f4p15));
 }
+
+TEST_F(LlvmLibcCbrtf16Test, SignalingNaNValue) {
+  float16 result = zero;
+  EXPECT_FP_EQ_WITH_EXCEPTION_ALL_ROUNDING(
+      aNaN, result = LIBC_NAMESPACE::cbrtf16(sNaN), FE_INVALID);
+  EXPECT_MATH_ERRNO(0);
+  EXPECT_FALSE(FPBits(result).is_signaling_nan());
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/236478


More information about the libc-commits mailing list