[libc-commits] [libc] [libc][math] Fix -Wc++23-extensions warnings in erfcf16 and erff16. (PR #215613)
via libc-commits
libc-commits at lists.llvm.org
Thu Aug 13 21:31:14 PDT 2026
https://github.com/zhangweize9-cyber updated https://github.com/llvm/llvm-project/pull/215613
>From 218a0508bc8c82c66d5ee8490f47196077eb15f0 Mon Sep 17 00:00:00 2001
From: zhangweize9-cyber <zhangweize9 at gmail.com>
Date: Wed, 12 Aug 2026 00:33:40 +0800
Subject: [PATCH] [libc][math] Fix -Wc++23-extensions warnings in erfcf16 and
erff16.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Change the original logic—which directly returns a fixed value—to use `fputil::cast` for the calculation.
---
libc/src/__support/math/erfcf16.h | 4 ++--
libc/src/__support/math/erff16.h | 7 +++++--
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/libc/src/__support/math/erfcf16.h b/libc/src/__support/math/erfcf16.h
index ad096527855d5..7608586001996 100644
--- a/libc/src/__support/math/erfcf16.h
+++ b/libc/src/__support/math/erfcf16.h
@@ -93,7 +93,7 @@ LIBC_INLINE float16 erfcf16(float16 x) {
}
if (LIBC_UNLIKELY(x_abs == 0))
- return 1.0f16;
+ return fputil::cast<float16>(1.0f);
// Asymptotic behavior: erfc(x) rounds to 0 or 2 for |x| >= 4.0.
if (LIBC_UNLIKELY(x_abs >= 0x4400U)) { // |x| >= 4.0
@@ -109,7 +109,7 @@ LIBC_INLINE float16 erfcf16(float16 x) {
if (fputil::fenv_is_round_up())
return FPBits::min_subnormal().get_val();
#endif
- return 0.0f16;
+ return FPBits::zero().get_val();
}
// Polynomial approximation:
diff --git a/libc/src/__support/math/erff16.h b/libc/src/__support/math/erff16.h
index 8e3a92c092e22..68b6575957989 100644
--- a/libc/src/__support/math/erff16.h
+++ b/libc/src/__support/math/erff16.h
@@ -134,9 +134,11 @@ LIBC_INLINE float16 erff16(float16 x) {
return x;
}
// Inf -> returns 1.0 or -1.0
- return is_neg ? -1.0f16 : 1.0f16;
+ constexpr float16 ONE_F16 = fputil::cast<float16>(1.0f);
+ return is_neg ? -ONE_F16 : ONE_F16;
}
+ // FIXME: Handle f16 constant emission without triggering -Wc++23-extensions
return fputil::cast<float16>(is_neg ? -1.0f - xf * 0x1.0p-28f
: 1.0f - xf * 0x1.0p-28f);
}
@@ -144,7 +146,8 @@ LIBC_INLINE float16 erff16(float16 x) {
// Polynomial approximation:
// erf(x) ~ x * (c0 + c1 * x^2 + c2 * x^4 + ... + c7 * x^14)
- int idx = static_cast<int>(xbits.abs().get_val() * 8.0f16);
+ constexpr float16 EIGHT_F16 = fputil::cast<float16>(8.0f);
+ int idx = static_cast<int>(xbits.abs().get_val() * EIGHT_F16);
float xsq = xf * xf;
float x4 = xsq * xsq;
More information about the libc-commits
mailing list