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

Jeff Johnston jjohnstn@redhat.com
Mon Jun 28 20:38:39 GMT 2021


Hi Joseph,

While I realize that glibc does things differently and there are cases
still not handled, do you object to merging Keith's patch as-is?  If not,
I'll push it.

-- Jeff J.

On Tue, Jun 22, 2021 at 5:26 PM Keith Packard <keithp@keithp.com> wrote:

> 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
>


More information about the Newlib mailing list