summaryrefslogtreecommitdiff
path: root/lib/libc/stdio
diff options
context:
space:
mode:
authorkleink <kleink@NetBSD.org>2001-12-02 20:12:03 +0000
committerkleink <kleink@NetBSD.org>2001-12-02 20:12:03 +0000
commitdcf4ce2588d281b763542cefebafc07b76743014 (patch)
treebedc36cb83c98e819e2e8c3763bc5f70c390a8e0 /lib/libc/stdio
parentfbd78c8e3c19fb909fcb588ffc8e8d52e42bded6 (diff)
C99:
* Recognize %F. * Convert {Infinity,NaN} to {"inf","nan"} for %[efg], and to {"INF","NAN"} for %[EFG].
Diffstat (limited to 'lib/libc/stdio')
-rw-r--r--lib/libc/stdio/printf.367
-rw-r--r--lib/libc/stdio/vfprintf.c19
2 files changed, 63 insertions, 23 deletions
diff --git a/lib/libc/stdio/printf.3 b/lib/libc/stdio/printf.3
index d5c945062cc..1c33586a316 100644
--- a/lib/libc/stdio/printf.3
+++ b/lib/libc/stdio/printf.3
@@ -1,4 +1,4 @@
-.\" $NetBSD: printf.3,v 1.21 2001/10/17 13:27:15 kleink Exp $
+.\" $NetBSD: printf.3,v 1.22 2001/12/02 20:12:03 kleink Exp $
.\"
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -37,7 +37,7 @@
.\"
.\" @(#)printf.3 8.1 (Berkeley) 6/4/93
.\"
-.Dd April 30, 2001
+.Dd December 2, 2001
.Dt PRINTF 3
.Os
.Sh NAME
@@ -216,6 +216,7 @@ For
.Cm e ,
.Cm E ,
.Cm f ,
+.Cm F ,
.Cm g ,
and
.Cm G ,
@@ -267,6 +268,7 @@ produced by a signed conversion
.Cm e ,
.Cm E ,
.Cm f ,
+.Cm F ,
.Cm g ,
.Cm G ,
or
@@ -302,8 +304,9 @@ and
conversions, the number of digits to appear after the decimal-point for
.Cm e ,
.Cm E ,
+.Cm f ,
and
-.Cm f
+.Cm F
conversions, the maximum number of significant digits for
.Cm g
and
@@ -443,6 +446,7 @@ specifying that a following
.Cm e ,
.Cm E ,
.Cm f ,
+.Cm F ,
.Cm g ,
or
.Cm G
@@ -505,6 +509,32 @@ or
.Cm lu
respectively.
These conversion characters are deprecated, and will eventually disappear.
+.It Cm fF
+The
+.Em double
+argument is rounded and converted to decimal notation in the style
+.Sm off
+.Pf [-]ddd Cm \&. No ddd ,
+.Sm on
+where the number of digits after the decimal-point character
+is equal to the precision specification.
+If the precision is missing, it is taken as 6; if the precision is
+explicitly zero, no decimal-point character appears.
+If a decimal point appears, at least one digit appears before it.
+.Pp
+If the double argument repesents an infinity it is converted
+in the style
+.Pf [-] Cm inf .
+If the double argument represents a NaN it is converted
+in the style
+.Pf [-] Cm nan .
+An
+.Cm F
+conversion produces
+.Pf [-] Cm INF
+and
+.Pf [-] Cm NAN ,
+respectively.
.It Cm eE
The
.Em double
@@ -527,26 +557,23 @@ conversion uses the letter
to introduce the exponent.
The exponent always contains at least two digits; if the value is zero,
the exponent is 00.
-.It Cm f
-The
-.Em double
-argument is rounded and converted to decimal notation in the style
-.Sm off
-.Pf [-]ddd Cm \&. No ddd ,
-.Sm on
-where the number of digits after the decimal-point character
-is equal to the precision specification.
-If the precision is missing, it is taken as 6; if the precision is
-explicitly zero, no decimal-point character appears.
-If a decimal point appears, at least one digit appears before it.
-.It Cm g
+.Pp
+Double arguments representing infinities or NaNs are converted in the
+same styles as in the
+.Cm f
+and
+.Cm F
+conversions.
+.It Cm gG
The
.Em double
argument is converted in style
.Cm f
or
.Cm e
-(or
+(or in style
+.Cm F
+or
.Cm E
for
.Cm G
@@ -560,6 +587,12 @@ is used if the exponent from its conversion is less than -4 or greater than
or equal to the precision.
Trailing zeros are removed from the fractional part of the result; a
decimal point appears only if it is followed by at least one digit.
+.Pp
+Double arguments representing infinities or NaNs are converted in the
+same styles as in the
+.Cm f
+and
+.Cm F
.It Cm c
The
.Em int
diff --git a/lib/libc/stdio/vfprintf.c b/lib/libc/stdio/vfprintf.c
index f042f383829..e0280dbb782 100644
--- a/lib/libc/stdio/vfprintf.c
+++ b/lib/libc/stdio/vfprintf.c
@@ -1,4 +1,4 @@
-/* $NetBSD: vfprintf.c,v 1.40 2001/11/28 11:58:22 kleink Exp $ */
+/* $NetBSD: vfprintf.c,v 1.41 2001/12/02 20:12:03 kleink Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
@@ -41,7 +41,7 @@
#if 0
static char *sccsid = "@(#)vfprintf.c 5.50 (Berkeley) 12/16/92";
#else
-__RCSID("$NetBSD: vfprintf.c,v 1.40 2001/11/28 11:58:22 kleink Exp $");
+__RCSID("$NetBSD: vfprintf.c,v 1.41 2001/12/02 20:12:03 kleink Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -469,6 +469,7 @@ reswitch: switch (ch) {
case 'e':
case 'E':
case 'f':
+ case 'F':
case 'g':
case 'G':
if (prec == -1) {
@@ -487,12 +488,18 @@ reswitch: switch (ch) {
if (isinf(_double)) {
if (_double < 0)
sign = '-';
- cp = "Inf";
+ if (ch == 'E' || ch == 'F' || ch == 'G')
+ cp = "INF";
+ else
+ cp = "inf";
size = 3;
break;
}
if (isnan(_double)) {
- cp = "NaN";
+ if (ch == 'E' || ch == 'F' || ch == 'G')
+ cp = "NAN";
+ else
+ cp = "nan";
size = 3;
break;
}
@@ -506,13 +513,13 @@ reswitch: switch (ch) {
else
ch = 'g';
}
- if (ch <= 'e') { /* 'e' or 'E' fmt */
+ if (ch == 'e' || ch == 'E') {
--expt;
expsize = exponent(expstr, expt, ch);
size = expsize + ndig;
if (ndig > 1 || flags & ALT)
++size;
- } else if (ch == 'f') { /* f fmt */
+ } else if (ch == 'f' || ch == 'F') {
if (expt > 0) {
size = expt;
if (prec || flags & ALT)