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

Joseph Myers joseph@codesourcery.com
Tue Jun 22 20:31:12 GMT 2021

On Tue, 22 Jun 2021, Keith Packard wrote:

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

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").

Joseph S. Myers

More information about the Newlib mailing list