-.\" $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.
.\"
.\" @(#)printf.3 8.1 (Berkeley) 6/4/93
.\"
-.Dd $Mdocdate: May 31 2007 $
+.Dd $Mdocdate: August 26 2008 $
.Dt PRINTF 3
.Os
.Sh NAME
.Cm e ,
.Cm E ,
.Cm f ,
+.Cm F ,
.Cm g ,
and
.Cm G
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
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
-/* $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.
case 'e':
case 'E':
case 'f':
+ case 'F':
case 'g':
case 'G':
if (prec == -1) {
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;
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)
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);
case 'e':
case 'E':
case 'f':
+ case 'F':
case 'g':
case 'G':
if (flags & LONGDBL)
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'
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;