[libc-commits] [libc] [libc][math] Qualify fdim funtions to constexpr (PR #194137)

Kiriti Ponduri via libc-commits libc-commits at lists.llvm.org
Sat Apr 25 14:25:02 PDT 2026


================
@@ -132,11 +148,15 @@ add_or_sub(InType x, InType y) {
   InType y_abs = y_bits.abs().get_val();
 
   if (x_abs == y_abs && !is_effectively_add) {
-    switch (fputil::quick_get_round()) {
-    case FE_DOWNWARD:
-      return OutFPBits::zero(Sign::NEG).get_val();
-    default:
+    if (__builtin_is_constant_evaluated()) {
       return OutFPBits::zero(Sign::POS).get_val();
----------------
udaykiriti wrote:

LIBC_INLINE int quick_get_round() {
static volatile float x = 0x1.0p-24f;
float y = x;
float z = (0x1.000002p0f + y) + (-1.0f - y);

if (z == 0.0f)
return FE_DOWNWARD;
if (z == 0x1.0p-23f)
return FE_TOWARDZERO;
return (2.0f + y == 2.0f) ? FE_TONEAREST : FE_UPWARD;
}

it is coming from this functions and it is using volatile keyword and it gives me an error.

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


More information about the libc-commits mailing list