diff options
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | awkgram.c | 6 | ||||
-rw-r--r-- | awkgram.y | 6 | ||||
-rw-r--r-- | awklib/eg/lib/intdiv.awk | 7 | ||||
-rw-r--r-- | builtin.c | 2 | ||||
-rw-r--r-- | configh.in | 3 | ||||
-rwxr-xr-x | configure | 18 | ||||
-rw-r--r-- | configure.ac | 11 | ||||
-rw-r--r-- | doc/ChangeLog | 7 | ||||
-rw-r--r-- | doc/awkcard.in | 6 | ||||
-rw-r--r-- | doc/gawk.1 | 2 | ||||
-rw-r--r-- | doc/gawk.info | 771 | ||||
-rw-r--r-- | doc/gawk.texi | 32 | ||||
-rw-r--r-- | doc/gawktexi.in | 32 | ||||
-rw-r--r-- | extension/ChangeLog | 4 | ||||
-rw-r--r-- | extension/intdiv.c | 2 | ||||
-rw-r--r-- | mpfr.c | 2 | ||||
-rw-r--r-- | test/ChangeLog | 5 | ||||
-rw-r--r-- | test/dumpvars.ok | 2 | ||||
-rw-r--r-- | test/id.ok | 1 | ||||
-rw-r--r-- | test/mpfrsqrt.awk | 2 | ||||
-rw-r--r-- | test/symtab6.ok | 2 | ||||
-rw-r--r-- | test/symtab8.ok | 2 |
23 files changed, 480 insertions, 456 deletions
@@ -1,5 +1,16 @@ 2017-04-16 Arnold D. Robbins <arnold@skeeve.com> + Rename intdiv it intdiv0 and require enabling at configure time. + + * awkgram.y (tokentab): Bracket intdiv0 in #ifdef SUPPLY_INTDIV. + (snode): Similar. + * builtin.c (do_intdiv): Bracket in #ifdef SUPPLY_INTDIV. + * mpfr.c (do_mpfr_intdiv): Bracket in #ifdef SUPPLY_INTDIV. + * configure.ac: Add --enable-builtin-intdiv0 option. If enabled, + also revise doc/gawktexi.in. + +2017-04-16 Arnold D. Robbins <arnold@skeeve.com> + * builtin.c (do_intdiv): Use DEREF on the arguments. Thanks to Andrew Schorr for finding the problem. * mpfr.c (do_mpfr_intdiv): Return -1 if numerator or denominator @@ -4547,7 +4547,9 @@ static const struct token tokentab[] = { {"include", Op_symbol, LEX_INCLUDE, GAWKX, 0, 0}, {"index", Op_builtin, LEX_BUILTIN, A(2), do_index, 0}, {"int", Op_builtin, LEX_BUILTIN, A(1), do_int, MPF(int)}, -{"intdiv", Op_builtin, LEX_BUILTIN, GAWKX|A(3), do_intdiv, MPF(intdiv)}, +#ifdef SUPPLY_INTDIV +{"intdiv0", Op_builtin, LEX_BUILTIN, GAWKX|A(3), do_intdiv, MPF(intdiv)}, +#endif {"isarray", Op_builtin, LEX_BUILTIN, GAWKX|A(1), do_isarray, 0}, {"length", Op_builtin, LEX_LENGTH, A(0)|A(1), do_length, 0}, {"load", Op_symbol, LEX_LOAD, GAWKX, 0, 0}, @@ -6846,6 +6848,7 @@ snode(INSTRUCTION *subn, INSTRUCTION *r) arg = subn->nexti; if (arg->nexti == arg->lasti && arg->nexti->opcode == Op_push) arg->nexti->opcode = Op_push_arg_untyped; /* argument may be untyped */ +#ifdef SUPPLY_INTDIV } else if (r->builtin == do_intdiv #ifdef HAVE_MPFR || r->builtin == MPF(intdiv) @@ -6855,6 +6858,7 @@ snode(INSTRUCTION *subn, INSTRUCTION *r) ip = arg->lasti; if (ip->opcode == Op_push) ip->opcode = Op_push_array; +#endif /* SUPPLY_INTDIV */ } else if (r->builtin == do_match) { static bool warned = false; @@ -2127,7 +2127,9 @@ static const struct token tokentab[] = { {"include", Op_symbol, LEX_INCLUDE, GAWKX, 0, 0}, {"index", Op_builtin, LEX_BUILTIN, A(2), do_index, 0}, {"int", Op_builtin, LEX_BUILTIN, A(1), do_int, MPF(int)}, -{"intdiv", Op_builtin, LEX_BUILTIN, GAWKX|A(3), do_intdiv, MPF(intdiv)}, +#ifdef SUPPLY_INTDIV +{"intdiv0", Op_builtin, LEX_BUILTIN, GAWKX|A(3), do_intdiv, MPF(intdiv)}, +#endif {"isarray", Op_builtin, LEX_BUILTIN, GAWKX|A(1), do_isarray, 0}, {"length", Op_builtin, LEX_LENGTH, A(0)|A(1), do_length, 0}, {"load", Op_symbol, LEX_LOAD, GAWKX, 0, 0}, @@ -4426,6 +4428,7 @@ snode(INSTRUCTION *subn, INSTRUCTION *r) arg = subn->nexti; if (arg->nexti == arg->lasti && arg->nexti->opcode == Op_push) arg->nexti->opcode = Op_push_arg_untyped; /* argument may be untyped */ +#ifdef SUPPLY_INTDIV } else if (r->builtin == do_intdiv #ifdef HAVE_MPFR || r->builtin == MPF(intdiv) @@ -4435,6 +4438,7 @@ snode(INSTRUCTION *subn, INSTRUCTION *r) ip = arg->lasti; if (ip->opcode == Op_push) ip->opcode = Op_push_array; +#endif /* SUPPLY_INTDIV */ } else if (r->builtin == do_match) { static bool warned = false; diff --git a/awklib/eg/lib/intdiv.awk b/awklib/eg/lib/intdiv.awk index dbc553b0..9de5978e 100644 --- a/awklib/eg/lib/intdiv.awk +++ b/awklib/eg/lib/intdiv.awk @@ -1,4 +1,4 @@ -# intdiv --- do integer division +# intdiv0 --- do integer division # # Arnold Robbins, arnold@skeeve.com, Public Domain @@ -6,8 +6,11 @@ # # Name changed from div() to intdiv() # April, 2015 +# +# Changed to intdiv0() +# April, 2016 -function intdiv(numerator, denominator, result) +function intdiv0(numerator, denominator, result) { split("", result) @@ -3971,6 +3971,7 @@ do_bindtextdomain(int nargs) return make_string(the_result, strlen(the_result)); } +#ifdef SUPPLY_INTDIV /* do_intdiv --- do integer division, return quotient and remainder in dest array */ /* @@ -4039,6 +4040,7 @@ do_intdiv(int nargs) return make_number((AWKNUM) 0.0); } +#endif /* SUPPLY_INTDIV */ /* do_typeof --- return a string with the type of the arg */ @@ -377,6 +377,9 @@ /* Define to 1 if you have the ANSI C header files. */ #undef STDC_HEADERS +/* enable built-in intdiv0 function */ +#undef SUPPLY_INTDIV + /* some systems define this type here */ #undef TIME_T_IN_SYS_TYPES_H @@ -766,6 +766,7 @@ enable_silent_rules with_whiny_user_strftime enable_lint enable_severe_portability_problems +enable_builtin_intdiv0 enable_dependency_tracking enable_largefile enable_nls @@ -1412,6 +1413,8 @@ Optional Features: --disable-lint Disable gawk lint checking --enable-severe-portability-problems Enable really nasty portability problems + --enable-builtin-intdiv0 + Enable built-in intdiv0 function --enable-dependency-tracking do not reject slow dependency extractors --disable-dependency-tracking @@ -3243,6 +3246,21 @@ $as_echo "#define I_DONT_KNOW_WHAT_IM_DOING 1" >>confdefs.h fi +# Check whether --enable-builtin-intdiv0 was given. +if test "${enable_builtin_intdiv0+set}" = set; then : + enableval=$enable_builtin_intdiv0; if test "$enableval" = yes + then + +$as_echo "#define SUPPLY_INTDIV 1" >>confdefs.h + + sed '/^@set PATCHLEVEL/a\ +@set INTDIV' < "$srcdir"/doc/gawktexi.in > foo + cp foo "$srcdir"/doc/gawktexi.in + rm foo + fi + +fi + # Make sure we can run config.sub. $SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 || diff --git a/configure.ac b/configure.ac index 338973b2..e2226ad9 100644 --- a/configure.ac +++ b/configure.ac @@ -67,6 +67,17 @@ AC_ARG_ENABLE([severe-portability-problems], AC_DEFINE(I_DONT_KNOW_WHAT_IM_DOING, 1, [enable severe portability problems]) fi ) +AC_ARG_ENABLE([builtin-intdiv0], + [AS_HELP_STRING([--enable-builtin-intdiv0],[Enable built-in intdiv0 function])], + if test "$enableval" = yes + then + AC_DEFINE(SUPPLY_INTDIV, 1, [enable built-in intdiv0 function]) + sed '/^@set PATCHLEVEL/a\ +@set INTDIV' < "$srcdir"/doc/gawktexi.in > foo + cp foo "$srcdir"/doc/gawktexi.in + rm foo + fi +) AC_CANONICAL_HOST AC_USE_SYSTEM_EXTENSIONS diff --git a/doc/ChangeLog b/doc/ChangeLog index 39fc8021..45876892 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,5 +1,12 @@ 2017-04-16 Arnold D. Robbins <arnold@skeeve.com> + * awkcard.in: Comment out description of intdiv(). + * gawk.1: Ditto. + * gawktexi.in: References to intdiv changed to intdiv0 and + bracketed inside @ifset INTDIV. Not set by default. + +2017-04-16 Arnold D. Robbins <arnold@skeeve.com> + * gawktexi.in: Improve documentation of the intdiv() function. 2017-04-12 Arnold D. Robbins <arnold@skeeve.com> diff --git a/doc/awkcard.in b/doc/awkcard.in index 86aeee2e..165fca43 100644 --- a/doc/awkcard.in +++ b/doc/awkcard.in @@ -1617,9 +1617,9 @@ l lw(1.9i). \*(FCcos(\*(FIexpr\*(FC)\*(FR The cosine of \*(FIexpr\fP, which is in radians. \*(FCexp(\*(FIexpr\*(FC)\*(FR The exponential function (\*(FIe \*(FC^ \*(FIx\*(FR). \*(FCint(\*(FIexpr\*(FC)\*(FR Truncate to integer. -\*(CB\*(FCintdiv(\*(FIn\*(FR\*(FC,\*(FI d\*(FR\*(FC,\*(FI r\*(FR\*(FC)\*(FR T{ -Return result of integer division in \*(FIr\*(FR.\*(CD -T} +.\" \*(CB\*(FCintdiv(\*(FIn\*(FR\*(FC,\*(FI d\*(FR\*(FC,\*(FI r\*(FR\*(FC)\*(FR T{ +.\" Return result of integer division in \*(FIr\*(FR.\*(CD +.\" T} \*(FClog(\*(FIexpr\*(FC)\*(FR The natural logarithm function (base \*(FIe\^\*(FR). \*(FCrand()\fP A random number \*(FIN\fP such that 0 \(<= \*(FIN\fP < 1. \*(FCsin(\*(FIexpr\*(FC)\*(FR The sine of \*(FIexpr\fP, which is in radians. @@ -2711,6 +2711,7 @@ The exponential function. .TP .BI int( expr ) Truncate to integer. +.ig .TP .BI intdiv( num ", " denom ", " result ) Truncate @@ -2728,6 +2729,7 @@ This is a .I gawk extension, primarily of value when working with arbitrarily large integers. +.. .TP .BI log( expr ) The natural logarithm function. diff --git a/doc/gawk.info b/doc/gawk.info index 238df1dc..25e9409d 100644 --- a/doc/gawk.info +++ b/doc/gawk.info @@ -12267,24 +12267,6 @@ brackets ([ ]): truncated toward zero. For example, 'int(3)' is 3, 'int(3.9)' is 3, 'int(-3.9)' is -3, and 'int(-3)' is -3 as well. -'intdiv(NUMERATOR, DENOMINATOR, RESULT)' - Perform integer division, similar to the standard C 'div()' - function. First, truncate 'numerator' and 'denominator' towards - zero, creating integer values. Clear the 'result' array, and then - set 'result["quotient"]' to the result of 'numerator / - denominator', truncated towards zero to an integer, and set - 'result["remainder"]' to the result of 'numerator % denominator', - truncated towards zero to an integer. Attempting division by zero - causes a fatal error. The function returns zero upon success, and - -1 upon error. - - This function is primarily intended for use with arbitrary length - integers; it avoids creating MPFR arbitrary precision - floating-point values (*note Arbitrary Precision Integers::). - - This function is a 'gawk' extension. It is not available in - compatibility mode (*note Options::). - 'log(X)' Return the natural logarithm of X, if X is positive; otherwise, return 'NaN' ("not a number") on IEEE 754 systems. Additionally, @@ -23081,59 +23063,7 @@ the following: When dividing two arbitrary precision integers with either '/' or '%', the result is typically an arbitrary 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 'intdiv()' function (*note Numeric Functions::). - - You can simulate the 'intdiv()' function in standard 'awk' using this -user-defined function: - - # intdiv --- do integer division - - function intdiv(numerator, denominator, result) - { - split("", result) - - numerator = int(numerator) - denominator = int(denominator) - result["quotient"] = int(numerator / denominator) - result["remainder"] = int(numerator % denominator) - - return 0.0 - } - - The following example program, contributed by Katie Wasserman, uses -'intdiv()' to compute the digits of pi to as many places as you choose -to set: - - # pi.awk --- compute the digits of pi - - BEGIN { - digits = 100000 - two = 2 * 10 ^ digits - pi = two - for (m = digits * 4; m > 0; --m) { - d = m * 2 + 1 - x = pi * m - intdiv(x, d, result) - pi = result["quotient"] - pi = pi + two - } - print pi - } - - When asked about the algorithm used, Katie replied: - - It's not that well known but it's not that obscure either. It's - Euler's modification to Newton's method for calculating pi. Take a - look at lines (23) - (25) here: - <http://mathworld.wolfram.com/PiFormulas.html>. - - The algorithm I wrote simply expands the multiply by 2 and works - from the innermost expression outwards. I used this to program HP - calculators because it's quite easy to modify for tiny memory - devices with smallish word sizes. See - <http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/articles.cgi?read=899>. +(unless the denominator evenly divides into the numerator). ---------- Footnotes ---------- @@ -27408,9 +27338,6 @@ current version of 'gawk'. - The 'bindtextdomain()', 'dcgettext()', and 'dcngettext()' functions for internationalization (*note Programmer i18n::) - - The 'intdiv()' function for doing integer division and - remainder (*note Numeric Functions::) - * Changes and/or additions in the command-line options: - The 'AWKPATH' environment variable for specifying a path @@ -27873,8 +27800,6 @@ POSIX 'awk', in the order they were added to 'gawk'. * The 'igawk' program and its manual page are no longer installed when 'gawk' is built. *Note Igawk Program::. - * The 'intdiv()' function. *Note Numeric Functions::. - * The maximum number of hexadecimal digits in '\x' escapes is now two. *Note Escape Sequences::. @@ -34274,8 +34199,6 @@ Index * instruction tracing, in debugger: Debugger Info. (line 90) * int: Numeric Functions. (line 24) * INT signal (MS-Windows): Profiling. (line 212) -* intdiv: Numeric Functions. (line 29) -* intdiv <1>: Numeric Functions. (line 29) * integer array indices: Numeric Array Subscripts. (line 31) * integers, arbitrary precision: Arbitrary Precision Integers. @@ -34425,9 +34348,9 @@ Index * localization: I18N and L10N. (line 6) * localization, See internationalization, localization: I18N and L10N. (line 6) -* log: Numeric Functions. (line 47) +* log: Numeric Functions. (line 29) * log files, timestamps in: Time Functions. (line 6) -* logarithm: Numeric Functions. (line 47) +* logarithm: Numeric Functions. (line 29) * logical false/true: Truth Values. (line 6) * logical operators, See Boolean expressions: Boolean Ops. (line 6) * login information: Passwd Functions. (line 16) @@ -34890,12 +34813,12 @@ Index * Rakitzis, Byron: History Sorting. (line 25) * Ramey, Chet: Acknowledgments. (line 60) * Ramey, Chet <1>: General Data Types. (line 6) -* rand: Numeric Functions. (line 52) +* rand: Numeric Functions. (line 34) * random numbers, Cliff: Cliff Random Function. (line 6) * random numbers, rand()/srand() functions: Numeric Functions. - (line 52) -* random numbers, seed of: Numeric Functions. (line 82) + (line 34) +* random numbers, seed of: Numeric Functions. (line 64) * range expressions (regexps): Bracket Expressions. (line 6) * range patterns: Ranges. (line 6) * range patterns, line continuation and: Ranges. (line 64) @@ -35073,7 +34996,7 @@ Index * sed utility: Full Line Fields. (line 22) * sed utility <1>: Simple Sed. (line 6) * sed utility <2>: Glossary. (line 16) -* seeding random number generator: Numeric Functions. (line 82) +* seeding random number generator: Numeric Functions. (line 64) * semicolon (;), AWKPATH variable and: PC Using. (line 9) * semicolon (;), separating statements in actions: Statements/Lines. (line 90) @@ -35177,8 +35100,8 @@ Index * SIGUSR1 signal, for dynamic profiling: Profiling. (line 186) * silent debugger command: Debugger Execution Control. (line 10) -* sin: Numeric Functions. (line 93) -* sine: Numeric Functions. (line 93) +* sin: Numeric Functions. (line 75) +* sine: Numeric Functions. (line 75) * single quote ('): One-shot. (line 15) * single quote (') in gawk command lines: Long. (line 35) * single quote ('), in shell commands: Quoting. (line 48) @@ -35228,10 +35151,10 @@ Index * sprintf() function, OFMT variable and: User-modified. (line 116) * sprintf() function, print/printf statements and: Round Function. (line 6) -* sqrt: Numeric Functions. (line 96) +* sqrt: Numeric Functions. (line 78) * square brackets ([]), regexp operator: Regexp Operators. (line 56) -* square root: Numeric Functions. (line 96) -* srand: Numeric Functions. (line 100) +* square root: Numeric Functions. (line 78) +* srand: Numeric Functions. (line 82) * stack frame: Debugging Terms. (line 10) * Stallman, Richard: Manual History. (line 6) * Stallman, Richard <1>: Acknowledgments. (line 18) @@ -35791,340 +35714,340 @@ Node: Functions516532 Node: Built-in517570 Node: Calling Built-in518651 Node: Numeric Functions520647 -Ref: Numeric Functions-Footnote-1525592 -Ref: Numeric Functions-Footnote-2525949 -Ref: Numeric Functions-Footnote-3525997 -Node: String Functions526269 -Ref: String Functions-Footnote-1549927 -Ref: String Functions-Footnote-2550055 -Ref: String Functions-Footnote-3550303 -Node: Gory Details550390 -Ref: table-sub-escapes552181 -Ref: table-sub-proposed553700 -Ref: table-posix-sub555063 -Ref: table-gensub-escapes556604 -Ref: Gory Details-Footnote-1557427 -Node: I/O Functions557581 -Ref: table-system-return-values564163 -Ref: I/O Functions-Footnote-1566143 -Ref: I/O Functions-Footnote-2566291 -Node: Time Functions566411 -Ref: Time Functions-Footnote-1577078 -Ref: Time Functions-Footnote-2577146 -Ref: Time Functions-Footnote-3577304 -Ref: Time Functions-Footnote-4577415 -Ref: Time Functions-Footnote-5577527 -Ref: Time Functions-Footnote-6577754 -Node: Bitwise Functions578020 -Ref: table-bitwise-ops578614 -Ref: Bitwise Functions-Footnote-1584647 -Ref: Bitwise Functions-Footnote-2584820 -Node: Type Functions585011 -Node: I18N Functions587686 -Node: User-defined589337 -Node: Definition Syntax590142 -Ref: Definition Syntax-Footnote-1595829 -Node: Function Example595900 -Ref: Function Example-Footnote-1598822 -Node: Function Caveats598844 -Node: Calling A Function599362 -Node: Variable Scope600320 -Node: Pass By Value/Reference603314 -Node: Return Statement606813 -Node: Dynamic Typing609792 -Node: Indirect Calls610722 -Ref: Indirect Calls-Footnote-1620973 -Node: Functions Summary621101 -Node: Library Functions623806 -Ref: Library Functions-Footnote-1627413 -Ref: Library Functions-Footnote-2627556 -Node: Library Names627727 -Ref: Library Names-Footnote-1631187 -Ref: Library Names-Footnote-2631410 -Node: General Functions631496 -Node: Strtonum Function632599 -Node: Assert Function635621 -Node: Round Function638947 -Node: Cliff Random Function640488 -Node: Ordinal Functions641504 -Ref: Ordinal Functions-Footnote-1644567 -Ref: Ordinal Functions-Footnote-2644819 -Node: Join Function645029 -Ref: Join Function-Footnote-1646799 -Node: Getlocaltime Function646999 -Node: Readfile Function650741 -Node: Shell Quoting652713 -Node: Data File Management654114 -Node: Filetrans Function654746 -Node: Rewind Function658842 -Node: File Checking660748 -Ref: File Checking-Footnote-1662082 -Node: Empty Files662283 -Node: Ignoring Assigns664262 -Node: Getopt Function665812 -Ref: Getopt Function-Footnote-1677281 -Node: Passwd Functions677481 -Ref: Passwd Functions-Footnote-1686320 -Node: Group Functions686408 -Ref: Group Functions-Footnote-1694306 -Node: Walking Arrays694513 -Node: Library Functions Summary697521 -Node: Library Exercises698927 -Node: Sample Programs699392 -Node: Running Examples700162 -Node: Clones700890 -Node: Cut Program702114 -Node: Egrep Program712043 -Ref: Egrep Program-Footnote-1719555 -Node: Id Program719665 -Node: Split Program723345 -Ref: Split Program-Footnote-1726804 -Node: Tee Program726933 -Node: Uniq Program729723 -Node: Wc Program737149 -Ref: Wc Program-Footnote-1741404 -Node: Miscellaneous Programs741498 -Node: Dupword Program742711 -Node: Alarm Program744741 -Node: Translate Program749596 -Ref: Translate Program-Footnote-1754161 -Node: Labels Program754431 -Ref: Labels Program-Footnote-1757782 -Node: Word Sorting757866 -Node: History Sorting761938 -Node: Extract Program763773 -Node: Simple Sed771302 -Node: Igawk Program774376 -Ref: Igawk Program-Footnote-1788707 -Ref: Igawk Program-Footnote-2788909 -Ref: Igawk Program-Footnote-3789031 -Node: Anagram Program789146 -Node: Signature Program792208 -Node: Programs Summary793455 -Node: Programs Exercises794669 -Ref: Programs Exercises-Footnote-1798798 -Node: Advanced Features798889 -Node: Nondecimal Data800879 -Node: Array Sorting802470 -Node: Controlling Array Traversal803170 -Ref: Controlling Array Traversal-Footnote-1811537 -Node: Array Sorting Functions811655 -Ref: Array Sorting Functions-Footnote-1816746 -Node: Two-way I/O816942 -Ref: Two-way I/O-Footnote-1823493 -Ref: Two-way I/O-Footnote-2823680 -Node: TCP/IP Networking823762 -Node: Profiling826880 -Ref: Profiling-Footnote-1835552 -Node: Advanced Features Summary835875 -Node: Internationalization837719 -Node: I18N and L10N839199 -Node: Explaining gettext839886 -Ref: Explaining gettext-Footnote-1845778 -Ref: Explaining gettext-Footnote-2845963 -Node: Programmer i18n846128 -Ref: Programmer i18n-Footnote-1851077 -Node: Translator i18n851126 -Node: String Extraction851920 -Ref: String Extraction-Footnote-1853052 -Node: Printf Ordering853138 -Ref: Printf Ordering-Footnote-1855924 -Node: I18N Portability855988 -Ref: I18N Portability-Footnote-1858444 -Node: I18N Example858507 -Ref: I18N Example-Footnote-1861313 -Node: Gawk I18N861386 -Node: I18N Summary862031 -Node: Debugger863372 -Node: Debugging864394 -Node: Debugging Concepts864835 -Node: Debugging Terms866644 -Node: Awk Debugging869219 -Node: Sample Debugging Session870125 -Node: Debugger Invocation870659 -Node: Finding The Bug872045 -Node: List of Debugger Commands878523 -Node: Breakpoint Control879856 -Node: Debugger Execution Control883550 -Node: Viewing And Changing Data886912 -Node: Execution Stack890286 -Node: Debugger Info891923 -Node: Miscellaneous Debugger Commands895994 -Node: Readline Support901082 -Node: Limitations901978 -Node: Debugging Summary904087 -Node: Arbitrary Precision Arithmetic905366 -Node: Computer Arithmetic906782 -Ref: table-numeric-ranges910373 -Ref: Computer Arithmetic-Footnote-1911095 -Node: Math Definitions911152 -Ref: table-ieee-formats914466 -Ref: Math Definitions-Footnote-1915069 -Node: MPFR features915174 -Node: FP Math Caution916891 -Ref: FP Math Caution-Footnote-1917963 -Node: Inexactness of computations918332 -Node: Inexact representation919292 -Node: Comparing FP Values920652 -Node: Errors accumulate921734 -Node: Getting Accuracy923167 -Node: Try To Round925877 -Node: Setting precision926776 -Ref: table-predefined-precision-strings927473 -Node: Setting the rounding mode929303 -Ref: table-gawk-rounding-modes929677 -Ref: Setting the rounding mode-Footnote-1933085 -Node: Arbitrary Precision Integers933264 -Ref: Arbitrary Precision Integers-Footnote-1938181 -Node: POSIX Floating Point Problems938330 -Ref: POSIX Floating Point Problems-Footnote-1942212 -Node: Floating point summary942250 -Node: Dynamic Extensions944440 -Node: Extension Intro945993 -Node: Plugin License947259 -Node: Extension Mechanism Outline948056 -Ref: figure-load-extension948495 -Ref: figure-register-new-function950060 -Ref: figure-call-new-function951152 -Node: Extension API Description953214 -Node: Extension API Functions Introduction954856 -Node: General Data Types960190 -Ref: General Data Types-Footnote-1967395 -Node: Memory Allocation Functions967694 -Ref: Memory Allocation Functions-Footnote-1970539 -Node: Constructor Functions970638 -Node: Registration Functions973637 -Node: Extension Functions974322 -Node: Exit Callback Functions979535 -Node: Extension Version String980785 -Node: Input Parsers981448 -Node: Output Wrappers994155 -Node: Two-way processors998667 -Node: Printing Messages1000932 -Ref: Printing Messages-Footnote-11002103 -Node: Updating ERRNO1002256 -Node: Requesting Values1002995 -Ref: table-value-types-returned1003732 -Node: Accessing Parameters1004668 -Node: Symbol Table Access1005903 -Node: Symbol table by name1006415 -Node: Symbol table by cookie1008204 -Ref: Symbol table by cookie-Footnote-11012389 -Node: Cached values1012453 -Ref: Cached values-Footnote-11015989 -Node: Array Manipulation1016080 -Ref: Array Manipulation-Footnote-11017171 -Node: Array Data Types1017208 -Ref: Array Data Types-Footnote-11019866 -Node: Array Functions1019958 -Node: Flattening Arrays1024357 -Node: Creating Arrays1031298 -Node: Redirection API1036067 -Node: Extension API Variables1038909 -Node: Extension Versioning1039542 -Ref: gawk-api-version1039979 -Node: Extension API Informational Variables1041707 -Node: Extension API Boilerplate1042771 -Node: Changes from API V11046633 -Node: Finding Extensions1047293 -Node: Extension Example1047852 -Node: Internal File Description1048650 -Node: Internal File Ops1052730 -Ref: Internal File Ops-Footnote-11064130 -Node: Using Internal File Ops1064270 -Ref: Using Internal File Ops-Footnote-11066653 -Node: Extension Samples1066927 -Node: Extension Sample File Functions1068456 -Node: Extension Sample Fnmatch1076105 -Node: Extension Sample Fork1077592 -Node: Extension Sample Inplace1078810 -Node: Extension Sample Ord1082020 -Node: Extension Sample Readdir1082856 -Ref: table-readdir-file-types1083745 -Node: Extension Sample Revout1084550 -Node: Extension Sample Rev2way1085139 -Node: Extension Sample Read write array1085879 -Node: Extension Sample Readfile1087821 -Node: Extension Sample Time1088916 -Node: Extension Sample API Tests1090264 -Node: gawkextlib1090756 -Node: Extension summary1093203 -Node: Extension Exercises1096905 -Node: Language History1098403 -Node: V7/SVR3.11100059 -Node: SVR41102211 -Node: POSIX1103645 -Node: BTL1105024 -Node: POSIX/GNU1105753 -Node: Feature History1111645 -Node: Common Extensions1126015 -Node: Ranges and Locales1127298 -Ref: Ranges and Locales-Footnote-11131914 -Ref: Ranges and Locales-Footnote-21131941 -Ref: Ranges and Locales-Footnote-31132176 -Node: Contributors1132397 -Node: History summary1137957 -Node: Installation1139337 -Node: Gawk Distribution1140281 -Node: Getting1140765 -Node: Extracting1141726 -Node: Distribution contents1143364 -Node: Unix Installation1149706 -Node: Quick Installation1150388 -Node: Shell Startup Files1152802 -Node: Additional Configuration Options1153891 -Node: Configuration Philosophy1155696 -Node: Non-Unix Installation1158065 -Node: PC Installation1158525 -Node: PC Binary Installation1159363 -Node: PC Compiling1159798 -Node: PC Using1160915 -Node: Cygwin1163960 -Node: MSYS1164730 -Node: VMS Installation1165231 -Node: VMS Compilation1166022 -Ref: VMS Compilation-Footnote-11167251 -Node: VMS Dynamic Extensions1167309 -Node: VMS Installation Details1168994 -Node: VMS Running1171247 -Node: VMS GNV1175526 -Node: VMS Old Gawk1176261 -Node: Bugs1176732 -Node: Bug address1177395 -Node: Usenet1179792 -Node: Maintainers1180569 -Node: Other Versions1181945 -Node: Installation summary1188529 -Node: Notes1189564 -Node: Compatibility Mode1190429 -Node: Additions1191211 -Node: Accessing The Source1192136 -Node: Adding Code1193571 -Node: New Ports1199789 -Node: Derived Files1204277 -Ref: Derived Files-Footnote-11209762 -Ref: Derived Files-Footnote-21209797 -Ref: Derived Files-Footnote-31210395 -Node: Future Extensions1210509 -Node: Implementation Limitations1211167 -Node: Extension Design1212350 -Node: Old Extension Problems1213504 -Ref: Old Extension Problems-Footnote-11215022 -Node: Extension New Mechanism Goals1215079 -Ref: Extension New Mechanism Goals-Footnote-11218443 -Node: Extension Other Design Decisions1218632 -Node: Extension Future Growth1220745 -Node: Old Extension Mechanism1221581 -Node: Notes summary1223344 -Node: Basic Concepts1224526 -Node: Basic High Level1225207 -Ref: figure-general-flow1225489 -Ref: figure-process-flow1226174 -Ref: Basic High Level-Footnote-11229475 -Node: Basic Data Typing1229660 -Node: Glossary1232988 -Node: Copying1264935 -Node: GNU Free Documentation License1302474 -Node: Index1327592 +Ref: Numeric Functions-Footnote-1524675 +Ref: Numeric Functions-Footnote-2525032 +Ref: Numeric Functions-Footnote-3525080 +Node: String Functions525352 +Ref: String Functions-Footnote-1549010 +Ref: String Functions-Footnote-2549138 +Ref: String Functions-Footnote-3549386 +Node: Gory Details549473 +Ref: table-sub-escapes551264 +Ref: table-sub-proposed552783 +Ref: table-posix-sub554146 +Ref: table-gensub-escapes555687 +Ref: Gory Details-Footnote-1556510 +Node: I/O Functions556664 +Ref: table-system-return-values563246 +Ref: I/O Functions-Footnote-1565226 +Ref: I/O Functions-Footnote-2565374 +Node: Time Functions565494 +Ref: Time Functions-Footnote-1576161 +Ref: Time Functions-Footnote-2576229 +Ref: Time Functions-Footnote-3576387 +Ref: Time Functions-Footnote-4576498 +Ref: Time Functions-Footnote-5576610 +Ref: Time Functions-Footnote-6576837 +Node: Bitwise Functions577103 +Ref: table-bitwise-ops577697 +Ref: Bitwise Functions-Footnote-1583730 +Ref: Bitwise Functions-Footnote-2583903 +Node: Type Functions584094 +Node: I18N Functions586769 +Node: User-defined588420 +Node: Definition Syntax589225 +Ref: Definition Syntax-Footnote-1594912 +Node: Function Example594983 +Ref: Function Example-Footnote-1597905 +Node: Function Caveats597927 +Node: Calling A Function598445 +Node: Variable Scope599403 +Node: Pass By Value/Reference602397 +Node: Return Statement605896 +Node: Dynamic Typing608875 +Node: Indirect Calls609805 +Ref: Indirect Calls-Footnote-1620056 +Node: Functions Summary620184 +Node: Library Functions622889 +Ref: Library Functions-Footnote-1626496 +Ref: Library Functions-Footnote-2626639 +Node: Library Names626810 +Ref: Library Names-Footnote-1630270 +Ref: Library Names-Footnote-2630493 +Node: General Functions630579 +Node: Strtonum Function631682 +Node: Assert Function634704 +Node: Round Function638030 +Node: Cliff Random Function639571 +Node: Ordinal Functions640587 +Ref: Ordinal Functions-Footnote-1643650 +Ref: Ordinal Functions-Footnote-2643902 +Node: Join Function644112 +Ref: Join Function-Footnote-1645882 +Node: Getlocaltime Function646082 +Node: Readfile Function649824 +Node: Shell Quoting651796 +Node: Data File Management653197 +Node: Filetrans Function653829 +Node: Rewind Function657925 +Node: File Checking659831 +Ref: File Checking-Footnote-1661165 +Node: Empty Files661366 +Node: Ignoring Assigns663345 +Node: Getopt Function664895 +Ref: Getopt Function-Footnote-1676364 +Node: Passwd Functions676564 +Ref: Passwd Functions-Footnote-1685403 +Node: Group Functions685491 +Ref: Group Functions-Footnote-1693389 +Node: Walking Arrays693596 +Node: Library Functions Summary696604 +Node: Library Exercises698010 +Node: Sample Programs698475 +Node: Running Examples699245 +Node: Clones699973 +Node: Cut Program701197 +Node: Egrep Program711126 +Ref: Egrep Program-Footnote-1718638 +Node: Id Program718748 +Node: Split Program722428 +Ref: Split Program-Footnote-1725887 +Node: Tee Program726016 +Node: Uniq Program728806 +Node: Wc Program736232 +Ref: Wc Program-Footnote-1740487 +Node: Miscellaneous Programs740581 +Node: Dupword Program741794 +Node: Alarm Program743824 +Node: Translate Program748679 +Ref: Translate Program-Footnote-1753244 +Node: Labels Program753514 +Ref: Labels Program-Footnote-1756865 +Node: Word Sorting756949 +Node: History Sorting761021 +Node: Extract Program762856 +Node: Simple Sed770385 +Node: Igawk Program773459 +Ref: Igawk Program-Footnote-1787790 +Ref: Igawk Program-Footnote-2787992 +Ref: Igawk Program-Footnote-3788114 +Node: Anagram Program788229 +Node: Signature Program791291 +Node: Programs Summary792538 +Node: Programs Exercises793752 +Ref: Programs Exercises-Footnote-1797881 +Node: Advanced Features797972 +Node: Nondecimal Data799962 +Node: Array Sorting801553 +Node: Controlling Array Traversal802253 +Ref: Controlling Array Traversal-Footnote-1810620 +Node: Array Sorting Functions810738 +Ref: Array Sorting Functions-Footnote-1815829 +Node: Two-way I/O816025 +Ref: Two-way I/O-Footnote-1822576 +Ref: Two-way I/O-Footnote-2822763 +Node: TCP/IP Networking822845 +Node: Profiling825963 +Ref: Profiling-Footnote-1834635 +Node: Advanced Features Summary834958 +Node: Internationalization836802 +Node: I18N and L10N838282 +Node: Explaining gettext838969 +Ref: Explaining gettext-Footnote-1844861 +Ref: Explaining gettext-Footnote-2845046 +Node: Programmer i18n845211 +Ref: Programmer i18n-Footnote-1850160 +Node: Translator i18n850209 +Node: String Extraction851003 +Ref: String Extraction-Footnote-1852135 +Node: Printf Ordering852221 +Ref: Printf Ordering-Footnote-1855007 +Node: I18N Portability855071 +Ref: I18N Portability-Footnote-1857527 +Node: I18N Example857590 +Ref: I18N Example-Footnote-1860396 +Node: Gawk I18N860469 +Node: I18N Summary861114 +Node: Debugger862455 +Node: Debugging863477 +Node: Debugging Concepts863918 +Node: Debugging Terms865727 +Node: Awk Debugging868302 +Node: Sample Debugging Session869208 +Node: Debugger Invocation869742 +Node: Finding The Bug871128 +Node: List of Debugger Commands877606 +Node: Breakpoint Control878939 +Node: Debugger Execution Control882633 +Node: Viewing And Changing Data885995 +Node: Execution Stack889369 +Node: Debugger Info891006 +Node: Miscellaneous Debugger Commands895077 +Node: Readline Support900165 +Node: Limitations901061 +Node: Debugging Summary903170 +Node: Arbitrary Precision Arithmetic904449 +Node: Computer Arithmetic905865 +Ref: table-numeric-ranges909456 +Ref: Computer Arithmetic-Footnote-1910178 +Node: Math Definitions910235 +Ref: table-ieee-formats913549 +Ref: Math Definitions-Footnote-1914152 +Node: MPFR features914257 +Node: FP Math Caution915974 +Ref: FP Math Caution-Footnote-1917046 +Node: Inexactness of computations917415 +Node: Inexact representation918375 +Node: Comparing FP Values919735 +Node: Errors accumulate920817 +Node: Getting Accuracy922250 +Node: Try To Round924960 +Node: Setting precision925859 +Ref: table-predefined-precision-strings926556 +Node: Setting the rounding mode928386 +Ref: table-gawk-rounding-modes928760 +Ref: Setting the rounding mode-Footnote-1932168 +Node: Arbitrary Precision Integers932347 +Ref: Arbitrary Precision Integers-Footnote-1935534 +Node: POSIX Floating Point Problems935683 +Ref: POSIX Floating Point Problems-Footnote-1939565 +Node: Floating point summary939603 +Node: Dynamic Extensions941793 +Node: Extension Intro943346 +Node: Plugin License944612 +Node: Extension Mechanism Outline945409 +Ref: figure-load-extension945848 +Ref: figure-register-new-function947413 +Ref: figure-call-new-function948505 +Node: Extension API Description950567 +Node: Extension API Functions Introduction952209 +Node: General Data Types957543 +Ref: General Data Types-Footnote-1964748 +Node: Memory Allocation Functions965047 +Ref: Memory Allocation Functions-Footnote-1967892 +Node: Constructor Functions967991 +Node: Registration Functions970990 +Node: Extension Functions971675 +Node: Exit Callback Functions976888 +Node: Extension Version String978138 +Node: Input Parsers978801 +Node: Output Wrappers991508 +Node: Two-way processors996020 +Node: Printing Messages998285 +Ref: Printing Messages-Footnote-1999456 +Node: Updating ERRNO999609 +Node: Requesting Values1000348 +Ref: table-value-types-returned1001085 +Node: Accessing Parameters1002021 +Node: Symbol Table Access1003256 +Node: Symbol table by name1003768 +Node: Symbol table by cookie1005557 +Ref: Symbol table by cookie-Footnote-11009742 +Node: Cached values1009806 +Ref: Cached values-Footnote-11013342 +Node: Array Manipulation1013433 +Ref: Array Manipulation-Footnote-11014524 +Node: Array Data Types1014561 +Ref: Array Data Types-Footnote-11017219 +Node: Array Functions1017311 +Node: Flattening Arrays1021710 +Node: Creating Arrays1028651 +Node: Redirection API1033420 +Node: Extension API Variables1036262 +Node: Extension Versioning1036895 +Ref: gawk-api-version1037332 +Node: Extension API Informational Variables1039060 +Node: Extension API Boilerplate1040124 +Node: Changes from API V11043986 +Node: Finding Extensions1044646 +Node: Extension Example1045205 +Node: Internal File Description1046003 +Node: Internal File Ops1050083 +Ref: Internal File Ops-Footnote-11061483 +Node: Using Internal File Ops1061623 +Ref: Using Internal File Ops-Footnote-11064006 +Node: Extension Samples1064280 +Node: Extension Sample File Functions1065809 +Node: Extension Sample Fnmatch1073458 +Node: Extension Sample Fork1074945 +Node: Extension Sample Inplace1076163 +Node: Extension Sample Ord1079373 +Node: Extension Sample Readdir1080209 +Ref: table-readdir-file-types1081098 +Node: Extension Sample Revout1081903 +Node: Extension Sample Rev2way1082492 +Node: Extension Sample Read write array1083232 +Node: Extension Sample Readfile1085174 +Node: Extension Sample Time1086269 +Node: Extension Sample API Tests1087617 +Node: gawkextlib1088109 +Node: Extension summary1090556 +Node: Extension Exercises1094258 +Node: Language History1095756 +Node: V7/SVR3.11097412 +Node: SVR41099564 +Node: POSIX1100998 +Node: BTL1102377 +Node: POSIX/GNU1103106 +Node: Feature History1108884 +Node: Common Extensions1123195 +Node: Ranges and Locales1124478 +Ref: Ranges and Locales-Footnote-11129094 +Ref: Ranges and Locales-Footnote-21129121 +Ref: Ranges and Locales-Footnote-31129356 +Node: Contributors1129577 +Node: History summary1135137 +Node: Installation1136517 +Node: Gawk Distribution1137461 +Node: Getting1137945 +Node: Extracting1138906 +Node: Distribution contents1140544 +Node: Unix Installation1146886 +Node: Quick Installation1147568 +Node: Shell Startup Files1149982 +Node: Additional Configuration Options1151071 +Node: Configuration Philosophy1152876 +Node: Non-Unix Installation1155245 +Node: PC Installation1155705 +Node: PC Binary Installation1156543 +Node: PC Compiling1156978 +Node: PC Using1158095 +Node: Cygwin1161140 +Node: MSYS1161910 +Node: VMS Installation1162411 +Node: VMS Compilation1163202 +Ref: VMS Compilation-Footnote-11164431 +Node: VMS Dynamic Extensions1164489 +Node: VMS Installation Details1166174 +Node: VMS Running1168427 +Node: VMS GNV1172706 +Node: VMS Old Gawk1173441 +Node: Bugs1173912 +Node: Bug address1174575 +Node: Usenet1176972 +Node: Maintainers1177749 +Node: Other Versions1179125 +Node: Installation summary1185709 +Node: Notes1186744 +Node: Compatibility Mode1187609 +Node: Additions1188391 +Node: Accessing The Source1189316 +Node: Adding Code1190751 +Node: New Ports1196969 +Node: Derived Files1201457 +Ref: Derived Files-Footnote-11206942 +Ref: Derived Files-Footnote-21206977 +Ref: Derived Files-Footnote-31207575 +Node: Future Extensions1207689 +Node: Implementation Limitations1208347 +Node: Extension Design1209530 +Node: Old Extension Problems1210684 +Ref: Old Extension Problems-Footnote-11212202 +Node: Extension New Mechanism Goals1212259 +Ref: Extension New Mechanism Goals-Footnote-11215623 +Node: Extension Other Design Decisions1215812 +Node: Extension Future Growth1217925 +Node: Old Extension Mechanism1218761 +Node: Notes summary1220524 +Node: Basic Concepts1221706 +Node: Basic High Level1222387 +Ref: figure-general-flow1222669 +Ref: figure-process-flow1223354 +Ref: Basic High Level-Footnote-11226655 +Node: Basic Data Typing1226840 +Node: Glossary1230168 +Node: Copying1262115 +Node: GNU Free Documentation License1299654 +Node: Index1324772 End Tag Table diff --git a/doc/gawk.texi b/doc/gawk.texi index fa8c6664..d374c93a 100644 --- a/doc/gawk.texi +++ b/doc/gawk.texi @@ -17458,9 +17458,10 @@ 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 +@ifset INTDIV +@item @code{intdiv0(@var{numerator}, @var{denominator}, @var{result})} +@cindexawkfunc{intdiv0} +@cindex intdiv0 Perform integer division, similar to the standard C @code{div()} function. First, truncate @code{numerator} and @code{denominator} towards zero, creating integer values. Clear the @code{result} @@ -17478,6 +17479,7 @@ Precision Integers}). This function is a @code{gawk} extension. It is not available in compatibility mode (@pxref{Options}). +@end ifset @item @code{log(@var{x})} @cindexawkfunc{log} @@ -31907,16 +31909,18 @@ gawk -M 'BEGIN @{ n = 13; print n % 2 @}' When dividing two arbitrary precision integers with either @samp{/} or @samp{%}, the result is typically an arbitrary precision floating point value (unless the denominator evenly -divides into the numerator). In order to do integer division +divides into the numerator). +@ifset INTDIV +In order to do integer division or remainder with arbitrary precision integers, use the built-in -@code{intdiv()} function (@pxref{Numeric Functions}). +@code{intdiv0()} function (@pxref{Numeric Functions}). -You can simulate the @code{intdiv()} function in standard @command{awk} +You can simulate the @code{intdiv0()} function in standard @command{awk} using this user-defined function: @example @c file eg/lib/intdiv.awk -# intdiv --- do integer division +# intdiv0 --- do integer division @c endfile @ignore @@ -31927,12 +31931,15 @@ using this user-defined function: # # Name changed from div() to intdiv() # April, 2015 +# +# Changed to intdiv0() +# April, 2016 @c endfile @end ignore @c file eg/lib/intdiv.awk -function intdiv(numerator, denominator, result) +function intdiv0(numerator, denominator, result) @{ split("", result) @@ -32019,6 +32026,7 @@ because it's quite easy to modify for tiny memory devices with smallish word sizes. See @uref{http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/articles.cgi?read=899}. @end quotation +@end ifset @node POSIX Floating Point Problems @section Standards Versus Existing Practice @@ -37067,10 +37075,12 @@ The @code{bindtextdomain()}, @code{dcgettext()}, and @code{dcngettext()} functions for internationalization (@pxref{Programmer i18n}) +@ifset INTDIV @item -The @code{intdiv()} function for doing integer +The @code{intdiv0()} function for doing integer division and remainder (@pxref{Numeric Functions}) +@end ifset @end itemize @item @@ -37862,9 +37872,11 @@ The @command{igawk} program and its manual page are no longer installed when @command{gawk} is built. @xref{Igawk Program}. +@ifset INTDIV @item -The @code{intdiv()} function. +The @code{intdiv0()} function. @xref{Numeric Functions}. +@end ifset @item The maximum number of hexadecimal digits in @samp{\x} escapes diff --git a/doc/gawktexi.in b/doc/gawktexi.in index 21c6e506..9d7be49a 100644 --- a/doc/gawktexi.in +++ b/doc/gawktexi.in @@ -16731,9 +16731,10 @@ 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 +@ifset INTDIV +@item @code{intdiv0(@var{numerator}, @var{denominator}, @var{result})} +@cindexawkfunc{intdiv0} +@cindex intdiv0 Perform integer division, similar to the standard C @code{div()} function. First, truncate @code{numerator} and @code{denominator} towards zero, creating integer values. Clear the @code{result} @@ -16751,6 +16752,7 @@ Precision Integers}). This function is a @code{gawk} extension. It is not available in compatibility mode (@pxref{Options}). +@end ifset @item @code{log(@var{x})} @cindexawkfunc{log} @@ -30921,16 +30923,18 @@ gawk -M 'BEGIN @{ n = 13; print n % 2 @}' When dividing two arbitrary precision integers with either @samp{/} or @samp{%}, the result is typically an arbitrary precision floating point value (unless the denominator evenly -divides into the numerator). In order to do integer division +divides into the numerator). +@ifset INTDIV +In order to do integer division or remainder with arbitrary precision integers, use the built-in -@code{intdiv()} function (@pxref{Numeric Functions}). +@code{intdiv0()} function (@pxref{Numeric Functions}). -You can simulate the @code{intdiv()} function in standard @command{awk} +You can simulate the @code{intdiv0()} function in standard @command{awk} using this user-defined function: @example @c file eg/lib/intdiv.awk -# intdiv --- do integer division +# intdiv0 --- do integer division @c endfile @ignore @@ -30941,12 +30945,15 @@ using this user-defined function: # # Name changed from div() to intdiv() # April, 2015 +# +# Changed to intdiv0() +# April, 2016 @c endfile @end ignore @c file eg/lib/intdiv.awk -function intdiv(numerator, denominator, result) +function intdiv0(numerator, denominator, result) @{ split("", result) @@ -31033,6 +31040,7 @@ because it's quite easy to modify for tiny memory devices with smallish word sizes. See @uref{http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/articles.cgi?read=899}. @end quotation +@end ifset @node POSIX Floating Point Problems @section Standards Versus Existing Practice @@ -36081,10 +36089,12 @@ The @code{bindtextdomain()}, @code{dcgettext()}, and @code{dcngettext()} functions for internationalization (@pxref{Programmer i18n}) +@ifset INTDIV @item -The @code{intdiv()} function for doing integer +The @code{intdiv0()} function for doing integer division and remainder (@pxref{Numeric Functions}) +@end ifset @end itemize @item @@ -36876,9 +36886,11 @@ The @command{igawk} program and its manual page are no longer installed when @command{gawk} is built. @xref{Igawk Program}. +@ifset INTDIV @item -The @code{intdiv()} function. +The @code{intdiv0()} function. @xref{Numeric Functions}. +@end ifset @item The maximum number of hexadecimal digits in @samp{\x} escapes diff --git a/extension/ChangeLog b/extension/ChangeLog index ef668467..7307a11a 100644 --- a/extension/ChangeLog +++ b/extension/ChangeLog @@ -1,3 +1,7 @@ +2017-04-16 Arnold D. Robbins <arnold@skeeve.com> + + * intdiv.c (func_table): Function is now named intdiv. + 2017-04-14 Andrew J. Schorr <aschorr@telemetry-investments.com> * intdiv.c (do_intdiv): On division by zero, return -1 and issue a diff --git a/extension/intdiv.c b/extension/intdiv.c index aa1afd18..77b4290b 100644 --- a/extension/intdiv.c +++ b/extension/intdiv.c @@ -194,7 +194,7 @@ do_intdiv(int nargs, awk_value_t *result, struct awk_ext_func *unused) } static awk_ext_func_t func_table[] = { - { "api_intdiv", do_intdiv, 3, 3, awk_false, NULL }, + { "intdiv", do_intdiv, 3, 3, awk_false, NULL }, }; /* init_intdiv --- initialization routine */ @@ -1169,6 +1169,7 @@ do_mpfr_srand(int nargs) return res; } +#ifdef SUPPLY_INTDIV /* do_mpfr_intdiv --- do integer division, return quotient and remainder in dest array */ /* @@ -1262,6 +1263,7 @@ do_mpfr_intdiv(int nargs) return make_number((AWKNUM) 0.0); } +#endif /* SUPPLY_INTDIV */ /* * mpg_tofloat --- convert an arbitrary-precision integer operand to diff --git a/test/ChangeLog b/test/ChangeLog index ecac0519..04077f1e 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,8 @@ +2017-04-16 Arnold D. Robbins <arnold@skeeve.com> + + * mpfrsqrt.awk: Add `@load intdiv'. + * dumpvars.ok, id.ok, symtab6.ok, symtab8.ok: Updated. + 2017-04-12 Manuel Collado <m-collado@users.sourceforge.net> * Makefile.am (fpat6): New test. diff --git a/test/dumpvars.ok b/test/dumpvars.ok index 7caecd35..85d1c859 100644 --- a/test/dumpvars.ok +++ b/test/dumpvars.ok @@ -9,7 +9,7 @@ FILENAME: "-" FNR: 3 FPAT: "[^[:space:]]+" FS: " " -FUNCTAB: array, 42 elements +FUNCTAB: array, 41 elements IGNORECASE: 0 LINT: 0 NF: 1 @@ -47,7 +47,6 @@ gsub -> builtin i -> untyped index -> builtin int -> builtin -intdiv -> builtin isarray -> builtin length -> builtin log -> builtin diff --git a/test/mpfrsqrt.awk b/test/mpfrsqrt.awk index 3fb1f5f8..8cc416bb 100644 --- a/test/mpfrsqrt.awk +++ b/test/mpfrsqrt.awk @@ -9,6 +9,8 @@ # # Running this program (sqrt-bug.awk): # -------------------------------------------------------------------- + +@load "intdiv" BEGIN { a=11111111111111111111111111111111111111111111111111111111111 print sqrt(a^2) diff --git a/test/symtab6.ok b/test/symtab6.ok index 34c10636..7de717a0 100644 --- a/test/symtab6.ok +++ b/test/symtab6.ok @@ -9,7 +9,7 @@ FILENAME: "" FNR: 0 FPAT: "[^[:space:]]+" FS: " " -FUNCTAB: array, 42 elements +FUNCTAB: array, 41 elements IGNORECASE: 0 LINT: 0 NF: 0 diff --git a/test/symtab8.ok b/test/symtab8.ok index 0cf40fe9..da29b585 100644 --- a/test/symtab8.ok +++ b/test/symtab8.ok @@ -9,7 +9,7 @@ FIELDWIDTHS: "" FNR: 1 FPAT: "[^[:space:]]+" FS: " " -FUNCTAB: array, 42 elements +FUNCTAB: array, 41 elements IGNORECASE: 0 LINT: 0 NF: 1 |