[PATCH] math: Fix errno setting for narrowing sqrt functions on underflow [BZ #33393]

Wilco Dijkstra Wilco.Dijkstra@arm.com
Mon Oct 20 01:12:52 GMT 2025


Hi Osama,

> Regarding the policy question: I understand glibc currently only sets errno
> for underflow-to-zero. However, the bug report (BZ #33393) shows a case where:
> - Input causes underflow during narrowing
> - Result is subnormal (2.938736e-39)
> - FE_UNDERFLOW is raised
> - math_errhandling indicates errno should be set
> - But errno remains 0
> 
> Should the behavior be:
> a) errno only for exact zero (current behavior)
> b) errno for any underflow (zero or subnormal)
> 
> If (a) is correct, should we close this bug as "won't fix"? Or is there a
> standards-based reason to prefer (b)?

GLIBC implements (a) for some math functions. For many others, it does
(c) don't set errno. There are cases where you can get (b) due to rounding
away from zero (but we tend not to care for such corner cases).

I don't see a point in implementing (b) for just this function - that would
add even more inconsistencies to GLIBC. Note that math_errhandling
makes setting errno on underflow implementation defined, so it may actually
be better to implement (c) and remove MATH_ERRNO from math_errhandling
(since we're lying about setting errno for many math functions).

So yes, I'd suggest to close it as "not-a-bug".

Cheers,
Wilco


More information about the Libc-alpha mailing list