[PATCH] math: Fix errno setting for narrowing sqrt functions on underflow [BZ #33393]
Osama Abdelkader
osama.abdelkader@gmail.com
Mon Oct 20 15:29:51 GMT 2025
On Mon, Oct 20, 2025 at 01:12:52AM +0000, Wilco Dijkstra wrote:
> 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
Hi Wilco,
Thanks for the feedback, that is actually my first contribution to glibc attempt,
will try to find something simpler.
Best regards,
Osama
More information about the Libc-alpha
mailing list