[PATCH v4 07/21] math: Remove the SVID error handling from remainder
Wilco Dijkstra
Wilco.Dijkstra@arm.com
Wed Oct 29 16:09:52 GMT 2025
Hi Adhemerval,
@@ -36,7 +38,7 @@ __ieee754_remainder (double x, double y)
{
/* |x| not finite, |y| equal 0 is handled by fmod. */
if (__glibc_unlikely (hx >= EXPONENT_MASK))
- return (x * y) / (x * y);
+ return __math_invalid (x);
Since we are unconditionally calling fmod (which has the same
error conditions and sets errno after patch 1/21), wouldn't it be
simpler to now let it handle all error conditions?
x = fabs (__ieee754_fmod (x, y + y));
Changing to __fmod would be clearer I think.
if (x + x > y)
@@ -53,8 +55,13 @@ __ieee754_remainder (double x, double y)
else
{
/* |x| not finite or |y| is NaN or 0 */
Remove "or 0" - y == 0 is not possible here.
- if ((hx >= EXPONENT_MASK || (hy - 1) >= EXPONENT_MASK))
- return (x * y) / (x * y);
+ if (__glibc_unlikely ((hx >= EXPONENT_MASK
+ || (hy - 1) >= EXPONENT_MASK)))
Should be: hy > EXPONENT_MASK since we don't need to handle
zero here.
At this point we have (hx is Inf) or (hx is NaN) or (hy is NaN).
+ {
+ if (is_inf (hy))
+ return __math_invalid (x);
+ return (x * y) / (x * y);
+ }
Ie. is_inf (hy) is always false and we never set errno if x is infinite.
This should be:
return __math_invalid (x * y);
If either is NaN this will return NaN and not set errno, otherwise if
x is infinite, it will set errno.
Cheers,
Wilco
More information about the Libc-alpha
mailing list