From 409668f6e88b63607e2cea29b3ce2a1c25f04bf1 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Fri, 14 Mar 2025 15:58:11 +0000 Subject: Implement C23 powr C23 adds various function families originally defined in TS 18661-4. Add the powr functions, which are like pow, but with simpler handling of special cases (based on exp(y*log(x)), so negative x and 0^0 are domain errors, powers of -0 are always +0 or +Inf never -0 or -Inf, and 1^+-Inf and Inf^0 are also domain errors, while NaN^0 and 1^NaN are NaN). The test inputs are taken from those for pow, with appropriate adjustments (including removing all tests that would be domain errors from those in auto-libm-test-in and adding some more such tests in libm-test-powr.inc). The underlying implementation uses __ieee754_pow functions after dealing with all special cases that need to be handled differently. It might be a little faster (avoiding a wrapper and redundant checks for special cases) to have an underlying implementation built separately for both pow and powr with compile-time conditionals for special-case handling, but I expect the benefit of that would be limited given that both functions will end up needing to use the same logic for computing pow outside of special cases. My understanding is that powr(negative, qNaN) should raise "invalid": that the rule on "invalid" for an argument outside the domain of the function takes precedence over a quiet NaN argument producing a quiet NaN result with no exceptions raised (for rootn it's explicit that the 0th root of qNaN raises "invalid"). I've raised this on the WG14 reflector to confirm the intent. Tested for x86_64 and x86, and with build-many-glibcs.py. --- math/bits/mathcalls.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'math/bits') diff --git a/math/bits/mathcalls.h b/math/bits/mathcalls.h index eb40fb2b1e..c0569009b7 100644 --- a/math/bits/mathcalls.h +++ b/math/bits/mathcalls.h @@ -186,6 +186,9 @@ __MATHCALL_VEC (cbrt,, (_Mdouble_ __x)); #endif #if __GLIBC_USE (IEC_60559_FUNCS_EXT_C23) +/* Return X to the Y power. */ +__MATHCALL (powr,, (_Mdouble_ __x, _Mdouble_ __y)); + /* Return the reciprocal of the square root of X. */ __MATHCALL (rsqrt,, (_Mdouble_ __x)); #endif -- cgit v1.2.3