summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartynas Venckus <martynas@cvs.openbsd.org>2008-09-14 11:44:55 +0000
committerMartynas Venckus <martynas@cvs.openbsd.org>2008-09-14 11:44:55 +0000
commit566a2ad839af900367f18a7d98a58f0d407c4384 (patch)
tree01211e8cbb8783dfa1a56d3377d2651003cc1709
parent096b7f75a83e441cb6d10d93db82d0bc0d7a9f17 (diff)
describe %a/%A. from freebsd
tweaks/ok millert@, jmc@
-rw-r--r--lib/libc/stdio/printf.360
-rw-r--r--usr.bin/printf/printf.121
2 files changed, 75 insertions, 6 deletions
diff --git a/lib/libc/stdio/printf.3 b/lib/libc/stdio/printf.3
index 502c4c1b346..240d06027ec 100644
--- a/lib/libc/stdio/printf.3
+++ b/lib/libc/stdio/printf.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: printf.3,v 1.55 2008/08/26 18:29:12 martynas Exp $
+.\" $OpenBSD: printf.3,v 1.56 2008/09/14 11:44:54 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: August 26 2008 $
+.Dd $Mdocdate: September 14 2008 $
.Dt PRINTF 3
.Os
.Sh NAME
@@ -203,6 +203,8 @@ for
.Cm X
conversions) prepended to it.
For
+.Cm a ,
+.Cm A ,
.Cm e ,
.Cm E ,
.Cm f ,
@@ -254,6 +256,8 @@ if both are given.
A space, specifying that a blank should be left before a positive number
produced by a signed conversion
.Pf ( Cm d ,
+.Cm a ,
+.Cm A ,
.Cm e ,
.Cm E ,
.Cm f ,
@@ -292,6 +296,8 @@ This gives the minimum number of digits to appear for
and
.Cm X
conversions, the number of digits to appear after the decimal-point for
+.Cm a ,
+.Cm A ,
.Cm e ,
.Cm E ,
.Cm f ,
@@ -351,6 +357,8 @@ equivalent in size to a
.Vt size_t .
.Pp
The following length modifier is valid for the
+.Cm a ,
+.Cm A ,
.Cm e ,
.Cm E ,
.Cm f ,
@@ -502,6 +510,54 @@ 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.
+.It Cm aA
+The
+.Li double
+argument is rounded and converted to hexadecimal notation in the style
+.Sm off
+.Pf [\-]0xh Cm \&. No hhh Cm p No [\\*(Pm]d
+.Sm on
+where the number of digits after the hexadecimal-point character
+is equal to the precision specification.
+If the precision is missing, it is taken as enough to represent
+the floating-point number exactly, and no rounding occurs.
+If the precision is zero, no hexadecimal-point character appears.
+The
+.Cm p
+is a literal character
+.Ql p ,
+and the exponent consists of a positive or negative sign
+followed by a decimal number representing an exponent of 2.
+The
+.Cm A
+conversion uses the prefix
+.Dq Li 0X
+(rather than
+.Dq Li 0x ) ,
+the letters
+.Dq Li ABCDEF
+(rather than
+.Dq Li abcdef )
+to represent the hex digits, and the letter
+.Ql P
+(rather than
+.Ql p )
+to separate the mantissa and exponent.
+.Pp
+Note that there may be multiple valid ways to represent floating-point
+numbers in this hexadecimal format.
+For example,
+.Li 0x3.24p+0 , 0x6.48p-1
+and
+.Li 0xc.9p-2
+are all equivalent.
+The format chosen depends on the internal representation of the
+number, but the implementation guarantees that the length of the
+mantissa will be minimized.
+Zeroes are always represented with a mantissa of 0 (preceded by a
+.Ql -
+if appropriate) and an exponent of
+.Li +0 .
.It Cm c
The
.Li int
diff --git a/usr.bin/printf/printf.1 b/usr.bin/printf/printf.1
index 088bdca3077..9ac9e9942ad 100644
--- a/usr.bin/printf/printf.1
+++ b/usr.bin/printf/printf.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: printf.1,v 1.19 2008/09/08 20:16:13 martynas Exp $
+.\" $OpenBSD: printf.1,v 1.20 2008/09/14 11:44:54 martynas Exp $
.\"
.\" Copyright (c) 1989, 1990 The Regents of the University of California.
.\" All rights reserved.
@@ -32,7 +32,7 @@
.\"
.\" from: @(#)printf.1 5.11 (Berkeley) 7/24/91
.\"
-.Dd $Mdocdate: September 8 2008 $
+.Dd $Mdocdate: September 14 2008 $
.Dt PRINTF 1
.Os
.Sh NAME
@@ -139,6 +139,8 @@ format, a non-zero result has the string
.Pq Li 0X
prepended to it.
For
+.Cm a ,
+.Cm A ,
.Cm e ,
.Cm E ,
.Cm f ,
@@ -206,7 +208,7 @@ from a string; if the digit string is missing, the precision is treated
as zero.
.It Format:
A character which indicates the type of format to use (one of
-.Cm diouxXfFeEgGbcs ) .
+.Cm diouxXfFeEgGaAbcs ) .
.El
.Pp
A field width or precision may be
@@ -243,7 +245,7 @@ is explicitly 0, no digits and no decimal point are printed.
If the argument is infinity, it will be converted to [-]inf
.Pq Cm f
or [-]INF
-.Pq Cm F ,
+.Pq Cm F ,
respectively.
If the argument is not-a-number (NaN), it will be converted to
[-]nan
@@ -276,6 +278,17 @@ or in style
.Cm e
.Pq Cm E
whichever gives full precision in minimum space.
+.It Cm aA
+The
+.Ar argument
+is printed in style
+.Sm off
+.Pf [\-]0xh Cm \&. No hhh Cm p No [\\*(Pm]d
+.Sm on
+where there is one digit before the hexadecimal point and the number
+after is equal to the precision specification for the argument.
+When the precision is missing, enough digits are produced to convey
+the argument's exact double-precision floating-point representation.
.It Cm b
Characters from the string
.Ar argument