summaryrefslogtreecommitdiff
path: root/manual/stdio.texi
diff options
context:
space:
mode:
Diffstat (limited to 'manual/stdio.texi')
-rw-r--r--manual/stdio.texi55
1 files changed, 45 insertions, 10 deletions
diff --git a/manual/stdio.texi b/manual/stdio.texi
index e922fd17d8..04c635b054 100644
--- a/manual/stdio.texi
+++ b/manual/stdio.texi
@@ -1007,6 +1007,12 @@ whichever is more appropriate for its magnitude. @samp{%g} uses
lower-case letters and @samp{%G} uses upper-case. @xref{Floating-Point
Conversions}, for details.
+@item @samp{%a}, @samp{%A}
+Print a floating-point number in a hexadecimal fractional notation which
+the exponent to base 2 represented in decimal digits. @samp{%a} uses
+lower-case letters and @samp{%A} uses upper-case. @xref{Floating-Point
+Conversions}, for details.
+
@item @samp{%c}
Print a single character. @xref{Other Output Conversions}.
@@ -1194,6 +1200,34 @@ than -4 or greater than or equal to the precision; otherwise they use the
of the result and a decimal-point character appears only if it is
followed by a digit.
+The @samp{%a} and @samp{%A} conversions are meant for representing
+floating-point number exactly in textual form so that they can be
+exchanged as texts between different programs and/or machines. The
+numbers are represented is the form
+@w{[@code{-}]@code{0x}@var{h}@code{.}@var{hhh}@code{p}[@code{+}|@code{-}]@var{dd}}.
+At the left of the decimal-point character exactly one digit is print.
+This character is only @code{0} is the number is denormalized.
+Otherwise the value is unspecifed; it is implemention dependent how many
+bits are used. The number of hexadecimal digits on the right side of
+the decimal-point character is equal to the precision. If the precision
+is zero it is determined to be large enough to provide an exact
+representation of the number (or it is large enough to distinguish two
+adjacent values if the @code{FLT_RADIX} is not a power of 2,
+@pxref{Floating Point Parameters}) For the @samp{%a} conversion
+lower-case characters are used to represent the hexadecimal number and
+the prefix and exponent sign are printed as @code{0x} and @code{p}
+respectively. Otherwise upper-case characters are used and @code{0X}
+and @code{P} are used for the representation of prefix and exponent
+string. The exponent to the base of two is printed as a decimal number
+using at least one digit but at most as many digits as necessary to
+represent the value exactly.
+
+If the value to be printed represents infinity or a NaN, the output is
+@w{[@code{-}]@code{inf}} or @code{nan} respectively if the conversion
+specifier is @samp{%a}, @samp{%e}, @samp{%f}, or @samp{%g} and it is
+@w{[@code{-}]@code{INF}} or @code{NAN} respectively if the conversion is
+@samp{%A}, @samp{%E}, or @samp{%G}.
+
The following flags can be used to modify the behavior:
@comment We use @asis instead of @samp so we can have ` ' as an item.
@@ -1255,21 +1289,22 @@ floating-point conversions. All of the numbers were printed using
this template string:
@smallexample
-"|%12.4f|%12.4e|%12.4g|\n"
+"|%13.4a|%13.4f|%13.4e|%13.4g|\n"
@end smallexample
Here is the output:
@smallexample
-| 0.0000| 0.0000e+00| 0|
-| 1.0000| 1.0000e+00| 1|
-| -1.0000| -1.0000e+00| -1|
-| 100.0000| 1.0000e+02| 100|
-| 1000.0000| 1.0000e+03| 1000|
-| 10000.0000| 1.0000e+04| 1e+04|
-| 12345.0000| 1.2345e+04| 1.234e+04|
-| 100000.0000| 1.0000e+05| 1e+05|
-| 123456.0000| 1.2346e+05| 1.234e+05|
+| 0x0.0000p+0| 0.0000| 0.0000e+00| 0|
+| 0x1.0000p-1| 0.5000| 5.0000e-01| 0.5|
+| 0x1.0000p+0| 1.0000| 1.0000e+00| 1|
+| -0x1.0000p+0| -1.0000| -1.0000e+00| -1|
+| 0x1.9000p+6| 100.0000| 1.0000e+02| 100|
+| 0x1.f400p+9| 1000.0000| 1.0000e+03| 1000|
+| 0x1.3880p+13| 10000.0000| 1.0000e+04| 1e+04|
+| 0x1.81c8p+13| 12345.0000| 1.2345e+04| 1.234e+04|
+| 0x1.86a0p+16| 100000.0000| 1.0000e+05| 1e+05|
+| 0x1.e240p+16| 123456.0000| 1.2346e+05| 1.235e+05|
@end smallexample
Notice how the @samp{%g} conversion drops trailing zeros.