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

Keith Packard keithp@keithp.com
Tue Jun 22 17:48:49 GMT 2021


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-stdlib-Make-strtod-strtof-set-ERANGE-consistently-fo.patch
Type: text/x-diff
Size: 3029 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/newlib/attachments/20210622/bf4d2216/attachment.bin>
-------------- next part --------------

-- 
-keith
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/newlib/attachments/20210622/bf4d2216/attachment.sig>


More information about the Newlib mailing list