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

Jeff Johnston jjohnstn@redhat.com
Wed Jul 7 17:22:39 GMT 2021

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 <keithp@keithp.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.
> --
> -keith

More information about the Newlib mailing list