Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/stdlib strtod yields ERANGE for below-subnormal mag...



details:   https://anonhg.NetBSD.org/src/rev/00d816c5b928
branches:  trunk
changeset: 344225:00d816c5b928
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Thu Mar 17 03:26:15 2016 +0000

description:
strtod yields ERANGE for below-subnormal magnitudes, not underflow.

For a floating-point computation, in the language of IEEE 754,
`underflow' means the output was rounded and is too small to be
represented *normally*.

There are many nonzero floating-point numbers to which the exact
output may have been rounded -- namely subnormals.  The condition
under which strtod returns ERANGE for small magnitudes is when the
magnitude of the exact result is so small it is rounded to zero, not
even to a subnormal.

While here, use parallel language about large magnitudes instead of
the (albeit correct) word `overflow', to avoid temptation to treat
`underflow' as the opposite notion with zero instead of infinity.

diffstat:

 lib/libc/stdlib/strtod.3 |  11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

diffs (38 lines):

diff -r 1424bb25ffa4 -r 00d816c5b928 lib/libc/stdlib/strtod.3
--- a/lib/libc/stdlib/strtod.3  Thu Mar 17 03:05:55 2016 +0000
+++ b/lib/libc/stdlib/strtod.3  Thu Mar 17 03:26:15 2016 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: strtod.3,v 1.20 2007/10/24 13:42:10 reed Exp $
+.\"    $NetBSD: strtod.3,v 1.21 2016/03/17 03:26:15 riastradh Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -151,7 +151,8 @@
 is stored in the location referenced by
 .Fa endptr .
 .Pp
-If the correct value would cause overflow, plus or minus
+If the correct value is too large in magnitude to be represented, plus
+or minus
 .Dv HUGE_VAL ,
 .Dv HUGE_VALF ,
 or
@@ -160,15 +161,15 @@
 .Dv ERANGE
 is stored in
 .Va errno .
-If the correct value would cause underflow, zero is
-returned and
+If the correct value is nonzero but too small in magnitude to be
+represented as nonzero, zero is returned and
 .Dv ERANGE
 is stored in
 .Va errno .
 .Sh ERRORS
 .Bl -tag -width Er
 .It Bq Er ERANGE
-Overflow or underflow occurred.
+The value is too large or small in magnitude to be represented.
 .El
 .Sh SEE ALSO
 .Xr atof 3 ,



Home | Main Index | Thread Index | Old Index