summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio
diff options
context:
space:
mode:
authormartynas <martynas@openbsd.org>2008-08-26 18:29:12 +0000
committermartynas <martynas@openbsd.org>2008-08-26 18:29:12 +0000
commit6bdd673a96b7dd421f7aaff38edb4fe66bca74d4 (patch)
tree6b40dc6c047e9ec16a7f655e1b52938ba4db62e6 /lib/libc/stdio
parentdon't zero-pad special values. ok millert@ (diff)
downloadwireguard-openbsd-6bdd673a96b7dd421f7aaff38edb4fe66bca74d4.tar.xz
wireguard-openbsd-6bdd673a96b7dd421f7aaff38edb4fe66bca74d4.zip
- add F
- make inf INF nan NAN comply to standards (eEfFgG) - extend man page bits ok millert@. w/ a man page tweak and ok jmc@
Diffstat (limited to 'lib/libc/stdio')
-rw-r--r--lib/libc/stdio/printf.319
-rw-r--r--lib/libc/stdio/vfprintf.c25
2 files changed, 33 insertions, 11 deletions
diff --git a/lib/libc/stdio/printf.3 b/lib/libc/stdio/printf.3
index af93da7646e..502c4c1b346 100644
--- a/lib/libc/stdio/printf.3
+++ b/lib/libc/stdio/printf.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: printf.3,v 1.54 2007/05/31 19:19:31 jmc Exp $
+.\" $OpenBSD: printf.3,v 1.55 2008/08/26 18:29:12 martynas Exp $
.\"
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -33,7 +33,7 @@
.\"
.\" @(#)printf.3 8.1 (Berkeley) 6/4/93
.\"
-.Dd $Mdocdate: May 31 2007 $
+.Dd $Mdocdate: August 26 2008 $
.Dt PRINTF 3
.Os
.Sh NAME
@@ -206,6 +206,7 @@ For
.Cm e ,
.Cm E ,
.Cm f ,
+.Cm F ,
.Cm g ,
and
.Cm G
@@ -456,7 +457,7 @@ 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
+.It Cm fF
The
.Li double
argument is rounded and converted to decimal notation in the style
@@ -468,6 +469,18 @@ 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 argument is infinity, it will be converted to [-]inf
+.Pq Cm f
+or [-]INF
+.Pq Cm F ,
+respectively.
+If the argument is not-a-number (NaN), it will be converted to
+[-]nan
+.Pq Cm f
+or [-]NAN
+.Pq Cm F ,
+respectively.
.It Cm gG
The
.Li double
diff --git a/lib/libc/stdio/vfprintf.c b/lib/libc/stdio/vfprintf.c
index 84c0eeaa08f..c8d364d7bc0 100644
--- a/lib/libc/stdio/vfprintf.c
+++ b/lib/libc/stdio/vfprintf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfprintf.c,v 1.49 2008/08/26 17:56:30 martynas Exp $ */
+/* $OpenBSD: vfprintf.c,v 1.50 2008/08/26 18:29:12 martynas Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
@@ -523,6 +523,7 @@ reswitch: switch (ch) {
case 'e':
case 'E':
case 'f':
+ case 'F':
case 'g':
case 'G':
if (prec == -1) {
@@ -541,13 +542,19 @@ 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;
flags &= ~ZEROPAD;
break;
}
if (isnan(_double)) {
- cp = "NaN";
+ if (ch == 'E' || ch == 'F' || ch == 'G')
+ cp = "NAN";
+ else
+ cp = "nan";
size = 3;
flags &= ~ZEROPAD;
break;
@@ -564,13 +571,14 @@ reswitch: switch (ch) {
else
ch = 'g';
}
- if (ch <= 'e') { /* 'e' or 'E' fmt */
+ if (ch == 'e' || ch == 'E') { /* 'e' or 'E' fmt */
--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') {
+ /* 'f' or 'F' fmt */
if (expt > 0) {
size = expt;
if (prec || flags & ALT)
@@ -783,7 +791,7 @@ number: if ((dprec = prec) >= 0)
if ((flags & FPT) == 0) {
PRINT(cp, size);
} else { /* glue together f_p fragments */
- if (ch >= 'f') { /* 'f' or 'g' */
+ if (ch >= 'f' || ch == 'F') { /* 'f', 'g' or 'F' */
if (_double == 0) {
/* kludge for __dtoa irregularity */
PRINT("0", 1);
@@ -1071,6 +1079,7 @@ reswitch: switch (ch) {
case 'e':
case 'E':
case 'f':
+ case 'F':
case 'g':
case 'G':
if (flags & LONGDBL)
@@ -1265,7 +1274,7 @@ cvt(double value, int ndigits, int flags, int *sign, int *decpt, int ch,
int mode;
char *digits, *bp, *rve;
- if (ch == 'f') {
+ if (ch == 'f' || ch == 'F') {
mode = 3; /* ndigits after the decimal point */
} else {
/* To obtain ndigits after the decimal point for the 'e'
@@ -1281,7 +1290,7 @@ cvt(double value, int ndigits, int flags, int *sign, int *decpt, int ch,
digits = __dtoa(value, mode, ndigits, decpt, sign, &rve);
if ((ch != 'g' && ch != 'G') || flags & ALT) {/* Print trailing zeros */
bp = digits + ndigits;
- if (ch == 'f') {
+ if (ch == 'f' || ch == 'F') {
if (*digits == '0' && value)
*decpt = -ndigits + 1;
bp += *decpt;