Re: [PATCH] stdlib: Make strtod/strtof set ERANGE consistently for underflow.
Jeff Johnston <[email protected]>
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <CAOox84sbk_7DHvH=Sct6-d4OAE42JP7Lu9CBEVY2R6_QmrWFNQ@mail.gmail.com> |
Hi Keith, Thanks for the patch. I have pushed it to master. -- Jeff J. On Tue, Jun 22, 2021 at 1:49 PM Keith Packard <[email protected]> wrote: > > (I suspect this patch is incomplete, but it covers all of the test cases > I've got. Help identifying additional places where this bug might exist > would be greatly appreciated) > > The C standard says that errno may acquire the value ERANGE if the > result from strtod underflows. According to IEEE 754, underflow occurs > whenever the value cannot be represented in normalized form. > > Newlib is inconsistent in this, setting errno to ERANGE only if the > value underflows to zero, but not for denorm values, and never for hex > format floats. > > This patch attempts to consistently set errno to ERANGE for all > 'underflow' conditions, which is to say all values which are not > exactly zero and which cannot be represented in normalized form. > > This matches glibc behavior, as well as the Linux, Mac OS X, OpenBSD, > FreeBSD and SunOS strtod man pages. > > > -- > -keith >