diff options
Diffstat (limited to 'doc/gawktexi.in')
-rw-r--r-- | doc/gawktexi.in | 96 |
1 files changed, 58 insertions, 38 deletions
diff --git a/doc/gawktexi.in b/doc/gawktexi.in index 178444a4..4cd04763 100644 --- a/doc/gawktexi.in +++ b/doc/gawktexi.in @@ -8407,6 +8407,7 @@ PROCINFO["@var{input_name}", "RETRY"] = 1 @end example When this element exists, @command{gawk} checks the value of the system +(C language) @code{errno} variable when an I/O error occurs. If @code{errno} indicates a subsequent I/O attempt may succeed, @code{getline} instead returns @minus{}2 and @@ -16370,23 +16371,6 @@ You can use @samp{pi = atan2(0, -1)} to retrieve the value of @cindex cosine Return the cosine of @var{x}, with @var{x} in radians. -@item @code{div(@var{numerator}, @var{denominator}, @var{result})} -@cindexawkfunc{div} -@cindex div -Perform integer division, similar to the standard C function of the -same name. First, truncate @code{numerator} and @code{denominator} -towards zero, creating integer values. Clear the @code{result} -array, and then set @code{result["quotient"]} to the result of -@samp{numerator / denominator}, truncated towards zero to an integer, -and set @code{result["remainder"]} to the result of @samp{numerator % -denominator}, truncated towards zero to an integer. This function is -primarily intended for use with arbitrary length integers; it avoids -creating MPFR arbitrary precision floating-point values (@pxref{Arbitrary -Precision Integers}). - -This function is a @code{gawk} extension. It is not available in -compatibility mode (@pxref{Options}). - @item @code{exp(@var{x})} @cindexawkfunc{exp} @cindex exponent @@ -16402,6 +16386,23 @@ truncated toward zero. For example, @code{int(3)} is 3, @code{int(3.9)} is 3, @code{int(-3.9)} is @minus{}3, and @code{int(-3)} is @minus{}3 as well. +@item @code{intdiv(@var{numerator}, @var{denominator}, @var{result})} +@cindexawkfunc{intdiv} +@cindex intdiv +Perform integer division, similar to the standard C function of the +same name. First, truncate @code{numerator} and @code{denominator} +towards zero, creating integer values. Clear the @code{result} +array, and then set @code{result["quotient"]} to the result of +@samp{numerator / denominator}, truncated towards zero to an integer, +and set @code{result["remainder"]} to the result of @samp{numerator % +denominator}, truncated towards zero to an integer. This function is +primarily intended for use with arbitrary length integers; it avoids +creating MPFR arbitrary precision floating-point values (@pxref{Arbitrary +Precision Integers}). + +This function is a @code{gawk} extension. It is not available in +compatibility mode (@pxref{Options}). + @item @code{log(@var{x})} @cindexawkfunc{log} @cindex logarithm @@ -16434,8 +16435,8 @@ function randint(n) @end example @noindent -The multiplication produces a random number greater than zero and less -than @code{n}. Using @code{int()}, this result is made into +The multiplication produces a random number greater than or equal to +zero and less than @code{n}. Using @code{int()}, this result is made into an integer between zero and @code{n} @minus{} 1, inclusive. The following example uses a similar function to produce random integers @@ -19626,10 +19627,23 @@ Remember that you must supply a leading @samp{@@} in front of an indirect functi Starting with @value{PVERSION} 4.1.2 of @command{gawk}, indirect function calls may also be used with built-in functions and with extension functions -(@pxref{Dynamic Extensions}). The only thing you cannot do is pass a regular -expression constant to a built-in function through an indirect function -call.@footnote{This may change in a future version; recheck the documentation that -comes with your version of @command{gawk} to see if it has.} +(@pxref{Dynamic Extensions}). There are some limitations when calling +built-in functions indirectly, as follows. + +@itemize @value{BULLET} +@item +You cannot pass a regular expression constant to a built-in function +through an indirect function call.@footnote{This may change in a future +version; recheck the documentation that comes with your version of +@command{gawk} to see if it has.} This applies to the @code{sub()}, +@code{gsub()}, @code{gensub()}, @code{match()}, @code{split()} and +@code{patsplit()} functions. + +@item +If calling @code{sub()} or @code{gsub()}, you may only pass two arguments, +since those functions are unusual in that they update their third argument. +This means that @code{$0} will be updated. +@end itemize @command{gawk} does its best to make indirect function calls efficient. For example, in the following case: @@ -30191,27 +30205,30 @@ When dividing two arbitrary precision integers with either precision floating point value (unless the denominator evenly divides into the numerator). In order to do integer division or remainder with arbitrary precision integers, use the built-in -@code{div()} function (@pxref{Numeric Functions}). +@code{intdiv()} function (@pxref{Numeric Functions}). -You can simulate the @code{div()} function in standard @command{awk} +You can simulate the @code{intdiv()} function in standard @command{awk} using this user-defined function: @example -@c file eg/lib/div.awk -# div --- do integer division +@c file eg/lib/intdiv.awk +# intdiv --- do integer division @c endfile @ignore -@c file eg/lib/div.awk +@c file eg/lib/intdiv.awk # # Arnold Robbins, arnold@@skeeve.com, Public Domain # July, 2014 +# +# Name changed from div() to intdiv() +# April, 2015 @c endfile @end ignore -@c file eg/lib/div.awk -function div(numerator, denominator, result) +@c file eg/lib/intdiv.awk +function intdiv(numerator, denominator, result) @{ split("", result) @@ -30226,7 +30243,7 @@ function div(numerator, denominator, result) @end example The following example program, contributed by Katie Wasserman, -uses @code{div()} to +uses @code{intdiv()} to compute the digits of @value{PI} to as many places as you choose to set: @@ -30251,7 +30268,7 @@ BEGIN @{ for (m = digits * 4; m > 0; --m) @{ d = m * 2 + 1 x = pi * m - div(x, d, result) + intdiv(x, d, result) pi = result["quotient"] pi = pi + two @} @@ -34376,18 +34393,21 @@ As of this writing, there are seven extensions: GD graphics library extension @item +MPFR library extension +(this provides access to a number of MPFR functions that @command{gawk}'s +native MPFR support does not) + +@item PDF extension @item PostgreSQL extension @item -MPFR library extension -(this provides access to a number of MPFR functions that @command{gawk}'s -native MPFR support does not) +Redis extension @item -Redis extension +Select extension @item XML parser extension, using the @uref{http://expat.sourceforge.net, Expat} @@ -35117,7 +35137,7 @@ functions for internationalization (@pxref{Programmer i18n}) @item -The @code{div()} function for doing integer +The @code{intdiv()} function for doing integer division and remainder (@pxref{Numeric Functions}) @end itemize @@ -35898,7 +35918,7 @@ installed when @command{gawk} is built. @xref{Igawk Program}. @item -The @code{div()} function. +The @code{intdiv()} function. @xref{Numeric Functions}. @item |