improve description of %a in printf(3)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The description of the %a/%A specifiers in the printf(3) man page
could stand some improvement.  In particular, it is not clear from
the current (6.9.1) document what base is used for the "p±d" part of
the format.  Furthermore, the description refers to a "decimal point",
even though it would be better referred to as the "radix point",
as the number in question is not a decimal representation.

It can be inferred from the nature of %a that the base should be
a power of two. and it can be further inferred from the nature of
hexadecimal floating-point literals in C (as specified by C99 and
later) that the base must exactly be the number two, but it would be
helpful for the printf(3) man page to state this explicitly.  My first
expectation when reading the man page was that the exponent would be
taken in base 16; my second thought is that it is base FLT_RADIX (which
is 2 on IEEE 754 floating-point systems, but 16 on S/390).  Only by
going back to the standard and reading carefully could I determine
that the exponent in p-notation must always be taken from a base of 2.

A patch with one suggested wording is attached. The entry for "a, A" in
   https://pubs.opengroup.org/onlinepubs/9699919799/functions/printf.html
gives an even better rewording, though I suspect there would be
copyright issues in simply copying its text.

		--Ken Pizzini
--- printf.3~	2024-11-13 01:07:23.023847047 -0800
+++ printf.3	2024-11-13 01:55:48.368341811 -0800
@@ -757,15 +757,18 @@
 the letters ABCDEF, and the exponent separator
 .B P
 is used.
-There is one hexadecimal digit before the decimal point,
+There is one hexadecimal digit before the radix point,
 and the number of digits after it is equal to the precision.
 The default precision suffices for an exact representation of the value
 if an exact representation in base 2 exists
 and otherwise is sufficiently large to distinguish values of type
 .IR double .
-The digit before the decimal point is unspecified for nonnormalized
+The digit before the radix point is unspecified for nonnormalized
 numbers, and nonzero but otherwise unspecified for normalized numbers.
-The exponent always contains at least one
+The exponent
+.IR d ,
+which is the appropriate exponent of 2 expressed as a decimal integer,
+always contains at least one
 digit; if the value is zero, the exponent is 0.
 .TP
 .B c

[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux