[PATCH] stdlib: Make strtod/strtof set ERANGE consistently for underflow.

Keith Packard keithp@keithp.com
Tue Jun 22 21:25:47 GMT 2021


Joseph Myers <joseph@codesourcery.com> writes:

>> This matches glibc behavior, as well as the Linux, Mac OS X, OpenBSD,
>> FreeBSD and SunOS strtod man pages.

(I should have said 'matches glibc in all of my tests, which are not
exhaustive' :-)

> What glibc does is set it when the IEEE underflow exception flag is 
> raised.  That is, when the result is tiny and inexact, where "tiny" 
> follows each architecture's choice of before-rounding or after-rounding 
> tininess detection (neither of which means "the rounded result is 
> subnormal"; for both definitions of tiny results, there are values that 
> round to the least-magnitude normal value of their sign but are still 
> considered tiny, because after-rounding actually means "the result would 
> have a subnormal exponent if rounded to the same precision as for normal 
> values but with a wider exponent range").

Thanks for this clarification; I didn't realize that underflow had this
additional subtly. It sounds like this means that there are additional
cases where errno should be set to ERANGE in the code. I'm afraid I
don't understand the workings of this function well enough to know how
to detect this particular case. Could we somehow detect this using
exceptions? Or are there places in the code which could add some direct
checks?

-- 
-keith
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/newlib/attachments/20210622/0b14b17c/attachment.sig>


More information about the Newlib mailing list