aboutsummaryrefslogtreecommitdiffstats
path: root/doc/gawk.texi
diff options
context:
space:
mode:
Diffstat (limited to 'doc/gawk.texi')
-rw-r--r--doc/gawk.texi55
1 files changed, 53 insertions, 2 deletions
diff --git a/doc/gawk.texi b/doc/gawk.texi
index 3d910ee0..b210da10 100644
--- a/doc/gawk.texi
+++ b/doc/gawk.texi
@@ -611,6 +611,9 @@ particular records in a file and perform operations upon them.
This is an advanced method of input.
* Conversion:: The conversion of strings to numbers
and vice versa.
+* Strings And Numbers:: How @command{awk} Converts Between
+ Strings And Numbers.
+* Locale influences conversions:: How the locale may affect conversions.
* All Operators:: @command{gawk}'s operators.
* Arithmetic Ops:: Arithmetic operations (@samp{+},
@samp{-}, etc.)
@@ -10663,6 +10666,19 @@ sequences
@node Conversion
@subsection Conversion of Strings and Numbers
+Number to string and string to number conversion are generally
+straightforward. There can be subtleties to be aware of;
+this @value{SECTION} discusses this important facet of @command{awk}.
+
+@menu
+* Strings And Numbers:: How @command{awk} Converts Between Strings And
+ Numbers.
+* Locale influences conversions:: How the locale may affect conversions.
+@end menu
+
+@node Strings And Numbers
+@subsubsection How @command{awk} Converts Between Strings And Numbers
+
@cindex converting, strings to numbers
@cindex strings, converting
@cindex numbers, converting
@@ -10732,6 +10748,35 @@ b = a ""
@code{b} has the value @code{"12"}, not @code{"12.00"}.
@value{DARKCORNER}
+@cindex sidebar, Pre-POSIX @command{awk} Used @code{OFMT} For String Conversion
+@ifdocbook
+@docbook
+<sidebar><title>Pre-POSIX @command{awk} Used @code{OFMT} For String Conversion</title>
+@end docbook
+
+@cindex POSIX @command{awk}, @code{OFMT} variable and
+@cindex @code{OFMT} variable
+@cindex portability, new @command{awk} vs.@: old @command{awk}
+@cindex @command{awk}, new vs.@: old, @code{OFMT} variable
+Prior to the POSIX standard, @command{awk} used the value
+of @code{OFMT} for converting numbers to strings. @code{OFMT}
+specifies the output format to use when printing numbers with @code{print}.
+@code{CONVFMT} was introduced in order to separate the semantics of
+conversion from the semantics of printing. Both @code{CONVFMT} and
+@code{OFMT} have the same default value: @code{"%.6g"}. In the vast majority
+of cases, old @command{awk} programs do not change their behavior.
+@xref{Print}, for more information on the @code{print} statement.
+
+@docbook
+</sidebar>
+@end docbook
+@end ifdocbook
+
+@ifnotdocbook
+@cartouche
+@center @b{Pre-POSIX @command{awk} Used @code{OFMT} For String Conversion}
+
+
@cindex POSIX @command{awk}, @code{OFMT} variable and
@cindex @code{OFMT} variable
@cindex portability, new @command{awk} vs.@: old @command{awk}
@@ -10744,6 +10789,11 @@ conversion from the semantics of printing. Both @code{CONVFMT} and
@code{OFMT} have the same default value: @code{"%.6g"}. In the vast majority
of cases, old @command{awk} programs do not change their behavior.
@xref{Print}, for more information on the @code{print} statement.
+@end cartouche
+@end ifnotdocbook
+
+@node Locale influences conversions
+@subsubsection Locales Can Influence Conversion
Where you are can matter when it comes to converting between numbers and
strings. The local character set and language---the @dfn{locale}---can
@@ -12632,6 +12682,7 @@ of others let you control how @command{awk} behaves.
Numbers are automatically converted to strings, and strings to numbers,
as needed by @command{awk}. Numeric values are converted as if they were
formatted with @code{sprintf()} using the format in @code{CONVFMT}.
+Locales can influence the conversions.
@item
@command{awk} provides the usual arithmetic operators (addition,
@@ -30354,7 +30405,7 @@ the following computes
5<superscript>4<superscript>3<superscript>2</superscript></superscript></superscript>, @c
@end docbook
the result of which is beyond the
-limits of ordinary @command{gawk} numbers:
+limits of ordinary hardware double-precision floating point values:
@example
$ @kbd{gawk -M 'BEGIN @{}
@@ -30462,7 +30513,7 @@ source code constants.)
Support for the special IEEE 754 floating point values ``Not A Number''
(NaN), positive Infinity (``inf'') and negative Infinity (``@minus{}inf'').
In particular, the format for these values is as specified by the ISO 1999
-C standard, which ignores case and can allow machine-dependent additional
+C standard, which ignores case and can allow implementation-dependent additional
characters after the @samp{nan} and allow either @samp{inf} or @samp{infinity}.
@end itemize