[PATCH] stdlib: Make strtod/strtof set ERANGE consistently for underflow.
Wed Jul 7 17:22:39 GMT 2021
Thanks for the patch. I have pushed it to master.
-- Jeff J.
On Tue, Jun 22, 2021 at 1:49 PM Keith Packard <email@example.com> 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.
More information about the Newlib