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

Jeff Johnston <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <CAOox84tLhL86b=RF7OkoNs9WmoBy-AfB1mOS9dC-1WpiY94b3g@mail.gmail.com>
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 <[email protected]> wrote:

> Joseph Myers <[email protected]> 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
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.