Skip to contentSkip to conversation

strtod.3: Fix return value for underflow

PATCH In review Jonathan Wakely 2 participants 2 messages Aug 7, 2020 – Aug 23, 2020 Man-pages: manual pages for Linux -- Sections 2, 3, 4, 5, and 7

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 strtod.3: Fix return value for underflow

In C89 strtod returns zero on underflow, but since C99 it can return non-zero. This means the strtod.3 page contradicts all recent C and POSIX standards. Both C and POSIX say "smallest normalized positive number", but for consistency with HUGE_VAL, HUGE_VALF and HUGE_VALL this patch uses the constants for those numbers.

Also slightly improve the presentation of return values for overflow.

man3/strtod.3 +14 -6
index a271498d5..56ddb5f27 100644
@@ -138,15 +138,23 @@ is stored in the location referenced by
 .IR endptr .
 .PP
 If the correct value would cause overflow, plus or minus
-.B HUGE_VAL
-.RB ( HUGE_VALF ,
-.BR HUGE_VALL )
-is returned (according to the sign of the value), and
+.BR HUGE_VAL ,
+.BR HUGE_VALF ,
+or
+.B HUGE_VALL
+is returned (according to the return type and sign of the value),
+and
 .B ERANGE
 is stored in
 .IR errno .
-If the correct value would cause underflow, zero is
-returned and
+.PP
+If the correct value would cause underflow,
+a value with magnitude no larger than
+.BR DBL_MIN ,
+.BR FLT_MIN ,
+or
+.B LDBL_MIN
+is returned and
 .B ERANGE
 is stored in
 .IR errno .
#1 lore raw

Hi again Jonathan,

Quoted 7 lines · Jonathan Wakely

In C89 strtod returns zero on underflow, but since C99 it can return non-zero. This means the strtod.3 page contradicts all recent C and POSIX standards. Both C and POSIX say "smallest normalized positive number", but for consistency with HUGE_VAL, HUGE_VALF and HUGE_VALL this patch uses the constants for those numbers.

Also slightly improve the presentation of return values for overflow.

Thanks. I've also applied this patch.

Cheers,

Michael

Quoted 35 lines
man3/strtod.3 +14 -6
index a271498d5..56ddb5f27 100644
@@ -138,15 +138,23 @@ is stored in the location referenced by
  .IR endptr .
  .PP
  If the correct value would cause overflow, plus or minus
-.B HUGE_VAL
-.RB ( HUGE_VALF ,
-.BR HUGE_VALL )
-is returned (according to the sign of the value), and
+.BR HUGE_VAL ,
+.BR HUGE_VALF ,
+or
+.B HUGE_VALL
+is returned (according to the return type and sign of the value),
+and
  .B ERANGE
  is stored in
  .IR errno .
-If the correct value would cause underflow, zero is
-returned and
+.PP
+If the correct value would cause underflow,
+a value with magnitude no larger than
+.BR DBL_MIN ,
+.BR FLT_MIN ,
+or
+.B LDBL_MIN
+is returned and
  .B ERANGE
  is stored in
  .IR errno .