diff options
-rw-r--r-- | ChangeLog | 13 | ||||
-rw-r--r-- | NEWS | 8 | ||||
-rw-r--r-- | awk.h | 9 | ||||
-rw-r--r-- | awklib/eg/test-programs/gen-float-table.awk | 59 | ||||
-rw-r--r-- | awklib/eg/test-programs/gen-float-table.c | 60 | ||||
-rw-r--r-- | awklib/eg/test-programs/gen-float-table.py | 42 | ||||
-rw-r--r-- | builtin.c | 2 | ||||
-rw-r--r-- | doc/ChangeLog | 34 | ||||
-rw-r--r-- | doc/gawk.info | 1284 | ||||
-rw-r--r-- | doc/gawk.texi | 271 | ||||
-rw-r--r-- | doc/gawktexi.in | 271 | ||||
-rw-r--r-- | doc/it/ChangeLog | 17 | ||||
-rwxr-xr-x[-rw-r--r--] | doc/it/gawktexi.in | 616 | ||||
-rwxr-xr-x[-rw-r--r--] | doc/it/texinfo.tex | 165 | ||||
-rw-r--r-- | doc/wordlist | 1 | ||||
-rw-r--r-- | eval.c | 96 | ||||
-rw-r--r-- | interpret.h | 12 | ||||
-rw-r--r-- | mpfr.c | 44 | ||||
-rw-r--r-- | node.c | 3 |
19 files changed, 2100 insertions, 907 deletions
@@ -120,6 +120,19 @@ 2020-11-02 Arnold D. Robbins <arnold@skeeve.com> + Make gawk numeric comparisons act like C doubles. + MPFR differs from doubles w.r.t. NaN, not sure why yet. + + * awk.h (scalar_cmp_t): New enum. + * builtin.c (format_nan_inf): Use mpfr_signbit, not mpfr_sgn. + * eval.c (cmp_doubles): New routine. + (cmp_scalars): Change type to bool, rework logic. + * interpret.h (r_interpret): Rework scalar comparisons. + * mpfr.c (mpg_cmp_as_numbers): New routine. + * node.c: Use <math.h>, not "math.h", minor comment edits. + +2020-11-02 Arnold D. Robbins <arnold@skeeve.com> + * re.c (make_regexp): Cast len parameter to int to avoid compiler warnings. @@ -4,6 +4,14 @@ are permitted in any medium without royalty provided the copyright notice and this notice are preserved. +Changes from 5.1.x to 5.2.0 +--------------------------- + +1. Numeric scalars now compare in the same way as C for the relational +operators. Comparison order for sorting has not changed. This only +makes a difference when comparing Infinity and NaN values with +regular numbers; it should not be noticeable most of the time. + Changes from 5.1.0 to 5.1.1 --------------------------- @@ -1576,6 +1576,15 @@ typedef enum { extern field_sep_type current_field_sep(void); extern const char *current_field_sep_str(void); +typedef enum { + SCALAR_EQ, + SCALAR_NEQ, + SCALAR_LT, + SCALAR_LE, + SCALAR_GT, + SCALAR_GE, +} scalar_cmp_t; + /* gawkapi.c: */ extern gawk_api_t api_impl; extern void init_ext_api(void); diff --git a/awklib/eg/test-programs/gen-float-table.awk b/awklib/eg/test-programs/gen-float-table.awk new file mode 100644 index 00000000..ea6269c3 --- /dev/null +++ b/awklib/eg/test-programs/gen-float-table.awk @@ -0,0 +1,59 @@ +function eq(left, right) +{ + return left == right +} + +function ne(left, right) +{ + return left != right +} + +function lt(left, right) +{ + return left < right +} + +function le(left, right) +{ + return left <= right +} + +function gt(left, right) +{ + return left > right +} + +function ge(left, right) +{ + return left >= right +} + +BEGIN { + nan = sqrt(-1) + inf = -log(0) + split("== != < <= > >=", names) + names[3] = names[3] " " + names[5] = names[5] " " + split("eq ne lt le gt ge", funcs) + + compare[1] = 2.0 + compare[2] = values[1] = -sqrt(-1.0) # nan + compare[3] = values[2] = sqrt(-1.0) # -nan + compare[4] = values[3] = -log(0.0) # inf + compare[5] = values[4] = log(0.0) # -inf + + for (i = 1; i in values; i++) { + for (j = 1; j in compare; j++) { + for (k = 1; k in names; k++) { + the_func = funcs[k] + printf("%g %s %g -> %s\n", + values[i], + names[k], + compare[j], + @the_func(values[i], compare[j]) ? + "True" : "False"); + } + printf("\n"); + } + } +} diff --git a/awklib/eg/test-programs/gen-float-table.c b/awklib/eg/test-programs/gen-float-table.c new file mode 100644 index 00000000..ba3a0d05 --- /dev/null +++ b/awklib/eg/test-programs/gen-float-table.c @@ -0,0 +1,60 @@ +#include <stdio.h> +#include <math.h> +#include <stdbool.h> + +#define def_func(name, op) \ + bool name(double left, double right) { \ + return left op right; \ + } + +def_func(eq, ==) +def_func(ne, !=) +def_func(lt, <) +def_func(le, <=) +def_func(gt, >) +def_func(ge, >=) + +struct { + const char *name; + bool (*func)(double left, double right); +} functions[] = { + { "==", eq }, + { "!=", ne }, + { "< ", lt }, + { "<=", le }, + { "> ", gt }, + { ">=", ge }, + { 0, 0 } +}; + +int main() +{ + double values[] = { + -sqrt(-1), // nan + sqrt(-1), // -nan + -log(0.0), // inf + log(0.0) // -inf + }; + double compare[] = { 2.0, + -sqrt(-1), // nan + sqrt(-1), // -nan + -log(0.0), // inf + log(0.0) // -inf + }; + + int i, j, k; + + for (i = 0; i < 4; i++) { + for (j = 0; j < 5; j++) { + for (k = 0; functions[k].name != NULL; k++) { + printf("%g %s %g -> %s\n", values[i], + functions[k].name, + compare[j], + functions[k].func(values[i], compare[j]) ? "True" : "False"); + } + printf("\n"); + } + } + + return 0; +} diff --git a/awklib/eg/test-programs/gen-float-table.py b/awklib/eg/test-programs/gen-float-table.py new file mode 100644 index 00000000..8631b817 --- /dev/null +++ b/awklib/eg/test-programs/gen-float-table.py @@ -0,0 +1,42 @@ +from math import * + +nan = float('NaN') +inf = float('Inf') + +def eq(left, right): + return left == right + +def ne(left, right): + return left != right + +def lt(left, right): + return left < right + +def le(left, right): + return left <= right + +def gt(left, right): + return left > right + +def ge(left, right): + return left >= right + +func_map = { + "==": eq, + "!=": ne, + "< ": lt, + "<=": le, + "> ": gt, + ">=": ge, +} + +compare = [2.0, nan, -nan, inf, -inf] +values = [nan, -nan, inf, -inf] + +for i in range(len(values)): + for j in range(len(compare)): + for op in func_map: + print("%g %s %g -> %s" % + (values[i], op, compare[j], func_map[op](values[i], compare[j]))) + + print("") @@ -4277,7 +4277,7 @@ format_nan_inf(NODE *n, char format) goto fmt; } else if (mpfr_inf_p(n->mpg_numbr)) { - strcpy(buf, mpfr_sgn(n->mpg_numbr) < 0 ? "-inf" : "+inf"); + strcpy(buf, mpfr_signbit(n->mpg_numbr) ? "-inf" : "+inf"); goto fmt; } else diff --git a/doc/ChangeLog b/doc/ChangeLog index 2ce2417d..02a87af5 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,10 @@ +2021-02-01 Arnold D. Robbins <arnold@skeeve.com> + + * gawktexi.in (Strange values): Fix a typo in the awk test + program. Make the C and Awk versions print "True" and + "False" to match Python, making comparisons easier. Thanks to + Antonio Columbo for the suggestions. + 2021-01-25 Arnold D. Robbins <arnold@skeeve.com> * gawktexi.in: Fix some spelling errors. @@ -68,12 +75,39 @@ * gawkworkflow.texi: Add an additional web resource. * gawktexi.in: More edits in sample programs chapter. +2020-11-20 Arnold D. Robbins <arnold@skeeve.com> + + * gawktexi.in (Strange values): Correct the description of what + happens with infinity. Thanks to Antonio Columbo for pointing + out the problem. + 2020-11-16 Arnold D. Robbins <arnold@skeeve.com> * gawktexi.in (Nextfile Statement): Clarify what happens in a BEGINFILE rule. * gawktexi.in: Additional small fixes. +2020-11-15 Arnold D. Robbins <arnold@skeeve.com> + + * gawktexi.in (Strange values): Add test programs inside + @ignore; extracted to example directory. + +2020-11-09 Arnold D. Robbins <arnold@skeeve.com> + + * gawktexi.in: Samll improvement in strange numbers section. + +2020-11-04 Arnold D. Robbins <arnold@skeeve.com> + + * gawktexi.in (Strange values): New section on NaN and infinity. + Update some other bits to point to it. + * wordlist: Updated with more words. + +2020-11-16 Arnold D. Robbins <arnold@skeeve.com> + + * gawktexi.in (Nextfile Statement): Clarify what happens in + a BEGINFILE rule. +>>>>>>> master + 2020-10-31 Arnold D. Robbins <arnold@skeeve.com> * texinfo.tex: Updated from GNULIB. diff --git a/doc/gawk.info b/doc/gawk.info index d29e3525..fd56f412 100644 --- a/doc/gawk.info +++ b/doc/gawk.info @@ -547,6 +547,7 @@ in (a) below. A copy of the license is included in the section entitled * Inexact representation:: Numbers are not exactly represented. * Comparing FP Values:: How to compare floating point values. * Errors accumulate:: Errors get bigger as they go. +* Strange values:: A few words about infinities and NaNs. * Getting Accuracy:: Getting more accuracy takes some work. * Try To Round:: Add digits and round. * Setting precision:: How to set the precision. @@ -6933,8 +6934,8 @@ width. Here is a list of the format-control letters: On systems supporting IEEE 754 floating-point format, values representing negative infinity are formatted as '-inf' or '-infinity', and positive infinity as 'inf' or 'infinity'. The - special "not a number" value formats as '-nan' or 'nan' (*note Math - Definitions::). + special "not a number" value formats as '-nan' or 'nan' (*note + Strange values::). '%F' Like '%f', but the infinity and "not a number" values are spelled @@ -12826,7 +12827,7 @@ brackets ([ ]): 'log(X)' Return the natural logarithm of X, if X is positive; otherwise, - return 'NaN' ("not a number") on IEEE 754 systems. Additionally, + return NaN ("not a number") on IEEE 754 systems. Additionally, 'gawk' prints a warning message when 'x' is negative. 'rand()' @@ -24209,18 +24210,10 @@ material here: another number and infinity produce infinity. "NaN" - "Not a number."(1) A special value that results from attempting a - calculation that has no answer as a real number. In such a case, - programs can either receive a floating-point exception, or get - 'NaN' back as the result. The IEEE 754 standard recommends that - systems return 'NaN'. Some examples: - - 'sqrt(-1)' - This makes sense in the range of complex numbers, but not in - the range of real numbers, so the result is 'NaN'. - - 'log(-8)' - -8 is out of the domain of 'log()', so the result is 'NaN'. + "Not a number." A special value that results from attempting a + calculation that has no answer as a real number. *Note Strange + values::, for more information about infinity and not-a-number + values. "Normalized" How the significand (see later in this list) is usually stored. @@ -24279,11 +24272,6 @@ Table 16.3: Basic IEEE format values NOTE: The precision numbers include the implied leading one that gives them one extra bit of significand. - ---------- Footnotes ---------- - - (1) Thanks to Michael Brennan for this description, which we have -paraphrased, and for the examples. - File: gawk.info, Node: MPFR features, Next: FP Math Caution, Prev: Math Definitions, Up: Arbitrary Precision Arithmetic @@ -24376,6 +24364,7 @@ be sure of the number of significant decimal places in the final result. * Inexact representation:: Numbers are not exactly represented. * Comparing FP Values:: How to compare floating point values. * Errors accumulate:: Errors get bigger as they go. +* Strange values:: A few words about infinities and NaNs. File: gawk.info, Node: Inexact representation, Next: Comparing FP Values, Up: Inexactness of computations @@ -24440,7 +24429,7 @@ values with a delta, you should be sure to use 'difference < abs(delta)' in case someone passes in a negative delta value. -File: gawk.info, Node: Errors accumulate, Prev: Comparing FP Values, Up: Inexactness of computations +File: gawk.info, Node: Errors accumulate, Next: Strange values, Prev: Comparing FP Values, Up: Inexactness of computations 16.4.1.3 Errors Accumulate .......................... @@ -24488,6 +24477,64 @@ representations yield an unexpected result: -| 4 +File: gawk.info, Node: Strange values, Prev: Errors accumulate, Up: Inexactness of computations + +16.4.1.4 Floating Point Values They Didn't Talk About In School +............................................................... + +Both IEEE 754 floating-point hardware, and MPFR, support two kinds of +values that you probably didn't learn about in school. The first is +"infinity", a special value, that can be either negative or positive, +and which is either smaller than any other value (negative infinity), or +larger than any other value (positive infinity). When such values are +generated, 'gawk' prints them as either '-inf' or '+inf', respectively. +It accepts those strings as data input and converts them to the proper +floating-point values internally. + + Infinity values of the same sign compare as equal to each other. +Otherwise, operations (addition, subtraction, etc.) involving another +number and infinity produce mathematically reasonable results. + + The second kind of value is "not a number", or NaN for short.(1) +This is a special value that results from attempting a calculation that +has no answer as a real number. In such a case, programs can either +receive a floating-point exception, or get NaN back as the result. The +IEEE 754 standard recommends that systems return NaN. Some examples: + +'sqrt(-1)' + This makes sense in the range of complex numbers, but not in the + range of real numbers, so the result is NaN. + +'log(-8)' + -8 is out of the domain of 'log()', so the result is NaN. + + NaN values are strange. In particular, they cannot be compared with +other floating point values; any such comparison, except for "is not +equal to", returns false. NaN values are so much unequal to other +values that even comparing two identical NaN values with '!=' returns +true! + + NaN values can also be signed, although it depends upon the +implementation as to which sign you get for any operation that returns a +NaN. For example, on some systems, 'sqrt(-1)' returns a negative NaN. On +others, it returns a positive NaN. + + When such values are generated, 'gawk' prints them as either '-nan' +or '+nan', respectively. Here too, 'gawk' accepts those strings as data +input and converts them to the proper floating-point values internally. + + If you want to dive more deeply into this topic, you can find test +programs in C, 'awk' and Python in the directory +'awklib/eg/test-programs' in the 'gawk' distribution. These programs +enable comparison among programming languages as to how they handle NaN +and infinity values. + + ---------- Footnotes ---------- + + (1) Thanks to Michael Brennan for this description, which we have +paraphrased, and for the examples. + + File: gawk.info, Node: Getting Accuracy, Next: Try To Round, Prev: Inexactness of computations, Up: FP Math Caution 16.4.2 Getting the Accuracy You Need @@ -38024,603 +38071,604 @@ Index Tag Table: Node: Top1200 -Node: Foreword344559 -Node: Foreword449001 -Node: Preface50533 -Ref: Preface-Footnote-153392 -Ref: Preface-Footnote-253501 -Ref: Preface-Footnote-353735 -Node: History53877 -Node: Names56229 -Ref: Names-Footnote-157333 -Node: This Manual57480 -Ref: This Manual-Footnote-164119 -Node: Conventions64219 -Node: Manual History66588 -Ref: Manual History-Footnote-169585 -Ref: Manual History-Footnote-269626 -Node: How To Contribute69700 -Node: Acknowledgments70626 -Node: Getting Started75563 -Node: Running gawk78002 -Node: One-shot79192 -Node: Read Terminal80455 -Node: Long82448 -Node: Executable Scripts83961 -Ref: Executable Scripts-Footnote-186594 -Node: Comments86697 -Node: Quoting89181 -Node: DOS Quoting94707 -Node: Sample Data Files96763 -Node: Very Simple99358 -Node: Two Rules105460 -Node: More Complex107345 -Node: Statements/Lines109677 -Ref: Statements/Lines-Footnote-1114161 -Node: Other Features114426 -Node: When115362 -Ref: When-Footnote-1117116 -Node: Intro Summary117181 -Node: Invoking Gawk118065 -Node: Command Line119579 -Node: Options120377 -Ref: Options-Footnote-1138291 -Ref: Options-Footnote-2138522 -Node: Other Arguments138547 -Node: Naming Standard Input142558 -Node: Environment Variables143768 -Node: AWKPATH Variable144326 -Ref: AWKPATH Variable-Footnote-1147738 -Ref: AWKPATH Variable-Footnote-2147772 -Node: AWKLIBPATH Variable148143 -Ref: AWKLIBPATH Variable-Footnote-1149840 -Node: Other Environment Variables150215 -Node: Exit Status154036 -Node: Include Files154713 -Node: Loading Shared Libraries158403 -Node: Obsolete159831 -Node: Undocumented160523 -Node: Invoking Summary160820 -Node: Regexp163661 -Node: Regexp Usage165115 -Node: Escape Sequences167152 -Node: Regexp Operators173393 -Node: Regexp Operator Details173878 -Ref: Regexp Operator Details-Footnote-1180310 -Node: Interval Expressions180457 -Ref: Interval Expressions-Footnote-1181878 -Node: Bracket Expressions181976 -Ref: table-char-classes184452 -Node: Leftmost Longest187778 -Node: Computed Regexps189081 -Node: GNU Regexp Operators192508 -Node: Case-sensitivity196245 -Ref: Case-sensitivity-Footnote-1199111 -Ref: Case-sensitivity-Footnote-2199346 -Node: Regexp Summary199454 -Node: Reading Files200920 -Node: Records203189 -Node: awk split records204264 -Node: gawk split records208964 -Ref: gawk split records-Footnote-1214038 -Node: Fields214075 -Node: Nonconstant Fields216816 -Ref: Nonconstant Fields-Footnote-1219052 -Node: Changing Fields219256 -Node: Field Separators225287 -Node: Default Field Splitting227985 -Node: Regexp Field Splitting229103 -Node: Single Character Fields232780 -Node: Command Line Field Separator233840 -Node: Full Line Fields237058 -Ref: Full Line Fields-Footnote-1238580 -Ref: Full Line Fields-Footnote-2238626 -Node: Field Splitting Summary238727 -Node: Constant Size240801 -Node: Fixed width data241533 -Node: Skipping intervening245000 -Node: Allowing trailing data245798 -Node: Fields with fixed data246835 -Node: Splitting By Content248353 -Ref: Splitting By Content-Footnote-1252136 -Node: More CSV252299 -Node: Testing field creation253891 -Node: Multiple Line255516 -Node: Getline261793 -Node: Plain Getline264262 -Node: Getline/Variable266835 -Node: Getline/File267986 -Node: Getline/Variable/File269374 -Ref: Getline/Variable/File-Footnote-1270979 -Node: Getline/Pipe271067 -Node: Getline/Variable/Pipe273771 -Node: Getline/Coprocess274906 -Node: Getline/Variable/Coprocess276173 -Node: Getline Notes276915 -Node: Getline Summary279712 -Ref: table-getline-variants280136 -Node: Read Timeout280884 -Ref: Read Timeout-Footnote-1284790 -Node: Retrying Input284848 -Node: Command-line directories286047 -Node: Input Summary286953 -Node: Input Exercises290125 -Node: Printing290559 -Node: Print292393 -Node: Print Examples293850 -Node: Output Separators296630 -Node: OFMT298647 -Node: Printf300003 -Node: Basic Printf300788 -Node: Control Letters302362 -Node: Format Modifiers307526 -Node: Printf Examples313541 -Node: Redirection316027 -Node: Special FD322868 -Ref: Special FD-Footnote-1326036 -Node: Special Files326110 -Node: Other Inherited Files326727 -Node: Special Network327728 -Node: Special Caveats328588 -Node: Close Files And Pipes329537 -Ref: table-close-pipe-return-values336444 -Ref: Close Files And Pipes-Footnote-1337257 -Ref: Close Files And Pipes-Footnote-2337405 -Node: Nonfatal337557 -Node: Output Summary339895 -Node: Output Exercises341117 -Node: Expressions341796 -Node: Values342984 -Node: Constants343662 -Node: Scalar Constants344353 -Ref: Scalar Constants-Footnote-1346863 -Node: Nondecimal-numbers347113 -Node: Regexp Constants350114 -Node: Using Constant Regexps350640 -Node: Standard Regexp Constants351262 -Node: Strong Regexp Constants354450 -Node: Variables357462 -Node: Using Variables358119 -Node: Assignment Options360029 -Node: Conversion362500 -Node: Strings And Numbers363024 -Ref: Strings And Numbers-Footnote-1366087 -Node: Locale influences conversions366196 -Ref: table-locale-affects368954 -Node: All Operators369572 -Node: Arithmetic Ops370201 -Node: Concatenation372917 -Ref: Concatenation-Footnote-1375764 -Node: Assignment Ops375871 -Ref: table-assign-ops380862 -Node: Increment Ops382175 -Node: Truth Values and Conditions385635 -Node: Truth Values386709 -Node: Typing and Comparison387757 -Node: Variable Typing388577 -Ref: Variable Typing-Footnote-1395040 -Ref: Variable Typing-Footnote-2395112 -Node: Comparison Operators395189 -Ref: table-relational-ops395608 -Node: POSIX String Comparison399103 -Ref: POSIX String Comparison-Footnote-1400798 -Ref: POSIX String Comparison-Footnote-2400937 -Node: Boolean Ops401021 -Ref: Boolean Ops-Footnote-1405503 -Node: Conditional Exp405595 -Node: Function Calls407331 -Node: Precedence411208 -Node: Locales414867 -Node: Expressions Summary416499 -Node: Patterns and Actions419072 -Node: Pattern Overview420192 -Node: Regexp Patterns421869 -Node: Expression Patterns422411 -Node: Ranges426192 -Node: BEGIN/END429300 -Node: Using BEGIN/END430061 -Ref: Using BEGIN/END-Footnote-1432815 -Node: I/O And BEGIN/END432921 -Node: BEGINFILE/ENDFILE435234 -Node: Empty438465 -Node: Using Shell Variables438782 -Node: Action Overview441056 -Node: Statements443381 -Node: If Statement445229 -Node: While Statement446724 -Node: Do Statement448752 -Node: For Statement449900 -Node: Switch Statement453071 -Node: Break Statement455512 -Node: Continue Statement457604 -Node: Next Statement459431 -Node: Nextfile Statement461814 -Node: Exit Statement464503 -Node: Built-in Variables466906 -Node: User-modified468039 -Node: Auto-set475806 -Ref: Auto-set-Footnote-1492613 -Ref: Auto-set-Footnote-2492819 -Node: ARGC and ARGV492875 -Node: Pattern Action Summary497088 -Node: Arrays499518 -Node: Array Basics500847 -Node: Array Intro501691 -Ref: figure-array-elements503666 -Ref: Array Intro-Footnote-1506370 -Node: Reference to Elements506498 -Node: Assigning Elements508962 -Node: Array Example509453 -Node: Scanning an Array511212 -Node: Controlling Scanning514234 -Ref: Controlling Scanning-Footnote-1520690 -Node: Numeric Array Subscripts521006 -Node: Uninitialized Subscripts523190 -Node: Delete524809 -Ref: Delete-Footnote-1527561 -Node: Multidimensional527618 -Node: Multiscanning530713 -Node: Arrays of Arrays532304 -Node: Arrays Summary537072 -Node: Functions539165 -Node: Built-in540203 -Node: Calling Built-in541284 -Node: Numeric Functions543280 -Ref: Numeric Functions-Footnote-1547308 -Ref: Numeric Functions-Footnote-2547956 -Ref: Numeric Functions-Footnote-3548004 -Node: String Functions548276 -Ref: String Functions-Footnote-1572417 -Ref: String Functions-Footnote-2572545 -Ref: String Functions-Footnote-3572793 -Node: Gory Details572880 -Ref: table-sub-escapes574671 -Ref: table-sub-proposed576190 -Ref: table-posix-sub577553 -Ref: table-gensub-escapes579094 -Ref: Gory Details-Footnote-1579917 -Node: I/O Functions580071 -Ref: table-system-return-values586525 -Ref: I/O Functions-Footnote-1588605 -Ref: I/O Functions-Footnote-2588753 -Node: Time Functions588873 -Ref: Time Functions-Footnote-1599544 -Ref: Time Functions-Footnote-2599612 -Ref: Time Functions-Footnote-3599770 -Ref: Time Functions-Footnote-4599881 -Ref: Time Functions-Footnote-5599993 -Ref: Time Functions-Footnote-6600220 -Node: Bitwise Functions600486 -Ref: table-bitwise-ops601080 -Ref: Bitwise Functions-Footnote-1607143 -Ref: Bitwise Functions-Footnote-2607316 -Node: Type Functions607507 -Node: I18N Functions610370 -Node: User-defined612021 -Node: Definition Syntax612833 -Ref: Definition Syntax-Footnote-1618527 -Node: Function Example618598 -Ref: Function Example-Footnote-1621520 -Node: Function Calling621542 -Node: Calling A Function622130 -Node: Variable Scope623088 -Node: Pass By Value/Reference626082 -Node: Function Caveats628726 -Ref: Function Caveats-Footnote-1630773 -Node: Return Statement630893 -Node: Dynamic Typing633872 -Node: Indirect Calls634802 -Ref: Indirect Calls-Footnote-1645054 -Node: Functions Summary645182 -Node: Library Functions647887 -Ref: Library Functions-Footnote-1651494 -Ref: Library Functions-Footnote-2651637 -Node: Library Names651808 -Ref: Library Names-Footnote-1655475 -Ref: Library Names-Footnote-2655698 -Node: General Functions655784 -Node: Strtonum Function656887 -Node: Assert Function659909 -Node: Round Function663235 -Node: Cliff Random Function664775 -Node: Ordinal Functions665791 -Ref: Ordinal Functions-Footnote-1668854 -Ref: Ordinal Functions-Footnote-2669106 -Node: Join Function669316 -Ref: Join Function-Footnote-1671086 -Node: Getlocaltime Function671286 -Node: Readfile Function675028 -Node: Shell Quoting677005 -Node: Data File Management678406 -Node: Filetrans Function679038 -Node: Rewind Function683134 -Node: File Checking685043 -Ref: File Checking-Footnote-1686377 -Node: Empty Files686578 -Node: Ignoring Assigns688557 -Node: Getopt Function690107 -Ref: Getopt Function-Footnote-1705318 -Node: Passwd Functions705518 -Ref: Passwd Functions-Footnote-1714357 -Node: Group Functions714445 -Ref: Group Functions-Footnote-1722343 -Node: Walking Arrays722550 -Node: Library Functions Summary725558 -Node: Library Exercises726964 -Node: Sample Programs727429 -Node: Running Examples728199 -Node: Clones728927 -Node: Cut Program730151 -Node: Egrep Program740291 -Node: Id Program749292 -Node: Split Program759239 -Ref: Split Program-Footnote-1769129 -Node: Tee Program769302 -Node: Uniq Program772092 -Node: Wc Program779680 -Node: Bytes vs. Characters780077 -Node: Using extensions781625 -Node: wc program782379 -Node: Miscellaneous Programs787244 -Node: Dupword Program788457 -Node: Alarm Program790487 -Node: Translate Program795342 -Ref: Translate Program-Footnote-1799907 -Node: Labels Program800177 -Ref: Labels Program-Footnote-1803528 -Node: Word Sorting803612 -Node: History Sorting807684 -Node: Extract Program809909 -Node: Simple Sed817963 -Node: Igawk Program821037 -Ref: Igawk Program-Footnote-1835368 -Ref: Igawk Program-Footnote-2835570 -Ref: Igawk Program-Footnote-3835692 -Node: Anagram Program835807 -Node: Signature Program838869 -Node: Programs Summary840116 -Node: Programs Exercises841330 -Ref: Programs Exercises-Footnote-1845460 -Node: Advanced Features845546 -Node: Nondecimal Data847613 -Node: Array Sorting849204 -Node: Controlling Array Traversal849904 -Ref: Controlling Array Traversal-Footnote-1858272 -Node: Array Sorting Functions858390 -Ref: Array Sorting Functions-Footnote-1863481 -Node: Two-way I/O863677 -Ref: Two-way I/O-Footnote-1871398 -Ref: Two-way I/O-Footnote-2871585 -Node: TCP/IP Networking871667 -Node: Profiling874785 -Node: Extension Philosophy884094 -Node: Advanced Features Summary885573 -Node: Internationalization887588 -Node: I18N and L10N889068 -Node: Explaining gettext889755 -Ref: Explaining gettext-Footnote-1895647 -Ref: Explaining gettext-Footnote-2895832 -Node: Programmer i18n895997 -Ref: Programmer i18n-Footnote-1900946 -Node: Translator i18n900995 -Node: String Extraction901789 -Ref: String Extraction-Footnote-1902921 -Node: Printf Ordering903007 -Ref: Printf Ordering-Footnote-1905793 -Node: I18N Portability905857 -Ref: I18N Portability-Footnote-1908313 -Node: I18N Example908376 -Ref: I18N Example-Footnote-1911651 -Ref: I18N Example-Footnote-2911724 -Node: Gawk I18N911833 -Node: I18N Summary912482 -Node: Debugger913823 -Node: Debugging914823 -Node: Debugging Concepts915264 -Node: Debugging Terms917073 -Node: Awk Debugging919648 -Ref: Awk Debugging-Footnote-1920593 -Node: Sample Debugging Session920725 -Node: Debugger Invocation921259 -Node: Finding The Bug922645 -Node: List of Debugger Commands929119 -Node: Breakpoint Control930452 -Node: Debugger Execution Control934146 -Node: Viewing And Changing Data937508 -Node: Execution Stack941049 -Node: Debugger Info942686 -Node: Miscellaneous Debugger Commands946757 -Node: Readline Support951819 -Node: Limitations952715 -Node: Debugging Summary955269 -Node: Namespaces956548 -Node: Global Namespace957659 -Node: Qualified Names959057 -Node: Default Namespace960056 -Node: Changing The Namespace960797 -Node: Naming Rules962411 -Node: Internal Name Management964259 -Node: Namespace Example965301 -Node: Namespace And Features967863 -Node: Namespace Summary969298 -Node: Arbitrary Precision Arithmetic970775 -Node: Computer Arithmetic972262 -Ref: table-numeric-ranges976028 -Ref: table-floating-point-ranges976521 -Ref: Computer Arithmetic-Footnote-1977179 -Node: Math Definitions977236 -Ref: table-ieee-formats980552 -Ref: Math Definitions-Footnote-1981155 -Node: MPFR features981260 -Node: FP Math Caution982978 -Ref: FP Math Caution-Footnote-1984050 -Node: Inexactness of computations984419 -Node: Inexact representation985379 -Node: Comparing FP Values986739 -Node: Errors accumulate987980 -Node: Getting Accuracy989413 -Node: Try To Round992123 -Node: Setting precision993022 -Ref: table-predefined-precision-strings993719 -Node: Setting the rounding mode995549 -Ref: table-gawk-rounding-modes995923 -Ref: Setting the rounding mode-Footnote-1999854 -Node: Arbitrary Precision Integers1000033 -Ref: Arbitrary Precision Integers-Footnote-11003208 -Node: Checking for MPFR1003357 -Node: POSIX Floating Point Problems1004831 -Ref: POSIX Floating Point Problems-Footnote-11009116 -Node: Floating point summary1009154 -Node: Dynamic Extensions1011344 -Node: Extension Intro1012897 -Node: Plugin License1014163 -Node: Extension Mechanism Outline1014960 -Ref: figure-load-extension1015399 -Ref: figure-register-new-function1016964 -Ref: figure-call-new-function1018056 -Node: Extension API Description1020118 -Node: Extension API Functions Introduction1021831 -Ref: table-api-std-headers1023667 -Node: General Data Types1027916 -Ref: General Data Types-Footnote-11036546 -Node: Memory Allocation Functions1036845 -Ref: Memory Allocation Functions-Footnote-11041346 -Node: Constructor Functions1041445 -Node: API Ownership of MPFR and GMP Values1044911 -Node: Registration Functions1046224 -Node: Extension Functions1046924 -Node: Exit Callback Functions1052246 -Node: Extension Version String1053496 -Node: Input Parsers1054159 -Node: Output Wrappers1066880 -Node: Two-way processors1071392 -Node: Printing Messages1073657 -Ref: Printing Messages-Footnote-11074828 -Node: Updating ERRNO1074981 -Node: Requesting Values1075720 -Ref: table-value-types-returned1076457 -Node: Accessing Parameters1077393 -Node: Symbol Table Access1078630 -Node: Symbol table by name1079142 -Ref: Symbol table by name-Footnote-11082166 -Node: Symbol table by cookie1082294 -Ref: Symbol table by cookie-Footnote-11086479 -Node: Cached values1086543 -Ref: Cached values-Footnote-11090079 -Node: Array Manipulation1090232 -Ref: Array Manipulation-Footnote-11091323 -Node: Array Data Types1091360 -Ref: Array Data Types-Footnote-11094018 -Node: Array Functions1094110 -Node: Flattening Arrays1098608 -Node: Creating Arrays1105584 -Node: Redirection API1110351 -Node: Extension API Variables1113184 -Node: Extension Versioning1113895 -Ref: gawk-api-version1114324 -Node: Extension GMP/MPFR Versioning1116055 -Node: Extension API Informational Variables1117683 -Node: Extension API Boilerplate1118756 -Node: Changes from API V11122730 -Node: Finding Extensions1124302 -Node: Extension Example1124861 -Node: Internal File Description1125659 -Node: Internal File Ops1129739 -Ref: Internal File Ops-Footnote-11141089 -Node: Using Internal File Ops1141229 -Ref: Using Internal File Ops-Footnote-11143612 -Node: Extension Samples1143886 -Node: Extension Sample File Functions1145415 -Node: Extension Sample Fnmatch1153064 -Node: Extension Sample Fork1154551 -Node: Extension Sample Inplace1155769 -Node: Extension Sample Ord1159395 -Node: Extension Sample Readdir1160231 -Ref: table-readdir-file-types1161120 -Node: Extension Sample Revout1162187 -Node: Extension Sample Rev2way1162776 -Node: Extension Sample Read write array1163516 -Node: Extension Sample Readfile1165458 -Node: Extension Sample Time1166553 -Node: Extension Sample API Tests1168305 -Node: gawkextlib1168797 -Node: Extension summary1171715 -Node: Extension Exercises1175417 -Node: Language History1176659 -Node: V7/SVR3.11178315 -Node: SVR41180467 -Node: POSIX1181901 -Node: BTL1183282 -Node: POSIX/GNU1184011 -Node: Feature History1189789 -Node: Common Extensions1206108 -Node: Ranges and Locales1207391 -Ref: Ranges and Locales-Footnote-11212007 -Ref: Ranges and Locales-Footnote-21212034 -Ref: Ranges and Locales-Footnote-31212269 -Node: Contributors1212492 -Node: History summary1218489 -Node: Installation1219869 -Node: Gawk Distribution1220813 -Node: Getting1221297 -Node: Extracting1222260 -Node: Distribution contents1223898 -Node: Unix Installation1230378 -Node: Quick Installation1231060 -Node: Shell Startup Files1233474 -Node: Additional Configuration Options1234563 -Node: Configuration Philosophy1236878 -Node: Non-Unix Installation1239247 -Node: PC Installation1239707 -Node: PC Binary Installation1240545 -Node: PC Compiling1240980 -Node: PC Using1242097 -Node: Cygwin1245650 -Node: MSYS1246874 -Node: VMS Installation1247476 -Node: VMS Compilation1248267 -Ref: VMS Compilation-Footnote-11249496 -Node: VMS Dynamic Extensions1249554 -Node: VMS Installation Details1251239 -Node: VMS Running1253492 -Node: VMS GNV1257771 -Node: VMS Old Gawk1258506 -Node: Bugs1258977 -Node: Bug address1259640 -Node: Usenet1262622 -Node: Maintainers1263626 -Node: Other Versions1264811 -Node: Installation summary1272676 -Node: Notes1273885 -Node: Compatibility Mode1274679 -Node: Additions1275461 -Node: Accessing The Source1276386 -Node: Adding Code1277823 -Node: New Ports1284042 -Node: Derived Files1288417 -Ref: Derived Files-Footnote-11294077 -Ref: Derived Files-Footnote-21294112 -Ref: Derived Files-Footnote-31294710 -Node: Future Extensions1294824 -Node: Implementation Limitations1295482 -Node: Extension Design1296692 -Node: Old Extension Problems1297836 -Ref: Old Extension Problems-Footnote-11299354 -Node: Extension New Mechanism Goals1299411 -Ref: Extension New Mechanism Goals-Footnote-11302775 -Node: Extension Other Design Decisions1302964 -Node: Extension Future Growth1305077 -Node: Notes summary1305683 -Node: Basic Concepts1306841 -Node: Basic High Level1307522 -Ref: figure-general-flow1307804 -Ref: figure-process-flow1308489 -Ref: Basic High Level-Footnote-11311790 -Node: Basic Data Typing1311975 -Node: Glossary1315303 -Node: Copying1347188 -Node: GNU Free Documentation License1384731 -Node: Index1409851 +Node: Foreword344638 +Node: Foreword449080 +Node: Preface50612 +Ref: Preface-Footnote-153471 +Ref: Preface-Footnote-253580 +Ref: Preface-Footnote-353814 +Node: History53956 +Node: Names56308 +Ref: Names-Footnote-157412 +Node: This Manual57559 +Ref: This Manual-Footnote-164198 +Node: Conventions64298 +Node: Manual History66667 +Ref: Manual History-Footnote-169664 +Ref: Manual History-Footnote-269705 +Node: How To Contribute69779 +Node: Acknowledgments70705 +Node: Getting Started75642 +Node: Running gawk78081 +Node: One-shot79271 +Node: Read Terminal80534 +Node: Long82527 +Node: Executable Scripts84040 +Ref: Executable Scripts-Footnote-186673 +Node: Comments86776 +Node: Quoting89260 +Node: DOS Quoting94786 +Node: Sample Data Files96842 +Node: Very Simple99437 +Node: Two Rules105539 +Node: More Complex107424 +Node: Statements/Lines109756 +Ref: Statements/Lines-Footnote-1114240 +Node: Other Features114505 +Node: When115441 +Ref: When-Footnote-1117195 +Node: Intro Summary117260 +Node: Invoking Gawk118144 +Node: Command Line119658 +Node: Options120456 +Ref: Options-Footnote-1138370 +Ref: Options-Footnote-2138601 +Node: Other Arguments138626 +Node: Naming Standard Input142637 +Node: Environment Variables143847 +Node: AWKPATH Variable144405 +Ref: AWKPATH Variable-Footnote-1147817 +Ref: AWKPATH Variable-Footnote-2147851 +Node: AWKLIBPATH Variable148222 +Ref: AWKLIBPATH Variable-Footnote-1149919 +Node: Other Environment Variables150294 +Node: Exit Status154115 +Node: Include Files154792 +Node: Loading Shared Libraries158482 +Node: Obsolete159910 +Node: Undocumented160602 +Node: Invoking Summary160899 +Node: Regexp163740 +Node: Regexp Usage165194 +Node: Escape Sequences167231 +Node: Regexp Operators173472 +Node: Regexp Operator Details173957 +Ref: Regexp Operator Details-Footnote-1180389 +Node: Interval Expressions180536 +Ref: Interval Expressions-Footnote-1181957 +Node: Bracket Expressions182055 +Ref: table-char-classes184531 +Node: Leftmost Longest187857 +Node: Computed Regexps189160 +Node: GNU Regexp Operators192587 +Node: Case-sensitivity196324 +Ref: Case-sensitivity-Footnote-1199190 +Ref: Case-sensitivity-Footnote-2199425 +Node: Regexp Summary199533 +Node: Reading Files200999 +Node: Records203268 +Node: awk split records204343 +Node: gawk split records209043 +Ref: gawk split records-Footnote-1214117 +Node: Fields214154 +Node: Nonconstant Fields216895 +Ref: Nonconstant Fields-Footnote-1219131 +Node: Changing Fields219335 +Node: Field Separators225366 +Node: Default Field Splitting228064 +Node: Regexp Field Splitting229182 +Node: Single Character Fields232859 +Node: Command Line Field Separator233919 +Node: Full Line Fields237137 +Ref: Full Line Fields-Footnote-1238659 +Ref: Full Line Fields-Footnote-2238705 +Node: Field Splitting Summary238806 +Node: Constant Size240880 +Node: Fixed width data241612 +Node: Skipping intervening245079 +Node: Allowing trailing data245877 +Node: Fields with fixed data246914 +Node: Splitting By Content248432 +Ref: Splitting By Content-Footnote-1252215 +Node: More CSV252378 +Node: Testing field creation253970 +Node: Multiple Line255595 +Node: Getline261872 +Node: Plain Getline264341 +Node: Getline/Variable266914 +Node: Getline/File268065 +Node: Getline/Variable/File269453 +Ref: Getline/Variable/File-Footnote-1271058 +Node: Getline/Pipe271146 +Node: Getline/Variable/Pipe273850 +Node: Getline/Coprocess274985 +Node: Getline/Variable/Coprocess276252 +Node: Getline Notes276994 +Node: Getline Summary279791 +Ref: table-getline-variants280215 +Node: Read Timeout280963 +Ref: Read Timeout-Footnote-1284869 +Node: Retrying Input284927 +Node: Command-line directories286126 +Node: Input Summary287032 +Node: Input Exercises290204 +Node: Printing290638 +Node: Print292472 +Node: Print Examples293929 +Node: Output Separators296709 +Node: OFMT298726 +Node: Printf300082 +Node: Basic Printf300867 +Node: Control Letters302441 +Node: Format Modifiers307603 +Node: Printf Examples313618 +Node: Redirection316104 +Node: Special FD322945 +Ref: Special FD-Footnote-1326113 +Node: Special Files326187 +Node: Other Inherited Files326804 +Node: Special Network327805 +Node: Special Caveats328665 +Node: Close Files And Pipes329614 +Ref: table-close-pipe-return-values336521 +Ref: Close Files And Pipes-Footnote-1337334 +Ref: Close Files And Pipes-Footnote-2337482 +Node: Nonfatal337634 +Node: Output Summary339972 +Node: Output Exercises341194 +Node: Expressions341873 +Node: Values343061 +Node: Constants343739 +Node: Scalar Constants344430 +Ref: Scalar Constants-Footnote-1346940 +Node: Nondecimal-numbers347190 +Node: Regexp Constants350191 +Node: Using Constant Regexps350717 +Node: Standard Regexp Constants351339 +Node: Strong Regexp Constants354527 +Node: Variables357539 +Node: Using Variables358196 +Node: Assignment Options360106 +Node: Conversion362577 +Node: Strings And Numbers363101 +Ref: Strings And Numbers-Footnote-1366164 +Node: Locale influences conversions366273 +Ref: table-locale-affects369031 +Node: All Operators369649 +Node: Arithmetic Ops370278 +Node: Concatenation372994 +Ref: Concatenation-Footnote-1375841 +Node: Assignment Ops375948 +Ref: table-assign-ops380939 +Node: Increment Ops382252 +Node: Truth Values and Conditions385712 +Node: Truth Values386786 +Node: Typing and Comparison387834 +Node: Variable Typing388654 +Ref: Variable Typing-Footnote-1395117 +Ref: Variable Typing-Footnote-2395189 +Node: Comparison Operators395266 +Ref: table-relational-ops395685 +Node: POSIX String Comparison399180 +Ref: POSIX String Comparison-Footnote-1400875 +Ref: POSIX String Comparison-Footnote-2401014 +Node: Boolean Ops401098 +Ref: Boolean Ops-Footnote-1405580 +Node: Conditional Exp405672 +Node: Function Calls407408 +Node: Precedence411285 +Node: Locales414944 +Node: Expressions Summary416576 +Node: Patterns and Actions419149 +Node: Pattern Overview420269 +Node: Regexp Patterns421946 +Node: Expression Patterns422488 +Node: Ranges426269 +Node: BEGIN/END429377 +Node: Using BEGIN/END430138 +Ref: Using BEGIN/END-Footnote-1432892 +Node: I/O And BEGIN/END432998 +Node: BEGINFILE/ENDFILE435311 +Node: Empty438542 +Node: Using Shell Variables438859 +Node: Action Overview441133 +Node: Statements443458 +Node: If Statement445306 +Node: While Statement446801 +Node: Do Statement448829 +Node: For Statement449977 +Node: Switch Statement453148 +Node: Break Statement455589 +Node: Continue Statement457681 +Node: Next Statement459508 +Node: Nextfile Statement461891 +Node: Exit Statement464580 +Node: Built-in Variables466983 +Node: User-modified468116 +Node: Auto-set475883 +Ref: Auto-set-Footnote-1492690 +Ref: Auto-set-Footnote-2492896 +Node: ARGC and ARGV492952 +Node: Pattern Action Summary497165 +Node: Arrays499595 +Node: Array Basics500924 +Node: Array Intro501768 +Ref: figure-array-elements503743 +Ref: Array Intro-Footnote-1506447 +Node: Reference to Elements506575 +Node: Assigning Elements509039 +Node: Array Example509530 +Node: Scanning an Array511289 +Node: Controlling Scanning514311 +Ref: Controlling Scanning-Footnote-1520767 +Node: Numeric Array Subscripts521083 +Node: Uninitialized Subscripts523267 +Node: Delete524886 +Ref: Delete-Footnote-1527638 +Node: Multidimensional527695 +Node: Multiscanning530790 +Node: Arrays of Arrays532381 +Node: Arrays Summary537149 +Node: Functions539242 +Node: Built-in540280 +Node: Calling Built-in541361 +Node: Numeric Functions543357 +Ref: Numeric Functions-Footnote-1547383 +Ref: Numeric Functions-Footnote-2548031 +Ref: Numeric Functions-Footnote-3548079 +Node: String Functions548351 +Ref: String Functions-Footnote-1572492 +Ref: String Functions-Footnote-2572620 +Ref: String Functions-Footnote-3572868 +Node: Gory Details572955 +Ref: table-sub-escapes574746 +Ref: table-sub-proposed576265 +Ref: table-posix-sub577628 +Ref: table-gensub-escapes579169 +Ref: Gory Details-Footnote-1579992 +Node: I/O Functions580146 +Ref: table-system-return-values586600 +Ref: I/O Functions-Footnote-1588680 +Ref: I/O Functions-Footnote-2588828 +Node: Time Functions588948 +Ref: Time Functions-Footnote-1599619 +Ref: Time Functions-Footnote-2599687 +Ref: Time Functions-Footnote-3599845 +Ref: Time Functions-Footnote-4599956 +Ref: Time Functions-Footnote-5600068 +Ref: Time Functions-Footnote-6600295 +Node: Bitwise Functions600561 +Ref: table-bitwise-ops601155 +Ref: Bitwise Functions-Footnote-1607218 +Ref: Bitwise Functions-Footnote-2607391 +Node: Type Functions607582 +Node: I18N Functions610445 +Node: User-defined612096 +Node: Definition Syntax612908 +Ref: Definition Syntax-Footnote-1618602 +Node: Function Example618673 +Ref: Function Example-Footnote-1621595 +Node: Function Calling621617 +Node: Calling A Function622205 +Node: Variable Scope623163 +Node: Pass By Value/Reference626157 +Node: Function Caveats628801 +Ref: Function Caveats-Footnote-1630848 +Node: Return Statement630968 +Node: Dynamic Typing633947 +Node: Indirect Calls634877 +Ref: Indirect Calls-Footnote-1645129 +Node: Functions Summary645257 +Node: Library Functions647962 +Ref: Library Functions-Footnote-1651569 +Ref: Library Functions-Footnote-2651712 +Node: Library Names651883 +Ref: Library Names-Footnote-1655550 +Ref: Library Names-Footnote-2655773 +Node: General Functions655859 +Node: Strtonum Function656962 +Node: Assert Function659984 +Node: Round Function663310 +Node: Cliff Random Function664850 +Node: Ordinal Functions665866 +Ref: Ordinal Functions-Footnote-1668929 +Ref: Ordinal Functions-Footnote-2669181 +Node: Join Function669391 +Ref: Join Function-Footnote-1671161 +Node: Getlocaltime Function671361 +Node: Readfile Function675103 +Node: Shell Quoting677080 +Node: Data File Management678481 +Node: Filetrans Function679113 +Node: Rewind Function683209 +Node: File Checking685118 +Ref: File Checking-Footnote-1686452 +Node: Empty Files686653 +Node: Ignoring Assigns688632 +Node: Getopt Function690182 +Ref: Getopt Function-Footnote-1705393 +Node: Passwd Functions705593 +Ref: Passwd Functions-Footnote-1714432 +Node: Group Functions714520 +Ref: Group Functions-Footnote-1722418 +Node: Walking Arrays722625 +Node: Library Functions Summary725633 +Node: Library Exercises727039 +Node: Sample Programs727504 +Node: Running Examples728274 +Node: Clones729002 +Node: Cut Program730226 +Node: Egrep Program740366 +Node: Id Program749367 +Node: Split Program759314 +Ref: Split Program-Footnote-1769204 +Node: Tee Program769377 +Node: Uniq Program772167 +Node: Wc Program779755 +Node: Bytes vs. Characters780152 +Node: Using extensions781700 +Node: wc program782454 +Node: Miscellaneous Programs787319 +Node: Dupword Program788532 +Node: Alarm Program790562 +Node: Translate Program795417 +Ref: Translate Program-Footnote-1799982 +Node: Labels Program800252 +Ref: Labels Program-Footnote-1803603 +Node: Word Sorting803687 +Node: History Sorting807759 +Node: Extract Program809984 +Node: Simple Sed818038 +Node: Igawk Program821112 +Ref: Igawk Program-Footnote-1835443 +Ref: Igawk Program-Footnote-2835645 +Ref: Igawk Program-Footnote-3835767 +Node: Anagram Program835882 +Node: Signature Program838944 +Node: Programs Summary840191 +Node: Programs Exercises841405 +Ref: Programs Exercises-Footnote-1845535 +Node: Advanced Features845621 +Node: Nondecimal Data847688 +Node: Array Sorting849279 +Node: Controlling Array Traversal849979 +Ref: Controlling Array Traversal-Footnote-1858347 +Node: Array Sorting Functions858465 +Ref: Array Sorting Functions-Footnote-1863556 +Node: Two-way I/O863752 +Ref: Two-way I/O-Footnote-1871473 +Ref: Two-way I/O-Footnote-2871660 +Node: TCP/IP Networking871742 +Node: Profiling874860 +Node: Extension Philosophy884169 +Node: Advanced Features Summary885648 +Node: Internationalization887663 +Node: I18N and L10N889143 +Node: Explaining gettext889830 +Ref: Explaining gettext-Footnote-1895722 +Ref: Explaining gettext-Footnote-2895907 +Node: Programmer i18n896072 +Ref: Programmer i18n-Footnote-1901021 +Node: Translator i18n901070 +Node: String Extraction901864 +Ref: String Extraction-Footnote-1902996 +Node: Printf Ordering903082 +Ref: Printf Ordering-Footnote-1905868 +Node: I18N Portability905932 +Ref: I18N Portability-Footnote-1908388 +Node: I18N Example908451 +Ref: I18N Example-Footnote-1911726 +Ref: I18N Example-Footnote-2911799 +Node: Gawk I18N911908 +Node: I18N Summary912557 +Node: Debugger913898 +Node: Debugging914898 +Node: Debugging Concepts915339 +Node: Debugging Terms917148 +Node: Awk Debugging919723 +Ref: Awk Debugging-Footnote-1920668 +Node: Sample Debugging Session920800 +Node: Debugger Invocation921334 +Node: Finding The Bug922720 +Node: List of Debugger Commands929194 +Node: Breakpoint Control930527 +Node: Debugger Execution Control934221 +Node: Viewing And Changing Data937583 +Node: Execution Stack941124 +Node: Debugger Info942761 +Node: Miscellaneous Debugger Commands946832 +Node: Readline Support951894 +Node: Limitations952790 +Node: Debugging Summary955344 +Node: Namespaces956623 +Node: Global Namespace957734 +Node: Qualified Names959132 +Node: Default Namespace960131 +Node: Changing The Namespace960872 +Node: Naming Rules962486 +Node: Internal Name Management964334 +Node: Namespace Example965376 +Node: Namespace And Features967938 +Node: Namespace Summary969373 +Node: Arbitrary Precision Arithmetic970850 +Node: Computer Arithmetic972337 +Ref: table-numeric-ranges976103 +Ref: table-floating-point-ranges976596 +Ref: Computer Arithmetic-Footnote-1977254 +Node: Math Definitions977311 +Ref: table-ieee-formats980287 +Node: MPFR features980854 +Node: FP Math Caution982572 +Ref: FP Math Caution-Footnote-1983644 +Node: Inexactness of computations984013 +Node: Inexact representation985044 +Node: Comparing FP Values986404 +Node: Errors accumulate987645 +Node: Strange values989101 +Ref: Strange values-Footnote-1991689 +Node: Getting Accuracy991794 +Node: Try To Round994504 +Node: Setting precision995403 +Ref: table-predefined-precision-strings996100 +Node: Setting the rounding mode997930 +Ref: table-gawk-rounding-modes998304 +Ref: Setting the rounding mode-Footnote-11002235 +Node: Arbitrary Precision Integers1002414 +Ref: Arbitrary Precision Integers-Footnote-11005589 +Node: Checking for MPFR1005738 +Node: POSIX Floating Point Problems1007212 +Ref: POSIX Floating Point Problems-Footnote-11011497 +Node: Floating point summary1011535 +Node: Dynamic Extensions1013725 +Node: Extension Intro1015278 +Node: Plugin License1016544 +Node: Extension Mechanism Outline1017341 +Ref: figure-load-extension1017780 +Ref: figure-register-new-function1019345 +Ref: figure-call-new-function1020437 +Node: Extension API Description1022499 +Node: Extension API Functions Introduction1024212 +Ref: table-api-std-headers1026048 +Node: General Data Types1030297 +Ref: General Data Types-Footnote-11038927 +Node: Memory Allocation Functions1039226 +Ref: Memory Allocation Functions-Footnote-11043727 +Node: Constructor Functions1043826 +Node: API Ownership of MPFR and GMP Values1047292 +Node: Registration Functions1048605 +Node: Extension Functions1049305 +Node: Exit Callback Functions1054627 +Node: Extension Version String1055877 +Node: Input Parsers1056540 +Node: Output Wrappers1069261 +Node: Two-way processors1073773 +Node: Printing Messages1076038 +Ref: Printing Messages-Footnote-11077209 +Node: Updating ERRNO1077362 +Node: Requesting Values1078101 +Ref: table-value-types-returned1078838 +Node: Accessing Parameters1079774 +Node: Symbol Table Access1081011 +Node: Symbol table by name1081523 +Ref: Symbol table by name-Footnote-11084547 +Node: Symbol table by cookie1084675 +Ref: Symbol table by cookie-Footnote-11088860 +Node: Cached values1088924 +Ref: Cached values-Footnote-11092460 +Node: Array Manipulation1092613 +Ref: Array Manipulation-Footnote-11093704 +Node: Array Data Types1093741 +Ref: Array Data Types-Footnote-11096399 +Node: Array Functions1096491 +Node: Flattening Arrays1100989 +Node: Creating Arrays1107965 +Node: Redirection API1112732 +Node: Extension API Variables1115565 +Node: Extension Versioning1116276 +Ref: gawk-api-version1116705 +Node: Extension GMP/MPFR Versioning1118436 +Node: Extension API Informational Variables1120064 +Node: Extension API Boilerplate1121137 +Node: Changes from API V11125111 +Node: Finding Extensions1126683 +Node: Extension Example1127242 +Node: Internal File Description1128040 +Node: Internal File Ops1132120 +Ref: Internal File Ops-Footnote-11143470 +Node: Using Internal File Ops1143610 +Ref: Using Internal File Ops-Footnote-11145993 +Node: Extension Samples1146267 +Node: Extension Sample File Functions1147796 +Node: Extension Sample Fnmatch1155445 +Node: Extension Sample Fork1156932 +Node: Extension Sample Inplace1158150 +Node: Extension Sample Ord1161776 +Node: Extension Sample Readdir1162612 +Ref: table-readdir-file-types1163501 +Node: Extension Sample Revout1164568 +Node: Extension Sample Rev2way1165157 +Node: Extension Sample Read write array1165897 +Node: Extension Sample Readfile1167839 +Node: Extension Sample Time1168934 +Node: Extension Sample API Tests1170686 +Node: gawkextlib1171178 +Node: Extension summary1174096 +Node: Extension Exercises1177798 +Node: Language History1179040 +Node: V7/SVR3.11180696 +Node: SVR41182848 +Node: POSIX1184282 +Node: BTL1185663 +Node: POSIX/GNU1186392 +Node: Feature History1192170 +Node: Common Extensions1208489 +Node: Ranges and Locales1209772 +Ref: Ranges and Locales-Footnote-11214388 +Ref: Ranges and Locales-Footnote-21214415 +Ref: Ranges and Locales-Footnote-31214650 +Node: Contributors1214873 +Node: History summary1220870 +Node: Installation1222250 +Node: Gawk Distribution1223194 +Node: Getting1223678 +Node: Extracting1224641 +Node: Distribution contents1226279 +Node: Unix Installation1232759 +Node: Quick Installation1233441 +Node: Shell Startup Files1235855 +Node: Additional Configuration Options1236944 +Node: Configuration Philosophy1239259 +Node: Non-Unix Installation1241628 +Node: PC Installation1242088 +Node: PC Binary Installation1242926 +Node: PC Compiling1243361 +Node: PC Using1244478 +Node: Cygwin1248031 +Node: MSYS1249255 +Node: VMS Installation1249857 +Node: VMS Compilation1250648 +Ref: VMS Compilation-Footnote-11251877 +Node: VMS Dynamic Extensions1251935 +Node: VMS Installation Details1253620 +Node: VMS Running1255873 +Node: VMS GNV1260152 +Node: VMS Old Gawk1260887 +Node: Bugs1261358 +Node: Bug address1262021 +Node: Usenet1265003 +Node: Maintainers1266007 +Node: Other Versions1267192 +Node: Installation summary1275057 +Node: Notes1276266 +Node: Compatibility Mode1277060 +Node: Additions1277842 +Node: Accessing The Source1278767 +Node: Adding Code1280204 +Node: New Ports1286423 +Node: Derived Files1290798 +Ref: Derived Files-Footnote-11296458 +Ref: Derived Files-Footnote-21296493 +Ref: Derived Files-Footnote-31297091 +Node: Future Extensions1297205 +Node: Implementation Limitations1297863 +Node: Extension Design1299073 +Node: Old Extension Problems1300217 +Ref: Old Extension Problems-Footnote-11301735 +Node: Extension New Mechanism Goals1301792 +Ref: Extension New Mechanism Goals-Footnote-11305156 +Node: Extension Other Design Decisions1305345 +Node: Extension Future Growth1307458 +Node: Notes summary1308064 +Node: Basic Concepts1309222 +Node: Basic High Level1309903 +Ref: figure-general-flow1310185 +Ref: figure-process-flow1310870 +Ref: Basic High Level-Footnote-11314171 +Node: Basic Data Typing1314356 +Node: Glossary1317684 +Node: Copying1349569 +Node: GNU Free Documentation License1387112 +Node: Index1412232 End Tag Table diff --git a/doc/gawk.texi b/doc/gawk.texi index c208ecac..82c06b52 100644 --- a/doc/gawk.texi +++ b/doc/gawk.texi @@ -920,6 +920,7 @@ particular records in a file and perform operations upon them. * Inexact representation:: Numbers are not exactly represented. * Comparing FP Values:: How to compare floating point values. * Errors accumulate:: Errors get bigger as they go. +* Strange values:: A few words about infinities and NaNs. * Getting Accuracy:: Getting more accuracy takes some work. * Try To Round:: Add digits and round. * Setting precision:: How to set the precision. @@ -3136,11 +3137,12 @@ column means that the person is a friend. An @samp{R} means that the person is a relative: @example -@c system if test ! -d eg ; then mkdir eg ; fi -@c system if test ! -d eg/lib ; then mkdir eg/lib ; fi -@c system if test ! -d eg/data ; then mkdir eg/data ; fi -@c system if test ! -d eg/prog ; then mkdir eg/prog ; fi -@c system if test ! -d eg/misc ; then mkdir eg/misc ; fi +@c system if test ! -d eg ; then mkdir eg ; fi +@c system if test ! -d eg/lib ; then mkdir eg/lib ; fi +@c system if test ! -d eg/data ; then mkdir eg/data ; fi +@c system if test ! -d eg/prog ; then mkdir eg/prog ; fi +@c system if test ! -d eg/misc ; then mkdir eg/misc ; fi +@c system if test ! -d eg/test-programs ; then mkdir eg/test-programs ; fi @c file eg/data/mail-list Amelia 555-5553 amelia.zodiacusque@@gmail.com F Anthony 555-3412 anthony.asserturo@@hotmail.com A @@ -10101,7 +10103,7 @@ infinity are formatted as and positive infinity as @samp{inf} or @samp{infinity}. The special ``not a number'' value formats as @samp{-nan} or @samp{nan} -(@pxref{Math Definitions}). +(@pxref{Strange values}). @item @code{%F} Like @samp{%f}, but the infinity and ``not a number'' values are spelled @@ -18337,7 +18339,7 @@ compatibility mode (@pxref{Options}). @cindexawkfunc{log} @cindex logarithm Return the natural logarithm of @var{x}, if @var{x} is positive; -otherwise, return @code{NaN} (``not a number'') on IEEE 754 systems. +otherwise, return NaN (``not a number'') on IEEE 754 systems. Additionally, @command{gawk} prints a warning message when @code{x} is negative. @@ -33683,21 +33685,9 @@ A special value representing infinity. Operations involving another number and infinity produce infinity. @item NaN -``Not a number.''@footnote{Thanks to Michael Brennan for this description, -which we have paraphrased, and for the examples.} A special value that -results from attempting a calculation that has no answer as a real number. -In such a case, programs can either receive a floating-point exception, -or get @code{NaN} back as the result. The IEEE 754 standard recommends -that systems return @code{NaN}. Some examples: - -@table @code -@item sqrt(-1) -This makes sense in the range of complex numbers, but not in the -range of real numbers, so the result is @code{NaN}. - -@item log(-8) -@minus{}8 is out of the domain of @code{log()}, so the result is @code{NaN}. -@end table +``Not a number.'' A special value that results from attempting a +calculation that has no answer as a real number. @xref{Strange values}, +for more information about infinity and not-a-number values. @item Normalized How the significand (see later in this list) is usually stored. The @@ -33866,6 +33856,7 @@ decimal places in the final result. * Inexact representation:: Numbers are not exactly represented. * Comparing FP Values:: How to compare floating point values. * Errors accumulate:: Errors get bigger as they go. +* Strange values:: A few words about infinities and NaNs. @end menu @node Inexact representation @@ -33987,6 +33978,242 @@ $ @kbd{gawk 'BEGIN @{} @print{} 4 @end example +@node Strange values +@subsubsection Floating Point Values They Didn't Talk About In School + +Both IEEE 754 floating-point hardware, and MPFR, support two kinds of +values that you probably didn't learn about in school. The first is +@dfn{infinity}, a special value, that can be either negative or positive, +and which is either smaller than any other value (negative infinity), +or larger than any other value (positive infinity). When such values +are generated, @command{gawk} prints them as either @samp{-inf} or +@samp{+inf}, respectively. It accepts those strings as data input and +converts them to the proper floating-point values internally. + +Infinity values of the same sign compare as equal to each other. +Otherwise, operations (addition, subtraction, etc.) involving another +number and infinity produce mathematically reasonable results. + +The second kind of value is ``not a number'', or NaN for +short.@footnote{Thanks to Michael Brennan for this description, which we +have paraphrased, and for the examples.} This is a special value that results +from attempting a calculation that has no answer as a real number. +In such a case, programs can either receive a floating-point exception, +or get NaN back as the result. The IEEE 754 standard recommends +that systems return NaN. Some examples: + +@table @code +@item sqrt(-1) +@iftex +The @math{\sqrt{-1}} +@end iftex +@ifnottex +This +@end ifnottex +makes sense in the range of complex numbers, but not in the +range of real numbers, so the result is NaN. + +@item log(-8) +@minus{}8 is out of the domain of @code{log()}, so the result is NaN. +@end table + +NaN values are strange. In particular, they cannot be compared with other +floating point values; any such comparison, except for ``is not equal +to'', returns false. NaN values are so much unequal to other values that +even comparing two identical NaN values with @code{!=} returns true! + +NaN values can also be signed, although it depends upon the implementation +as to which sign you get for any operation that returns a NaN. For +example, on some systems, @code{sqrt(-1)} returns a negative NaN. On +others, it returns a positive NaN. + +When such values are generated, @command{gawk} prints them as either +@samp{-nan} or @samp{+nan}, respectively. Here too, @command{gawk} +accepts those strings as data input and converts them to the proper +floating-point values internally. + +If you want to dive more deeply into this topic, you can find +test programs in C, @command{awk} and Python in the directory +@file{awklib/eg/test-programs} in the @command{gawk} distribution. +These programs enable comparison among programming languages as to how +they handle NaN and infinity values. + +@ignore +@c file eg/test-programs/gen-float-table.awk +function eq(left, right) +@{ + return left == right +@} + +function ne(left, right) +@{ + return left != right +@} + +function lt(left, right) +@{ + return left < right +@} + +function le(left, right) +@{ + return left <= right +@} + +function gt(left, right) +@{ + return left > right +@} + +function ge(left, right) +@{ + return left >= right +@} + +BEGIN @{ + nan = sqrt(-1) + inf = -log(0) + split("== != < <= > >=", names) + names[3] = names[3] " " + names[5] = names[5] " " + split("eq ne lt le gt ge", funcs) + + compare[1] = 2.0 + compare[2] = values[1] = -sqrt(-1.0) # nan + compare[3] = values[2] = sqrt(-1.0) # -nan + compare[4] = values[3] = -log(0.0) # inf + compare[5] = values[4] = log(0.0) # -inf + + for (i = 1; i in values; i++) @{ + for (j = 1; j in compare; j++) @{ + for (k = 1; k in names; k++) @{ + the_func = funcs[k] + printf("%g %s %g -> %s\n", + values[i], + names[k], + compare[j], + @@the_func(values[i], compare[j]) ? + "True" : "False"); + @} + printf("\n"); + @} + @} +@} +@c endfile +@end ignore + +@ignore +@c file eg/test-programs/gen-float-table.c +#include <stdio.h> +#include <math.h> +#include <stdbool.h> + +#define def_func(name, op) \ + bool name(double left, double right) @{ \ + return left op right; \ + @} + +def_func(eq, ==) +def_func(ne, !=) +def_func(lt, <) +def_func(le, <=) +def_func(gt, >) +def_func(ge, >=) + +struct @{ + const char *name; + bool (*func)(double left, double right); +@} functions[] = @{ + @{ "==", eq @}, + @{ "!=", ne @}, + @{ "< ", lt @}, + @{ "<=", le @}, + @{ "> ", gt @}, + @{ ">=", ge @}, + @{ 0, 0 @} +@}; + +int main() +@{ + double values[] = @{ + -sqrt(-1), // nan + sqrt(-1), // -nan + -log(0.0), // inf + log(0.0) // -inf + @}; + double compare[] = @{ 2.0, + -sqrt(-1), // nan + sqrt(-1), // -nan + -log(0.0), // inf + log(0.0) // -inf + @}; + + int i, j, k; + + for (i = 0; i < 4; i++) @{ + for (j = 0; j < 5; j++) @{ + for (k = 0; functions[k].name != NULL; k++) @{ + printf("%g %s %g -> %s\n", values[i], + functions[k].name, + compare[j], + functions[k].func(values[i], compare[j]) ? "True" : "False"); + @} + printf("\n"); + @} + @} + + return 0; +@} +@c endfile +@end ignore + +@ignore +@c file eg/test-programs/gen-float-table.py +from math import * + +nan = float('NaN') +inf = float('Inf') + +def eq(left, right): + return left == right + +def ne(left, right): + return left != right + +def lt(left, right): + return left < right + +def le(left, right): + return left <= right + +def gt(left, right): + return left > right + +def ge(left, right): + return left >= right + +func_map = { + "==": eq, + "!=": ne, + "< ": lt, + "<=": le, + "> ": gt, + ">=": ge, +} + +compare = [2.0, nan, -nan, inf, -inf] +values = [nan, -nan, inf, -inf] + +for i in range(len(values)): + for j in range(len(compare)): + for op in func_map: + print("%g %s %g -> %s" % + (values[i], op, compare[j], func_map[op](values[i], compare[j]))) + + print("") +@c endfile +@end ignore + @node Getting Accuracy @subsection Getting the Accuracy You Need diff --git a/doc/gawktexi.in b/doc/gawktexi.in index 6ad9d6e0..fb237350 100644 --- a/doc/gawktexi.in +++ b/doc/gawktexi.in @@ -915,6 +915,7 @@ particular records in a file and perform operations upon them. * Inexact representation:: Numbers are not exactly represented. * Comparing FP Values:: How to compare floating point values. * Errors accumulate:: Errors get bigger as they go. +* Strange values:: A few words about infinities and NaNs. * Getting Accuracy:: Getting more accuracy takes some work. * Try To Round:: Add digits and round. * Setting precision:: How to set the precision. @@ -3046,11 +3047,12 @@ column means that the person is a friend. An @samp{R} means that the person is a relative: @example -@c system if test ! -d eg ; then mkdir eg ; fi -@c system if test ! -d eg/lib ; then mkdir eg/lib ; fi -@c system if test ! -d eg/data ; then mkdir eg/data ; fi -@c system if test ! -d eg/prog ; then mkdir eg/prog ; fi -@c system if test ! -d eg/misc ; then mkdir eg/misc ; fi +@c system if test ! -d eg ; then mkdir eg ; fi +@c system if test ! -d eg/lib ; then mkdir eg/lib ; fi +@c system if test ! -d eg/data ; then mkdir eg/data ; fi +@c system if test ! -d eg/prog ; then mkdir eg/prog ; fi +@c system if test ! -d eg/misc ; then mkdir eg/misc ; fi +@c system if test ! -d eg/test-programs ; then mkdir eg/test-programs ; fi @c file eg/data/mail-list Amelia 555-5553 amelia.zodiacusque@@gmail.com F Anthony 555-3412 anthony.asserturo@@hotmail.com A @@ -9624,7 +9626,7 @@ infinity are formatted as and positive infinity as @samp{inf} or @samp{infinity}. The special ``not a number'' value formats as @samp{-nan} or @samp{nan} -(@pxref{Math Definitions}). +(@pxref{Strange values}). @item @code{%F} Like @samp{%f}, but the infinity and ``not a number'' values are spelled @@ -17532,7 +17534,7 @@ compatibility mode (@pxref{Options}). @cindexawkfunc{log} @cindex logarithm Return the natural logarithm of @var{x}, if @var{x} is positive; -otherwise, return @code{NaN} (``not a number'') on IEEE 754 systems. +otherwise, return NaN (``not a number'') on IEEE 754 systems. Additionally, @command{gawk} prints a warning message when @code{x} is negative. @@ -32619,21 +32621,9 @@ A special value representing infinity. Operations involving another number and infinity produce infinity. @item NaN -``Not a number.''@footnote{Thanks to Michael Brennan for this description, -which we have paraphrased, and for the examples.} A special value that -results from attempting a calculation that has no answer as a real number. -In such a case, programs can either receive a floating-point exception, -or get @code{NaN} back as the result. The IEEE 754 standard recommends -that systems return @code{NaN}. Some examples: - -@table @code -@item sqrt(-1) -This makes sense in the range of complex numbers, but not in the -range of real numbers, so the result is @code{NaN}. - -@item log(-8) -@minus{}8 is out of the domain of @code{log()}, so the result is @code{NaN}. -@end table +``Not a number.'' A special value that results from attempting a +calculation that has no answer as a real number. @xref{Strange values}, +for more information about infinity and not-a-number values. @item Normalized How the significand (see later in this list) is usually stored. The @@ -32802,6 +32792,7 @@ decimal places in the final result. * Inexact representation:: Numbers are not exactly represented. * Comparing FP Values:: How to compare floating point values. * Errors accumulate:: Errors get bigger as they go. +* Strange values:: A few words about infinities and NaNs. @end menu @node Inexact representation @@ -32923,6 +32914,242 @@ $ @kbd{gawk 'BEGIN @{} @print{} 4 @end example +@node Strange values +@subsubsection Floating Point Values They Didn't Talk About In School + +Both IEEE 754 floating-point hardware, and MPFR, support two kinds of +values that you probably didn't learn about in school. The first is +@dfn{infinity}, a special value, that can be either negative or positive, +and which is either smaller than any other value (negative infinity), +or larger than any other value (positive infinity). When such values +are generated, @command{gawk} prints them as either @samp{-inf} or +@samp{+inf}, respectively. It accepts those strings as data input and +converts them to the proper floating-point values internally. + +Infinity values of the same sign compare as equal to each other. +Otherwise, operations (addition, subtraction, etc.) involving another +number and infinity produce mathematically reasonable results. + +The second kind of value is ``not a number'', or NaN for +short.@footnote{Thanks to Michael Brennan for this description, which we +have paraphrased, and for the examples.} This is a special value that results +from attempting a calculation that has no answer as a real number. +In such a case, programs can either receive a floating-point exception, +or get NaN back as the result. The IEEE 754 standard recommends +that systems return NaN. Some examples: + +@table @code +@item sqrt(-1) +@iftex +The @math{\sqrt{-1}} +@end iftex +@ifnottex +This +@end ifnottex +makes sense in the range of complex numbers, but not in the +range of real numbers, so the result is NaN. + +@item log(-8) +@minus{}8 is out of the domain of @code{log()}, so the result is NaN. +@end table + +NaN values are strange. In particular, they cannot be compared with other +floating point values; any such comparison, except for ``is not equal +to'', returns false. NaN values are so much unequal to other values that +even comparing two identical NaN values with @code{!=} returns true! + +NaN values can also be signed, although it depends upon the implementation +as to which sign you get for any operation that returns a NaN. For +example, on some systems, @code{sqrt(-1)} returns a negative NaN. On +others, it returns a positive NaN. + +When such values are generated, @command{gawk} prints them as either +@samp{-nan} or @samp{+nan}, respectively. Here too, @command{gawk} +accepts those strings as data input and converts them to the proper +floating-point values internally. + +If you want to dive more deeply into this topic, you can find +test programs in C, @command{awk} and Python in the directory +@file{awklib/eg/test-programs} in the @command{gawk} distribution. +These programs enable comparison among programming languages as to how +they handle NaN and infinity values. + +@ignore +@c file eg/test-programs/gen-float-table.awk +function eq(left, right) +@{ + return left == right +@} + +function ne(left, right) +@{ + return left != right +@} + +function lt(left, right) +@{ + return left < right +@} + +function le(left, right) +@{ + return left <= right +@} + +function gt(left, right) +@{ + return left > right +@} + +function ge(left, right) +@{ + return left >= right +@} + +BEGIN @{ + nan = sqrt(-1) + inf = -log(0) + split("== != < <= > >=", names) + names[3] = names[3] " " + names[5] = names[5] " " + split("eq ne lt le gt ge", funcs) + + compare[1] = 2.0 + compare[2] = values[1] = -sqrt(-1.0) # nan + compare[3] = values[2] = sqrt(-1.0) # -nan + compare[4] = values[3] = -log(0.0) # inf + compare[5] = values[4] = log(0.0) # -inf + + for (i = 1; i in values; i++) @{ + for (j = 1; j in compare; j++) @{ + for (k = 1; k in names; k++) @{ + the_func = funcs[k] + printf("%g %s %g -> %s\n", + values[i], + names[k], + compare[j], + @@the_func(values[i], compare[j]) ? + "True" : "False"); + @} + printf("\n"); + @} + @} +@} +@c endfile +@end ignore + +@ignore +@c file eg/test-programs/gen-float-table.c +#include <stdio.h> +#include <math.h> +#include <stdbool.h> + +#define def_func(name, op) \ + bool name(double left, double right) @{ \ + return left op right; \ + @} + +def_func(eq, ==) +def_func(ne, !=) +def_func(lt, <) +def_func(le, <=) +def_func(gt, >) +def_func(ge, >=) + +struct @{ + const char *name; + bool (*func)(double left, double right); +@} functions[] = @{ + @{ "==", eq @}, + @{ "!=", ne @}, + @{ "< ", lt @}, + @{ "<=", le @}, + @{ "> ", gt @}, + @{ ">=", ge @}, + @{ 0, 0 @} +@}; + +int main() +@{ + double values[] = @{ + -sqrt(-1), // nan + sqrt(-1), // -nan + -log(0.0), // inf + log(0.0) // -inf + @}; + double compare[] = @{ 2.0, + -sqrt(-1), // nan + sqrt(-1), // -nan + -log(0.0), // inf + log(0.0) // -inf + @}; + + int i, j, k; + + for (i = 0; i < 4; i++) @{ + for (j = 0; j < 5; j++) @{ + for (k = 0; functions[k].name != NULL; k++) @{ + printf("%g %s %g -> %s\n", values[i], + functions[k].name, + compare[j], + functions[k].func(values[i], compare[j]) ? "True" : "False"); + @} + printf("\n"); + @} + @} + + return 0; +@} +@c endfile +@end ignore + +@ignore +@c file eg/test-programs/gen-float-table.py +from math import * + +nan = float('NaN') +inf = float('Inf') + +def eq(left, right): + return left == right + +def ne(left, right): + return left != right + +def lt(left, right): + return left < right + +def le(left, right): + return left <= right + +def gt(left, right): + return left > right + +def ge(left, right): + return left >= right + +func_map = { + "==": eq, + "!=": ne, + "< ": lt, + "<=": le, + "> ": gt, + ">=": ge, +} + +compare = [2.0, nan, -nan, inf, -inf] +values = [nan, -nan, inf, -inf] + +for i in range(len(values)): + for j in range(len(compare)): + for op in func_map: + print("%g %s %g -> %s" % + (values[i], op, compare[j], func_map[op](values[i], compare[j]))) + + print("") +@c endfile +@end ignore + @node Getting Accuracy @subsection Getting the Accuracy You Need diff --git a/doc/it/ChangeLog b/doc/it/ChangeLog index 863eef47..83ed6247 100644 --- a/doc/it/ChangeLog +++ b/doc/it/ChangeLog @@ -1,3 +1,20 @@ +2021-02-01 Antonio Giovanni Colombo <azc100@gmail.com> + + * gawktexi.in: Updated. + +2021-01-25 Antonio Giovanni Colombo <azc100@gmail.com> + + * gawktexi.in: Updated. + * texinfo.tex: Updated. + +2021-01-22 Antonio Giovanni Colombo <azc100@gmail.com> + + * gawktexi.in: Updated. + +2020-11-20 Antonio Giovanni Colombo <azc100@gmail.com> + + * gawktexi.in: Updated. + 2020-11-01 Antonio Giovanni Colombo <azc100@gmail.com> * texinfo.tex: Updated. diff --git a/doc/it/gawktexi.in b/doc/it/gawktexi.in index fe7c6b29..e05abc4b 100644..100755 --- a/doc/it/gawktexi.in +++ b/doc/it/gawktexi.in @@ -56,7 +56,7 @@ @c applies to and all the info about who's publishing this edition @c These apply across the board. -@set UPDATE-MONTH Settembre 2020 +@set UPDATE-MONTH Gennaio 2021 @set VERSION 5.1 @set PATCHLEVEL 0 @@ -76,6 +76,7 @@ @iftex @set DOCUMENT libro @set CHAPTER capitolo +@set CHAPTERS capitoli @set APPENDIX appendice @set SECTION sezione @set SECTIONS sezioni @@ -93,6 +94,7 @@ @ifinfo @set DOCUMENT File Info @set CHAPTER nodo principale +@set CHAPTERS nodi principali @set APPENDIX nodo principale @set SECTION nodo secondario @set SECTIONS nodi secondari @@ -105,6 +107,7 @@ @ifhtml @set DOCUMENT Documento @set CHAPTER capitolo +@set CHAPTERS capitoli @set APPENDIX appendice @set SECTION sezione @set SECTIONS sezioni @@ -117,6 +120,7 @@ @ifdocbook @set DOCUMENT libro @set CHAPTER capitolo +@set CHAPTERS capitoli @set APPENDIX appendice @set SECTION sezione @set SECTIONS sezioni @@ -129,6 +133,7 @@ @ifxml @set DOCUMENT libro @set CHAPTER capitolo +@set CHAPTERS capitoli @set APPENDIX appendice @set SECTION sezione @set SECTIONS sezioni @@ -141,6 +146,7 @@ @ifplaintext @set DOCUMENT libro @set CHAPTER capitolo +@set CHAPTERS capitoli @set APPENDIX appendice @set SECTION sezione @set SECTIONS sezioni @@ -309,7 +315,7 @@ Some comments on the layout for TeX. Tel.: +1-617-542-5942 Fax: +1-617-542-2652 Email: <email>gnu@@gnu.org</email> URL: <ulink url="https://www.gnu.org">https://www.gnu.org/</ulink></literallayout> -<literallayout class="normal">Copyright © 1989, 1991, 1992, 1993, 1996–2005, 2007, 2009–2020 +<literallayout class="normal">Copyright © 1989, 1991, 1992, 1993, 1996–2005, 2007, 2009–2021 Free Software Foundation, Inc. All Rights Reserved. </literallayout> @@ -331,7 +337,7 @@ Italian Linux Documentation Project (ILDP) Email: <emailildp@@pluto.it URL: <ulink url="http://www.pluto.it/ildp">http://www.pluto.it/ildp/</ulink></literallayout> -<literallayout class="normal">Copyright © 2016–2020 +<literallayout class="normal">Copyright © 2016–2021 Free Software Foundation, Inc. All Rights Reserved. </literallayout> @@ -339,7 +345,7 @@ All Rights Reserved. @ifnotdocbook @iftex -Copyright @copyright{} 1989, 1991, 1992, 1993, 1996--2005, 2007, 2009--2020 @* +Copyright @copyright{} 1989, 1991, 1992, 1993, 1996--2005, 2007, 2009--2021 @* Free Software Foundation, Inc. @end iftex @end ifnotdocbook @@ -687,7 +693,7 @@ Copyright dell'edizione italiana @copyright{} 2016 -- Free Software Foundation, * Separazione in base al contenuto:: Definire campi dal loro contenuto. * File CSV:: Ancora sui file CSV. * Controllare la creazione di campi:: Controllare come @command{gawk} sta - dividendo i record. + suddividendo i record. * Righe multiple:: Record su righe multiple * Getline:: Richiedere input usando @code{getline}. * Getline semplice:: Usare @code{getline} senza argomenti. @@ -1005,6 +1011,7 @@ Copyright dell'edizione italiana @copyright{} 2016 -- Free Software Foundation, programmazione di rete. * Profilare:: Profilare i propri programmi @command{awk}. +* Filosofia delle estensioni:: Cosa dovrebbe essere incluso e cosa no. * Sommario funzionalit@`a avanzate:: Sommario funzionalit@`a avanzate. * I18N e L10N:: Internazionalizzazione e localiz. * Utilizzare @command{gettext}:: Come funziona GNU @code{gettext}. @@ -1065,13 +1072,14 @@ Copyright dell'edizione italiana @copyright{} 2016 -- Free Software Foundation, esattamente. * Confronti tra valori in VM:: Come confrontare valori in virgola mobile. * Gli errori si sommano:: Gli errori diventano sempre maggiori. +* Valori strani:: Un cenno riguardo ai valori infiniti e a NaN [``non @`e un numero'']. * Ottenere la precisione:: Ottenere la precisione voluta. * Tentare di arrotondare:: Tentare di aggiungere bit di precisione e arrotondare. * Impostare la precisione:: Impostare la precisione. * Impostare modo di arrotondare:: Impostare la modalit@`a di arrotondamento. -* Controllare disponibilit@`a MPFR:: Come controllare se MPFR @`e disponibile. +* Controllare disponibilit@`a MPFR:: Come controllare se MPFR @`e disponibile. * Interi a precisione arbitraria:: Aritmetica dei numeri interi a precisione arbitraria con @command{gawk}. * Problemi virgola mobile POSIX:: Confronto tra standard e uso corrente. @@ -3259,7 +3267,7 @@ Le ``shell'' nei sistemi Microsoft Windows usano il carattere doppio apice per protezione, e rendono difficile o impossibile inserire un carattere doppio apice letterale in uno @dfn{script} scritto su una riga di comando. L'esempio che segue, per il quale ringraziamo Jeroen Brink, mostra come -proteggere i doppi apici, con questo script di una sola riga, che stampa +proteggere i doppi apici, con questo @dfn{script} di una sola riga, che stampa tutte le righe di un file, racchiudendole tra doppi apici: @example @@ -3338,11 +3346,12 @@ persona @`e un amico [Friend]. Una @samp{R} vuol dire che quella persona @`e un parente [Relative]: @example -@c system if test ! -d eg ; then mkdir eg ; fi -@c system if test ! -d eg/lib ; then mkdir eg/lib ; fi -@c system if test ! -d eg/data ; then mkdir eg/data ; fi -@c system if test ! -d eg/prog ; then mkdir eg/prog ; fi -@c system if test ! -d eg/misc ; then mkdir eg/misc ; fi +@c system if test ! -d eg ; then mkdir eg ; fi +@c system if test ! -d eg/lib ; then mkdir eg/lib ; fi +@c system if test ! -d eg/data ; then mkdir eg/data ; fi +@c system if test ! -d eg/prog ; then mkdir eg/prog ; fi +@c system if test ! -d eg/misc ; then mkdir eg/misc ; fi +@c system if test ! -d eg/test-programs ; then mkdir eg/test-programs ; fi @c file eg/data/mail-list Amelia 555-5553 amelia.zodiacusque@@gmail.com F Anthony 555-3412 anthony.asserturo@@hotmail.com A @@ -4534,7 +4543,7 @@ Forza l'uso del carattere di separazione decimale della localizzazione quando analizza i dati in input (@pxref{Localizzazioni}). -@cindex stampa elegante +@cindex stampa-elegante @item @option{-o}[@var{file}] @itemx @option{--pretty-print}[@code{=}@var{file}] @cindex @option{-o} (opzione) @@ -5018,7 +5027,7 @@ variabile non esiste, o se ha un come valore la stringa nulla, @command{gawk} usa un percorso di default (descritto tra poco). La funzionalit@`a del percorso di ricerca @`e particolarmente utile per costruire -librerie di funzioni di @command{awk}. I file di libreria possono essere messi +librerie di funzioni di @command{awk}. Le librerie di file possono essere messe in una directory standard inclusa nel percorso di ricerca e richiamati sulla riga di comando con un @value{FN} breve. Altrimenti, si dovrebbe scrivere l'intero @value{FN} per @@ -5026,7 +5035,7 @@ ciascun file. Usando l'opzione @option{-i}, o l'opzione @option{-f}, i programmi di @command{awk} scritti sulla riga di comando possono usare le funzionalit@`a -contenute nei file di libreria di @command{awk} +contenute nelle librerie di file di @command{awk} @iftex (@pxrefil{Funzioni di libreria}). @end iftex @@ -5386,7 +5395,7 @@ possono includere queste ``librerie'' usando il percorso completo dei file, o impostando opportunamente la variabile d'ambiente @env{AWKPATH} e quindi usando @code{@@include} con la sola parte del percorso completo che designa il file. Naturalmente, -si possono tenere i file di libreria in pi@`u di una directory; +si possono tenere le librerie di file in pi@`u di una directory; pi@`u @`e complesso l'ambiente di lavoro, pi@`u directory possono essere necessarie per organizzare i file da includere. @@ -6384,7 +6393,7 @@ che occupano un unico byte (caratteri il cui valore stia nell'intervallo 0--256). Per individuare un intervallo di caratteri in cui i punti di inizio e fine dell'intervello abbiano valori maggiori di 256, occorre immettere direttamente -le codifiche multi-byte dei caratteri in questione. +le codifiche multibyte dei caratteri in questione. @cindex @code{\} (barra inversa) @subentry in espressioni tra parentesi quadre @cindex barra inversa (@code{\}) @subentry in espressioni tra parentesi quadre @@ -6523,7 +6532,7 @@ sono equivalenti). Queste sequenze sono: @cindex espressioni @subentry tra parentesi quadre @subentry elementi di collazione @cindex elementi @subentry di collazione @item elementi di collazione -Elementi di collazione multi-byte racchiusi fra +Elementi di collazione multibyte racchiusi fra @samp{[.} e @samp{.]}. Per esempio, se @samp{ch} @`e un elemento di collazione, @samp{[[.ch.]]} @`e una @dfn{regexp} che individua questo elemento di collazione, mentre @samp{[ch]} @`e una @dfn{regexp} che individua le lettere @@ -7096,7 +7105,7 @@ getline (@pxref{Getline}). * Dimensione costante:: Leggere campi di larghezza costante. * Separazione in base al contenuto:: Definire campi dal loro contenuto. * Controllare la creazione di campi:: Controllare come @command{gawk} sta - dividendo i record. + suddividendo i record. * Righe multiple:: Leggere record che sono su pi@`u righe. * Getline:: Leggere file sotto il controllo del programma, usando la funzione @@ -7274,23 +7283,6 @@ in questione non viene trattato come tale, ma viene usato letteralmente. Ci@`o viene fatto per compatibilit@`a all'indietro sia con il comando Unix @command{awk} che con lo standard POSIX. -Quando si usano caratteri normali come separatore di record, -c'@`e un caso insolito che capita quando @command{gawk} -@`e reso completamente conforme a POSIX (@pxref{Opzioni}). -In quel caso, la seguente (estrema) @dfn{pipeline} stampa un sorprendente -@samp{1}: - -@example -$ echo | gawk --posix 'BEGIN @{ RS = "a" @} ; @{ print NF @}' -@print{} 1 -@end example - -C'@`e un solo campo, consistente in un ritorno a capo. Il valore della -variabile predefinita @code{NF} @`e il numero di campi nel record corrente. -(Normalmente @command{gawk} tratta il ritorno a capo come uno spazio -vuoto, stampando @samp{0} come risultato. Anche molte altre versioni di -@command{awk} agiscono in questo modo.) - @cindex angolo buio @subentry file in input Il raggiungimento della fine di un file in input fa terminare il record di input corrente, anche se l'ultimo carattere nel file non @`e il carattere in @@ -7387,7 +7379,7 @@ particolare se il testo di input che potrebbe avere una corrispondenza con la parte finale @`e piuttosto lungo. @command{gawk} cerca di evitare questo problema, ma al momento non ci sono garanzie che questo funzioni sempre. -@quotation NOTA +@sidebar Avvertenze per quando si usano espressioni regolari come @code{RS} Si ricordi che in @command{awk}, i metacaratteri di ancoraggio @samp{^} e @samp{$} trovano l'inizio e la fine di una @emph{stringa}, e non l'inizio e la fine di una @emph{riga}. Come risultato, qualcosa come @@ -7395,7 +7387,15 @@ fine di una @emph{riga}. Come risultato, qualcosa come Questo perch@'e @command{gawk} vede il file in input come un'unica lunga stringa in cui possono essere presenti dei caratteri di ritorno a capo. @`E meglio perci@`o evitare metacaratteri di ancoraggio nel valore di @code{RS}. -@end quotation + +La suddivisione in campi usando espressioni regolari funziona in maniera +differente di quando la si usa con le funzioni @code{sub()}, @code{gsub()}, e +@code{gensub()} (@pxref{Funzioni per stringhe}). Tali funzioni consentono +che un'espressione regolare sia soddisfatta da una stringa nulla; +La suddivisione in campi non lo consente. Quindi, per esempio, +@samp{RS = "()"} @emph{non} divide un record in campi di un carattere +ciascuno. +@end sidebar @cindex @command{gawk} @subentry variabile @subentry @code{RT} in @cindex @code{RT} (variabile) @@ -8034,6 +8034,15 @@ $ @kbd{echo 'xxAA xxBxx C' |} @print{} -->C<-- @end example +Inoltre, +la suddivisione in campi usando espressioni regolari funziona in maniera +differente di quando la si usa con le funzioni @code{sub()}, @code{gsub()}, e +@code{gensub()} (@pxref{Funzioni per stringhe}). Tali funzioni consentono +che un'espressione regolare sia soddisfatta da una stringa nulla; +La suddivisione in campi non lo consente. Quindi, per esempio, +@samp{RS = "()"} @emph{non} divide un record in campi di un carattere +ciascuno. + @node Campi di un solo carattere @subsection Fare di ogni carattere un campo separato @@ -8592,6 +8601,10 @@ parole, @code{FS} definisce cosa un campo @emph{non @`e}, invece di cosa Tuttavia, ci sono casi in cui effettivamente si ha bisogno di definire i campi in base a cosa essi sono, e non in base a cosa non sono. +@cindex dati CSV (valori separati da virgole) @subentry analizzare con @code{FPAT} +@cindex CSV (valori separati da virgole) come dati @subentry analizzare con @code{FPAT} +@cindex Comma Separated Values (CSV) come dati @subentry analizzare con @code{FPAT} +@cindex valori separati da virgole (CSV) come dati @subentry analizzare con @code{FPAT} Il caso pi@`u emblematico @`e quello dei dati cosiddetti @dfn{comma-separated value} (CSV). Molti fogli elettronici, per esempio, possono esportare i dati in file di testo, dove ogni record termina con un ritorno a capo e i campi @@ -8710,7 +8723,7 @@ FPAT = "([^,]*)|(\"[^\"]+\")" @c Per email from Ed Morton <mortoneccc@comcast.net> @c @c WONTFIX: 10/2020 -@c This is too much work. FPAT and CSV files are very flakey and +@c This is too much work. FPAT and CSV files are very flaky and @c fragile. Doing something like this is merely inviting trouble. Come per @code{FS}, la variabile @code{IGNORECASE} @@ -8789,8 +8802,20 @@ $ @kbd{gawk -v fpat=2 -f test-csv.awk sample.csv} @print{} NF = 3 <p><><s> @end example +@cindex Collado, Manuel +@cindex @code{CSVMODE}, libreria per @command{gawk} +@cindex libreria @code{CSVMODE} per @command{gawk} +@cindex dati CSV (valori separati da virgole) @subentry analizzare con libreria @code{CSVMODE} +@cindex CSV (valori separati da virgole) come dati @subentry analizzare con libreria @code{CSVMODE} +@cindex valori separati da virgole (CSV) come dati @subentry analizzare con libreria @code{CSVMODE} +In generale, usare @code{FPAT} per effettuare l'analisi di dati in formato CSV +@`e come utilizzare un lenzuolo troppo corto. Rimane sempre un angolo che non +@`e coperto. Si raccomanda, in alternativa, di usare la libreria @code{CSVMODE} +messa a disposizione da Manuel Collado. Vedere: +@uref{http://mcollado.z15.es/xgawk/, @code{CSVMODE} libreria per @command{gawk}}. + @node Controllare la creazione di campi -@section Controllare come @command{gawk} sta dividendo i record +@section Controllare come @command{gawk} sta suddividendo i record @cindex @command{gawk} @subentry separazione in campi e Come visto sopra, @command{gawk} fornisce tre metodi indipendenti per @@ -10473,9 +10498,9 @@ dallo standard IEEE 754, il valore infinito negativo @`e rappresentato come @samp{-inf} o @samp{-infinity}, e l'infinito positivo come @samp{inf} o @samp{infinity}. -Il valore speciale ``not a number'' [non @`e un numero] viene scritto come +Il valore speciale ``not a number'' ["non @`e un numero"] viene scritto come @samp{-nan} o @samp{nan} -(@pxref{Definizioni matematiche}). +(@pxref{Valori strani}). @item @code{%F} Come @samp{%f}, ma i valori di infinito e di ``not a number'' sono scritti @@ -13160,16 +13185,18 @@ Per avere la massima portabilit@`a, non usare l'operatore @samp{**=}. @sidebar Ambiguit@`a sintattiche tra @samp{/=} e le espressioni regolari @cindex angolo buio @subentry costanti @dfn{regexp} @subentry operatore @code{/=} e -@cindex @code{/} (barra) @subentry operatore @code{/=} @subentry vs. costante @dfn{regexp} @code{/=@dots{}/} -@cindex barra (@code{/}) @subentry operatore @code{/=} @subentry vs. costante @dfn{regexp} @code{/=@dots{}/} +@cindex @code{/} (barra) @subentry operatore @code{/=} @subentry vs.@: costante @dfn{regexp} @code{/=@dots{}/} +@cindex barra (@code{/}) @subentry operatore @code{/=} @subentry vs.@: costante @dfn{regexp} @code{/=@dots{}/} @cindex @dfn{regexp} @subentry costanti @subentry @code{/=@dots{}/}, operatore @code{/=} e @c derived from email from "Nelson H. F. Beebe" <beebe@math.utah.edu> @c Date: Mon, 1 Sep 1997 13:38:35 -0600 (MDT) -@cindex angolo buio @subentry operatore @code{/=} vs. costante @dfn{regexp} @code{/=@dots{}/} -@cindex ambiguit@`a sintattica: operatore @code{/=} vs. costante @dfn{regexp} @code{/=@dots{}/} -@cindex sintattica @subentry ambiguit@`a: operatore @code{/=} vs. costante @dfn{regexp} @code{/=@dots{}/} +@cindex angolo buio @subentry operatore @code{/=} vs.@: costante @dfn{regexp} @code{/=@dots{}/} +@cindex ambiguit@`a sintattica: operatore @code{/=} vs.@: costante @dfn{regexp} @code{/=@dots{}/} +@cindex sintattica @subentry ambiguit@`a: operatore @code{/=} vs.@: costante @dfn{regexp} @code{/=@dots{}/} +@cindex @code{/=} (uguale) @subentry operatore vs.@: @code{/=@dots{}/} costante @dfn{regexp} +@cindex uguale (@code{/=}) @subentry operatore vs.@: @code{/=@dots{}/} costante @dfn{regexp} C'@`e un'ambiguit@`a sintattica tra l'operatore di assegnamento @code{/=} e le costanti @dfn{regexp} il cui primo carattere sia @samp{=}. @value{DARKCORNER} @@ -14996,12 +15023,13 @@ Ci@`o non @`e pi@`u obbligatorio, ma @`e una buona idea continuare a seguire que modello per migliorare l'organizzazione e la leggibilit@`a del programma. Regole multiple @code{BEGIN} ed @code{END} sono utili per scrivere funzioni -di libreria, poich@'e ogni file di libreria pu@`o avere la sua propria regola -@code{BEGIN} e/o @code{END} per fare la propria inizializzazione e/o pulizia. +di libreria, poich@'e ogni file di una libreria pu@`o avere la sua propria +regola @code{BEGIN} e/o @code{END} per fare la propria inizializzazione e/o +pulizia. L'ordine in cui le funzioni di libreria sono menzionate nella riga dei comandi determina l'ordine in cui le rispettive regole @code{BEGIN} ed @code{END} sono eseguite. Per questo motivi, occorre prestare attenzione nello scrivere tali -regole nei file di libreria, in modo che non sia importante +regole nelle librerie di file, in modo che non sia importante l'ordine in cui tali regole vengono eseguite. @xref{Opzioni} per maggiori informazioni sull'uso di funzioni di libreria. @iftex @@ -16060,16 +16088,17 @@ risultato. In @command{gawk}, l'esecuzione di @code{nextfile} produce ulteriori effetti: le eventuali regole @code{ENDFILE} sono eseguite se @command{gawk} non -si trova correntemente all'interno di una regola @code{END} o -@code{BEGINFILE}; @code{ARGIND} @`e +si trova correntemente all'interno di una regola @code{END}, +@code{ARGIND} @`e incrementato e le eventuali regole @code{BEGINFILE} sono eseguite. (@code{ARGIND} non @`e stato ancora trattato. @xref{Variabili predefinite}.) -In @command{gawk}, @code{nextfile} @`e utile all'interno di una regola +C'@`e un ulteriore caso speciale di utilizzo in @command{gawk}. +@code{nextfile} @`e utile all'interno di una regola @code{BEGINFILE} per evitare di elaborare un file che altrimenti causerebbe un errore fatale in @command{gawk}. -In questo caso, le regole @code{ENDFILE} non vengono eseguite. +In questo caso speciale, le regole @code{ENDFILE} non vengono eseguite. @xref{BEGINFILE/ENDFILE}. Sebbene possa sembrare che @samp{close(FILENAME)} ottenga lo stesso @@ -19051,8 +19080,8 @@ modalit@`a compatibile (@pxref{Opzioni}). @cindexawkfunc{log} @cindex logaritmo Restituisce il logaritmo naturale di @var{x}, se @var{x} @`e positivo; -altrimenti, restituisce @code{NaN} (``not a number'') sui sistemi che -implementano lo standard IEEE 754. +altrimenti, restituisce NaN (``not a number'',[``non @`e un numero'']) +sui sistemi che implementano lo standard IEEE 754. Inoltre, @command{gawk} stampa un messaggio di avvertimento qualora @code{x} sia negativo. @@ -26199,13 +26228,13 @@ possono essere separati da virgole, e intervalli di caratteri possono essere separated da trattini. La lista @samp{1-8,15,22-35} specifica i caratteri da 1 a 8, 15, e da 22 a 35. -@item -f @var{lista} -Usare @var{lista} come lista di campi da ritagliare. - @item -d @var{delimitatore} Usare @var{delimitatore} come carattere che separa i campi invece del carattere TAB. +@item -f @var{lista} +Usare @var{lista} come lista di campi da ritagliare. + @item -s Evita la stampa di righe che non contengono il delimitatore di campo. @end table @@ -26216,6 +26245,12 @@ di libreria @code{getopt()} e la funzione di libreria @code{join()} (@pxref{Funzione join}). +La versione POSIX corrente del comando @command{cut} prevede opzioni +per ritagliare dei campi che possono essere sia byte che caratteri +[possibilmente multibyte]. Questa versione non tenta di implementare +tali opzioni, poich@'e @command{awk} lavora esclusivamente in termini +di caratteri. + Il programma inizia con un commento che descrive le opzioni, le funzioni di libreria necessarie, e una funzione @code{sintassi()} che stampa un messaggio ed esce. @code{sintassi()} @`e chiamato se si specificano degli @@ -26237,9 +26272,9 @@ argomenti non validi: @c file eg/prog/cut.awk # Opzioni: +# -c lista Ritagliare caratteri # -f lista Ritagliare campi # -d c Carattere di delimitazione di campo -# -c lista Ritagliare caratteri # # -s Sopprimere righe che non contengono il delimitatore # @@ -26315,7 +26350,7 @@ un semplice spazio (@code{@w{" "}}) come valore per @code{FS} @`e sbagliato: @command{awk} separerebbe i campi con serie di spazi, TAB, e/o ritorni a capo, mentre devono essere separati solo da uno spazio. Per far questo, salviamo il carattere di spazio originale nella variabile -@code{fs} per un uso futuro; dopo aver impostato @code{FS} a @code{"[ ]"} non +@code{fs} per un uso futuro; dopo aver impostato @code{FS} a @code{@w"[ ]"} non @`e possibile usarlo direttamente per vedere se il carattere delimitatore di campo @`e nella stringa. @@ -26633,14 +26668,17 @@ BEGIN @{ @noindent Si noti il commento relativo alla chiamata del programma: -Poich@'e parecchie opzioni possono essere sepcificate anche per +Poich@'e parecchie opzioni possono essere specificate anche per @command{gawk}, occorre immettere @option{--} per far s@`@{dotless{i}} che @command{gawk} non prosegua nell'analisi delle opzioni. Nel seguito c'@`e il codice che gestisce il comportamento specifico di -@command{egrep}. Se non @`e fornito esplicitamente alcun criterio di ricerca -tramite l'opzione @option{-e}, si usa il primo argomento sulla riga di -comando che non sia un'opzione. +@command{egrep}. @command{egrep} utilizza il primo argomento sulla +riga di comando che non sia un'opzione se non @`e fornito esplicitamente +alcun criterio di ricerca tramite l'opzione @option{-e}. +Se il criterio di ricerca @`e la stringa nulla, ci@`o significa che non +@`e stato fornito alcun criterio, quindi @`e necessario stampare un +messaggio di errore e terminare il programma. Gli argomenti della riga di comando di @command{awk} fino ad @code{ARGV[Optind]} vengono cancellati, in modo che @command{awk} non tenti di elaborarli come file. Se @@ -26734,9 +26772,9 @@ verificando i valori delle variabili @code{RSTART} e @code{RLENGTH}. Se questi indicano che la corrispondenza non coincide con l'intera riga, la variabile @code{corrisponde} @`e impostata a zero (falsa). -Se l'utente chiede invece le righe che @emph{non} corrispondono, -il senso di @code{corrisponde} @`e invertito, usando l'operatore @samp{!}. -@code{contatore_file} @`e incrementato con il valore di +Se l'utente chiede invece le righe che non corrispondono, si inverte +il senso di @code{corrisponde}, usando l'operatore @samp{!}. +Poi, @code{contatore_file} @`e incrementato con il valore di @code{corrisponde}, che vale uno o zero, a seconda che la corrispondenza sia stata trovata oppure no. Se la riga non corrisponde, l'istruzione @code{next} passa ad esaminare il record successivo. @@ -27285,7 +27323,9 @@ Ecco un'implementazione di @command{split} in @command{awk}. Viene utilizzata la funzione @code{getopt()} presentata in @ref{Funzione getopt}. Il programma inizia con un commento descrittivo e poi con la -funzione @code{sintassi()} che ne descrive le opzioni: +funzione @code{sintassi()} che ne descrive le opzioni. La variabile +@code{comune} permettere di avere delle righe brevi nella funzione, +in modo che sia stampata in maniera elegante nella pagina: @cindex @code{split.awk} (programma) @cindex programma @subentry @code{split.awk} @@ -27306,10 +27346,11 @@ funzione @code{sintassi()} che ne descrive le opzioni: @c endfile @end ignore @c file eg/prog/split.awk -function sintassi() +function sintassi( comune) @{ - print("Uso: split [-l contatore] [-a lunghezza-suffisso] [file [nome-output-file]]") > "/dev/stderr" - print(" split [-b N[k|m]] [-a lunghezza-suffisso] [file [nome-output-file]]") > "/dev/stderr" + common = "[-a lunghezza-suffisso] [file [nome-output-file]]" + printf("Uso: split [-l contatore] %s\n", comune) > "/dev/stderr" + printf(" split [-b N[k|m]] %s\n", comune) > "/dev/stderr" exit 1 @} @c endfile @@ -27801,7 +27842,8 @@ spiegazione delle opzioni e del loro significato, sotto forma di commenti: function sintassi() @{ - print("Uso: uniq [-udc [-f campi]] [-s caratteri] [ in [ out ]]") > "/dev/stderr" + print("Uso: uniq [-udc [-f campi] [-s caratteri]] " \ + "[ in [ out ]]") > "/dev/stderr" exit 1 @} @@ -28063,7 +28105,7 @@ Klingon e il linguaggio degli elfi di J.R.R.@: Tolkien). Per risparmiare spazio nei file, i @dfn{code points} Unicode sono @dfn{codificati}, e la rappresentazione di ogni carattere pu@`o richiedere da uno a quattro byte nel file. UTF-8 @`e verosimilmente la pi@`u diffusa -fra queste codifiche multi-byte (@dfn{multibyte encodings}). +fra queste codifiche multibyte (@dfn{multibyte encodings}). Lo standard POSIX richiede che @command{awk} gestisca dei caratteri, non dei byte. Per questo motivo, in @command{gawk}, le funzioni @@ -28091,7 +28133,7 @@ Per quanto riguarda @file{wc.awk}, @`e sufficiente sapere che l'estensione viene caricata con la direttiva @code{@@load}, e la funzione ulteriore che dovr@`a essere usata si chiama @code{mbs_length()}. Questa funzione restiuisce il numero -di byte in una stringa, e non il numero di caratteri. +di byte in una stringa, non il numero di caratteri. L'estensione @code{"mbs"} fa parte del progetto @code{gawkextlib}. @xref{gawkextlib} for ulteriori informazioni. @@ -28110,23 +28152,23 @@ standard input. Se ci sono pi@`u file, stampa anche il contatore totale di tutti i file. Le opzioni e il loro significato sono i seguenti: @table @code -@item -l -Conta solo le righe. - -@item -w -Conta solo le parole. -Una ``parola'' @`e una sequenza contigua di caratteri non bianchi, separata da -spazi e/o TAB. Fortunatamente, questo @`e il modo normale in cui @command{awk} -separa i campi nei suoi record in input. - @item -c Conta solo i byte. Un tempo, la lettera @samp{c} di questa opzione stava per ``caratteri.'' Ma, come spiegato pi@`u sopra, byte e carattere non sono pi@`u sinonimi tra loro. +@item -l +Conta solo le righe. + @item -m Conta solo caratteri. + +@item -w +Conta solo le parole. +Una ``parola'' @`e una sequenza contigua di caratteri non bianchi, separata da +spazi e/o TAB. Fortunatamente, questo @`e il modo normale in cui @command{awk} +separa i campi nei suoi record in input. @end table L'implementazione di @command{wc} in @command{awk} @`e particolarmente @@ -30618,6 +30660,7 @@ tratta della capacit@`a di aggiungere dinamicamente nuove funzioni predefinite a processo. * Reti TCP/IP:: Usare @command{gawk} per programmazione di rete. * Profilare:: Profilare i propri programmi @command{awk}. +* Filosofia delle estensioni:: Cosa dovrebbe essere incluso e cosa no. * Sommario funzionalit@`a avanzate:: Sommario delle funzionalit@`a avanzate. @end menu @@ -31828,7 +31871,7 @@ alfabetico. La versione profilata del proprio programma potrebbe non apparire esattamente come quella scritta durante la stesura del programma. Questo perch@'e -@command{gawk} crea la versione profilata facendo una ``stampa elegante'' della +@command{gawk} crea la versione profilata facendo una ``stampa-elegante'' della sua rappresentazione interna del programma. Un vantaggio di ci@`o @`e che @command{gawk} pu@`o produrre una rappresentazione standard. Inoltre, cose come: @@ -31923,9 +31966,9 @@ tastiera. Il segnale @code{INT} @`e generato dalle combinazioni di tasti @kbd{Ctrl-c} o @kbd{Ctrl-BREAK}, mentre il segnale @code{QUIT} @`e generato dalla combinazione di tasti @kbd{Ctrl-\}. -@cindex stampa elegante +@cindex stampa-elegante Infine, @command{gawk} accetta anche un'altra opzione, @option{--pretty-print}. -Quando viene chiamato in questo modo, @command{gawk} fa una ``stampa elegante'' +Quando viene chiamato in questo modo, @command{gawk} fa una ``stampa-elegante'' del programma nel file @file{awkprof.out}, senza conteggi sull'esecuzione. @quotation NOTA @@ -31933,10 +31976,10 @@ Una volta, l'opzione @option{--pretty-print} eseguiva anche il programma. Ora non pi@`u. @end quotation -@cindex profilazione @subentry differenza rispetto alla stampa elegante -@cindex stampa elegante @subentry differenza rispetto alla profilazione +@cindex profilazione @subentry differenza rispetto alla ``stampa-elegante'' +@cindex stampa-elegante @subentry differenza rispetto alla profilazione C'@`e una differenza significativa tra l'output creato durante la profilazione, -e quello creato durante la stampa elegante. L'output della stampa elegante +e quello creato durante la ``stampa-elegante''. L'output della ``stampa-elegante'' preserva i commenti originali che erano nel programma, anche se la loro posizione pu@`o non corrispondere esattamente alle posizioni originali che avevano nel codice sorgente. Tuttavia, nessun commento dovrebbe andare @@ -31948,23 +31991,83 @@ in maniera perfetta. Comunque, per una precisa scelta progettuale, l'output della profilazione @emph{omette} i commenti del programma originale. Questo permette di concentrarsi sui dati del conteggio di esecuzione ed evita la tentazione di -usare il profilatore per creare una stampa elegante. +usare il profilatore per creare una ``stampa-elegante''. Oltre a ci@`o, l'output stampato in modo elegante non ha l'indentazione iniziale -che ha l'output della profilazione. Questo rende agevole la stampa elegante +che ha l'output della profilazione. Questo rende agevole la ``stampa-elegante'' del proprio codice una volta completato lo sviluppo, usando poi il risultato come versione finale del programma. Poich@'e la rappresentazione interna del programma @`e formattata per essere aderente al programma @command{awk} in questione, la profilazione -e la stampa elegante (opzione @option{--pretty-print}) disabilitano +e la ``stampa-elegante'' (opzione @option{--pretty-print}) disabilitano automaticamente le optimizzazioni di default di @command{gawk}. -La profilazione e la stampa elegante mantengono anche il formato originale +La profilazione e la ``stampa-elegante'' mantengono anche il formato originale delle costanti numeriche; se sono stati usati dei valori ottali o esadecimali nel codice sorgente, questi compariranno nell'output nello stesso formato con cui sono stati inseriti. +@node Filosofia delle estensioni +@section Funzionalit@`a incluse @dfn{versus} estensioni + +Come descritto in questo e nei successivi @value{CHAPTERS}, +@command{gawk} ha numerose estensioni ulteriori, +rispetto a quelle presenti nel comando @command{awk} standard. +Queste sono state sviluppate col passare del tempo. +Pi@`u recentemente, l'attenzione si @`e spostata sull'utilizzo +del meccanismo delle estensioni (@pxref{Estensioni dinamiche}), +per aggiungere ulteriori funzionalit@`a. +@ifnotinfo +Questa @value{SECTION} +@end ifnotinfo +@ifinfo +Questo @value{SECTION} +@end ifinfo +tratta della ``filosofia ispiratrice'' riguardo a ci@`o che dovrebbe +essere aggiunto all'interprete come funzionalit@`a interna, +rispetto a quello che dovrebbe essere reso disponibile tramite +estensioni. + +Ci sono parecchi obiettivi: + +@enumerate 1 +@item +Conservare il comando @command{awk}; non dovrebbe divenire irriconoscibile +anche se i programmi scritti per esso verranno eseguito solo usando +@command{gawk}. + +@item +Non aumentare le dimensioni del nucleo del programma, a meno che ci@`o +sia assolutamente indispensabile. + +@item +Aggiungere nuove funzionalit@`a o tramite @dfn{script} +(opzione @option{-f}, direttiva @code{@@include}) +o in un'estensione caricabile scritta in C o C++ +(opzione @option{-l}, direttiva @code{@@load}). + +@item +Estendere il nucleo dell'interpretatore solo se qualche funzionalit@`a @`e: + +@c sublist +@enumerate A +@item +Veramente desiderabile. +@item +Non si pu@`o fare tramite dei file di libreria o estensioni caricabili. +@item +Pu@`o essere aggiunta al nucleo senza troppe difficolt@`a. +@end enumerate +@end enumerate + +Combinare dei moduli con dei file @command{awk} @`e una tecnica efficace. +Lo si pu@`o vedere in alcuni degli esempi di estensione. + +Il caricamento di estensioni e librerie di file non dovrebbe essere +fatto automaticamente, perch@'e questo richiede un consumo di risorse +che molti utenti non desiderano, o di cui non hanno bisogno. + @node Sommario funzionalit@`a avanzate @section Sommario @@ -32012,9 +32115,14 @@ profilazione @command{gawk} scrive il profilo, includendo lo @dfn{stack} della chiamata alla funzione e prosegue nell'elaborazione. @item -Si pu@`o anche fare solo una ``stampa elegante'' del programma. +Si pu@`o anche fare solo una ``stampa-elegante'' del programma. +@item +Nuove funzionalit@`a dovrebbero essere sviluppate usando, se possibile, +il meccanismo delle estensioni; si dovrebbero aggiungere al nucleo +dell'interpretatore solo come ultima risorsa. @end itemize + @node Internazionalizzazione @chapter Internazionalizzazione con @command{gawk} @@ -35079,10 +35187,10 @@ Questo interagisce con altre importanti funzionalit@`a di @command{gawk}. @cindex spazio-dei-nomi @subentry interazione con la profilazione -@cindex spazio-dei-nomi @subentry interazione con la stampa elegante +@cindex spazio-dei-nomi @subentry interazione con la ``stampa-elegante'' @cindex profilazione @subentry interazione con spazio-dei-nomi -@cindex stampa elegante @subentry interazione con spazio-dei-nomi -La profilazione e la stampa elegante (@pxref{Profilare}) sono state +@cindex stampa-elegante @subentry interazione con spazio-dei-nomi +La profilazione e la ``stampa-elegante'' (@pxref{Profilare}) sono state migliorate per trattare gli spazi-dei-nomi e le regole per assegnare nomi in uno spazio-dei-nomi @ref{Regole per i nomi}. In particolare, l'output tiene insieme le funzioni che appartengono @@ -35143,7 +35251,7 @@ disponibile la potenza e la flessibilit@`a necessarie. @item Altre parti di @command{gawk} sono state estese come necessario per integrare gli spazi-dei-nomi nel loro funzionamento. -Questo vale soprattutto per la profilazione / stampa elegante +Questo vale soprattutto per la profilazione / ``stampa-elegante'' (@pxref{Profilare}) e per le funzionalit@`a relative alle estensioni (@pxref{Estensioni dinamiche}). @@ -35366,23 +35474,10 @@ Come i numeri vanno arrotondati, per eccesso o per difetto, quando necessario. Maggiori dettagli verranno forniti in seguito. @item NaN -``Not a number'' (Non un Numero).@footnote{Grazie a Michael -Brennan per questa descrizione, che abbiamo parafrasato, e per gli esempi.} Un -valore speciale che risulta da un calcolo che non ha risposta come numero -reale. In tal caso, i programmi possono o ricevere un'eccezione di virgola -mobile, o restituire @code{NaN} come risultato. Lo standard IEEE 754 -consiglia che i sistemi restituiscano @code{NaN}. Alcuni esempi: - -@table @code -@item sqrt(-1) -La radice quadrata di @minus{}1 ha senso nell'insieme dei numeri complessi, -ma non nell'insieme dei numeri reali, -per cui il risultato @`e @code{NaN}. - -@item log(-8) -Il logaritmo di @minus{}8 @`e fuori dal dominio di @code{log()}, -per cui il risultato @`e @code{NaN}. -@end table +``Not a number'' (``non @`e un numero''). Un valore speciale +che risulta da un calcolo che non ha come risposta un numero +reale. @xref{Valori strani}, per maggiori informazioni riguardo +ai valori infiniti e ai valori ``non-un-numero''. @item Normalizzato (formato) Come la mantissa (vedi oltre in questa lista) @`e usualmente memorizzata. Il @@ -35534,8 +35629,7 @@ ottenere ulteriori informazioni, e non basarsi solo su quanto qui detto. * Ottenere la precisione:: Ottenere pi@`u precisione richiede qualche sforzo. * Tentare di arrotondare:: Aggiungere cifre di precisione e arrotondare. -* Impostare la precisione:: Come impostare la precisione. -* Impostare modo di arrotondare:: Impostare le modalit@`a di arrotondamento. +* Valori strani:: Un cenno riguardo ai valori infiniti e a NaN [``non @`e un numero'']. @end menu @node Inesattezza nei calcoli @@ -35682,6 +35776,257 @@ $ @kbd{gawk 'BEGIN @{} @print{} 4 @end example +@node Valori strani +@subsubsection Valori in virgola mobile non spiegati a scuola + +Sia l'hardware che implementa lo standard per i numeri in virgola +mobili IEEE 754, che la libreria matematica MPFR, prevedono due +tipi di valori di cui probabilmente non vi hanno parlato a scuola. +Il primo @`e il valore @dfn{infinity} (``infinito''), un valore speciale +che pu@`o avere un segno sia negativo che positivo, e che @`e pi@`u +piccolo di ogni altro valore (infinito negativo), o maggiore di ogni +altro valore (infinito positivo). Quando vengono generati tali valori +@command{gawk} li stampa come @samp{-inf} o @samp{+inf}, rispettivamente. +@command{gawk} accetta queste stringhe come dati in input, e li converte +internamente all'appropriato valore in virgola mobile. + +Valori di infinito che abbiano lo stesso segno risultano uguali +quando sono confrontati fra loro. +Per il resto, altre operazioni (addizione, sottrazione, etc.) +che hanno come operando un infinito e un altro numero producono +risultati matematicamente ragionevoli. + +Il secondo tipo di valore @`e ``not a number'' [``non @`e un numero''] +scritto in forma abbreviata come NaN.@footnote{Grazie a Michael Brennan +per questa descrizione, che abbiamo parafrasato, e per gli esempi.} + +Questo @`e un valore speciale che risulta da un calcolo che non ha come +risposta un numero reale. In tal caso, i programmi possono o ricevere +un’eccezione di virgola mobile, o restituire NaN come risultato. +Lo standard IEEE 754 consiglia che i sistemi restituiscano NaN. +Alcuni esempi: + +@table @code +@item sqrt(-1) +@iftex +La funzione @math{\sqrt{-1}} +@end iftex +@ifnottex +Questa funzione +@end ifnottex +ha senso nell'insieme dei numeri complessi, +ma non nell'insieme dei numeri reali, +per cui il risultato @`e @code{NaN}. + +@item log(-8) +Il logaritmo di @minus{}8 @`e fuori dal dominio di @code{log()}, +per cui il risultato @`e @code{NaN}. +@end table + +I valori Nan sono strani. In particolare, non possono essere confrontati +con altri numeri in virgola mobile; ogni confronto di questo tipo, eccetto +quello ``non uguale a'', restituisce il valore ``falso''. +I valori NaN sono talmente differenti da altri valori che perfino il +confronto di due valori NaN identici fra loro con @code{!=} restituisce +il valore ``vero''! + +I valori NaN possono anche avere un segno (positivo o negativo), +anche se dipende dall'implementazione quale segno viene restituito +da qualsiasi operazione il cui risultato sia un valore NaN. +Per esempio, su alcuni sistemi la funzione @code{sqrt(-1)} +restituisce un NaN negativo. Su altri sistemi il NaN restituito +@`e invece positivo. + +Quando tali valori vengono generati, @command{gawk} li stampa +come @samp{-nan} o @samp{+nan}, rispettivamente. Anche per +questi valori, @command{gawk} accetta queste stringhe come +dati in input e le converte internamente ai valori loro +assegnati come numeri in virgola mobile. + +Se si desidera approfondire ulteriormente questo argomento, si possono +trovare programmi di test scritti in C, @command{awk} e Python +nella directory @file{awklib/eg/test-programs} disponibile +nella distribuzione di @command{gawk}. +Tali programmi permettono un confronto tra i linguaggi di +programmazione, riguardo al modo con cui vengono trattati +i valori di infinito e quelli NaN. + +@ignore +@c file eg/test-programs/gen-float-table.awk +function eq(left, right) +@{ + return left == right +@} + +function ne(left, right) +@{ + return left != right +@} + +function lt(left, right) +@{ + return left < right +@} + +function le(left, right) +@{ + return left <= right +@} + +function gt(left, right) +@{ + return left > right +@} + +function ge(left, right) +@{ + return left >= right +@} + +BEGIN @{ + nan = sqrt(-1) + inf = -log(0) + split("== != < <= > >=", names) + names[3] = names[3] " " + names[5] = names[5] " " + split("eq ne lt le gt ge", funcs) + + compare[1] = 2.0 + compare[2] = values[1] = -sqrt(-1.0) # nan + compare[3] = values[2] = sqrt(-1.0) # -nan + compare[4] = values[3] = -log(0.0) # inf + compare[5] = values[4] = log(0.0) # -inf + + for (i = 1; i in values; i++) @{ + for (j = 1; j in compare; j++) @{ + for (k = 1; k in names; k++) @{ + the_func = funcs[k] + printf("%g %s %g -> %s\n", + values[i], + names[k], + compare[j], + @@the_func(values[i], compare[j]) ? + "True" : "False"); + @} + printf("\n"); + @} + @} +@} +@c endfile +@end ignore + +@ignore +@c file eg/test-programs/gen-float-table.c +#include <stdio.h> +#include <math.h> +#include <stdbool.h> + +#define def_func(name, op) \ + bool name(double left, double right) @{ \ + return left op right; \ + @} + +def_func(eq, ==) +def_func(ne, !=) +def_func(lt, <) +def_func(le, <=) +def_func(gt, >) +def_func(ge, >=) + +struct @{ + const char *name; + bool (*func)(double left, double right); +@} functions[] = @{ + @{ "==", eq @}, + @{ "!=", ne @}, + @{ "< ", lt @}, + @{ "<=", le @}, + @{ "> ", gt @}, + @{ ">=", ge @}, + @{ 0, 0 @} +@}; + +int main() +@{ + double values[] = @{ + -sqrt(-1), // nan + sqrt(-1), // -nan + -log(0.0), // inf + log(0.0) // -inf + @}; + double compare[] = @{ 2.0, + -sqrt(-1), // nan + sqrt(-1), // -nan + -log(0.0), // inf + log(0.0) // -inf + @}; + + int i, j, k; + + for (i = 0; i < 4; i++) @{ + for (j = 0; j < 5; j++) @{ + for (k = 0; functions[k].name != NULL; k++) @{ + printf("%g %s %g -> %s\n", values[i], + functions[k].name, + compare[j], + functions[k].func(values[i], compare[j]) ? "True" : "False"); + @} + printf("\n"); + @} + @} + + return 0; +@} +@c endfile +@end ignore + +@ignore +@c file eg/test-programs/gen-float-table.py +from math import * + +nan = float('NaN') +inf = float('Inf') + +def eq(left, right): + return left == right + +def ne(left, right): + return left != right + +def lt(left, right): + return left < right + +def le(left, right): + return left <= right + +def gt(left, right): + return left > right + +def ge(left, right): + return left >= right + +func_map = { + "==": eq, + "!=": ne, + "< ": lt, + "<=": le, + "> ": gt, + ">=": ge, +} + +compare = [2.0, nan, -nan, inf, -inf] +values = [nan, -nan, inf, -inf] + +for i in range(len(values)): + for j in range(len(compare)): + for op in func_map: + print("%g %s %g -> %s" % + (values[i], op, compare[j], func_map[op](values[i], compare[j]))) + + print("") +@c endfile +@end ignore + @node Ottenere la precisione @subsection Ottenere la precisione voluta @@ -38023,7 +38368,7 @@ I campi sono: @table @code @item awk_bool_t use_chars; Impostare ad @code{awk_true} se le lunghezze di campo sono specificate in -unit@`a di caratteri potenzialmente multi-byte, oppure impostarlo a +unit@`a di caratteri potenzialmente multibyte, oppure impostarlo a @code{awk_false} se le lunghezze sono espresse in numero di byte. L'efficienza del programma sar@`a maggiore utilizzando la dimensione in byte. @@ -42555,7 +42900,7 @@ con @option{--}. @item L'opzione @option{--source} per combinare codice sorgente immesso nella riga -di comando e codice sorgente proveniente da file di libreria. +di comando e codice sorgente proveniente da librerie di file. @end itemize @end itemize @@ -43057,7 +43402,7 @@ L'opzione @option{-D} attiva il debugger. @item Le opzioni @option{-i} e @option{--include} -caricano dei file di libreria @command{awk}. +caricano delle librerie di file @command{awk}. @item Le opzioni @option{-l} e @option{--load} caricano estensioni dinamiche @@ -44390,7 +44735,7 @@ Il codice sorgente di @command{gawk}, in generale, cerca di aderire, nei limiti del possibile, a degli standard formali. Ci@`o significa che @command{gawk} usa routine di libreria che sono specificate nello standard ISO C e nello standard POSIX per le interfacce dei sistemi operativi. Il codice sorgente di -@command{gawk} richiede l'uso di un compilatore ISO C (standard 1990). +@command{gawk} richiede l'uso di un compilatore ISO C (standard 1999). Molti sistemi Unix non aderiscono completamente n@'e allo standard ISO n@'e a quello POSIX. La sottodirectory @file{missing_d} nella distribuzione di @@ -45411,6 +45756,10 @@ il sito @url{https://sourceforge.net/projects/awka}. Il progetto sembra essere stato congelato; non ci sono state modifiche nel codice sorgente dal 2001 circa. +@item Resuscitare Awka +Questo progetto, disponibile nel sito @uref{https://github.com/noyesno/awka}, +si propone di fissare bug in @command{awka} e di aggiungere nuove funzionalit@`a. + @cindex Beebe, Nelson H.F.@: @cindex @command{pawk} (versione con profilazione di Brian Kernighan @command{awk}) @cindex codice sorgente @subentry @command{pawk} @@ -45464,6 +45813,17 @@ il progetto mette a disposizione questa implementazione. Si possono vedere i singoli file in @uref{https://github.com/joyent/illumos-joyent/blob/master/usr/src/cmd/awk_xpg4}. +@cindex @command{frawk} +@cindex sorgente @subentry codice @subentry @command{frawk} +@cindex codice sorgente @subentry @command{frawk} +@item @command{frawk} +Questo @`e un linguaggio per scrivere programmi corti. +``In prima approssimazione, @`e un'implementazione del linguaggio AWK; +molti comuni programmi @command{awk} producono un output equivalente +quando passati a @command{frawk}.'' Comunque, ha anche numerose e +importanti funzionalit@`a ulteriori. Il codice sorgente @`e disponibile +sul sito @uref{https://github.com/ezrosent/frawk}. + @cindex @command{goawk} @cindex Go @subentry implementazione di @command{awk} @cindex sorgente @subentry @command{goawk} @@ -45490,7 +45850,13 @@ essere un interprete completo, anche se, poich@'e usa funzionalit@`a di Java per l'I/O e per la ricerca di @dfn{regexp}, il linguaggio che supporta @`e differente da @command{awk} POSIX. Ulteriori informazioni sono disponibili sulla -@uref{https://jawk.sourceforge.net, pagina principale del progetto}. +@uref{http://jawk.sourceforge.net, pagina principale del progetto}. + +@item Hoijui's @command{jawk} +Questo progetto, disponibili sul sito +@uref{https://github.com/hoijui/Jawk}, +@`e un altro interpretatore di @command{awk} scritto in Java. +Usa i moderni strumenti di sviluppo software di Java. @item Libmawk @cindex @command{libmawk} (interpretatore) @@ -45504,7 +45870,6 @@ Questo @`e un interprete @command{awk} incorporabile, derivato da @cindex interpretatore @command{awk} incorporabile @subentry codice sorgente @cindex Neacsu, Mircea @item @command{awk} incorporabile di Mircea Neacsu -@item incorporabile, @command{awk}, di Mircea Neacsu Mircea Neacsu ha creato un interpretatore @command{awk} incorporabile, basato su BWK @command{awk}. @`E disponibile nel sito @uref{https://github.com/neacsum/awk}. @@ -45549,6 +45914,9 @@ Wikipedia} su @command{awk} per informazioni su ulteriori versioni. @end table +Un'interessante raccolta di funzioni di libreria @`e disponibile sul sito +@uref{https://github.com/e36freak/awk-libs}. + @node Sommario dell'installazione @appendixsec Sommario diff --git a/doc/it/texinfo.tex b/doc/it/texinfo.tex index 68153132..247f7e24 100644..100755 --- a/doc/it/texinfo.tex +++ b/doc/it/texinfo.tex @@ -3,7 +3,7 @@ % Load plain if necessary, i.e., if running under initex. \expandafter\ifx\csname fmtname\endcsname\relax\input plain\fi % -\def\texinfoversion{2020-10-24.12} +\def\texinfoversion{2020-11-25.18} % % Copyright 1985, 1986, 1988, 1990-2020 Free Software Foundation, Inc. % @@ -248,7 +248,7 @@ \def\bigbreak{\ifnum\lastpenalty<10000\par\ifdim\lastskip<\bigskipamount \removelastskip\penalty-200\bigskip\fi\fi} -% Output routine +% Output routine % % For a final copy, take out the rectangles @@ -588,10 +588,9 @@ \fi } -% @end foo executes the definition of \Efoo. -% But first, it executes a specialized version of \checkenv -% -\parseargdef\end{% + +% @end foo calls \checkenv and executes the definition of \Efoo. +\parseargdef\end{ \if 1\csname iscond.#1\endcsname \else % The general wording of \badenverr may not be ideal. @@ -2689,8 +2688,6 @@ end \definetextfontsizexi -\message{markup,} - % Check if we are currently using a typewriter font. Since all the % Computer Modern typewriter fonts have zero interword stretch (and % shrink), and it is reasonable to expect all typewriter fonts to have @@ -2698,68 +2695,14 @@ end % \def\ifmonospace{\ifdim\fontdimen3\font=0pt } -% Markup style infrastructure. \defmarkupstylesetup\INITMACRO will -% define and register \INITMACRO to be called on markup style changes. -% \INITMACRO can check \currentmarkupstyle for the innermost -% style. - -\let\currentmarkupstyle\empty - -\def\setupmarkupstyle#1{% - \def\currentmarkupstyle{#1}% - \markupstylesetup -} - -\let\markupstylesetup\empty - -\def\defmarkupstylesetup#1{% - \expandafter\def\expandafter\markupstylesetup - \expandafter{\markupstylesetup #1}% - \def#1% -} - -% Markup style setup for left and right quotes. -\defmarkupstylesetup\markupsetuplq{% - \expandafter\let\expandafter \temp - \csname markupsetuplq\currentmarkupstyle\endcsname - \ifx\temp\relax \markupsetuplqdefault \else \temp \fi -} - -\defmarkupstylesetup\markupsetuprq{% - \expandafter\let\expandafter \temp - \csname markupsetuprq\currentmarkupstyle\endcsname - \ifx\temp\relax \markupsetuprqdefault \else \temp \fi -} - { \catcode`\'=\active \catcode`\`=\active -\gdef\markupsetuplqdefault{\let`\lq} -\gdef\markupsetuprqdefault{\let'\rq} - -\gdef\markupsetcodequoteleft{\let`\codequoteleft} -\gdef\markupsetcodequoteright{\let'\codequoteright} +\gdef\setcodequotes{\let`\codequoteleft \let'\codequoteright} +\gdef\setregularquotes{\let`\lq \let'\rq} } -\let\markupsetuplqcode \markupsetcodequoteleft -\let\markupsetuprqcode \markupsetcodequoteright -% -\let\markupsetuplqexample \markupsetcodequoteleft -\let\markupsetuprqexample \markupsetcodequoteright -% -\let\markupsetuplqkbd \markupsetcodequoteleft -\let\markupsetuprqkbd \markupsetcodequoteright -% -\let\markupsetuplqsamp \markupsetcodequoteleft -\let\markupsetuprqsamp \markupsetcodequoteright -% -\let\markupsetuplqverb \markupsetcodequoteleft -\let\markupsetuprqverb \markupsetcodequoteright -% -\let\markupsetuplqverbatim \markupsetcodequoteleft -\let\markupsetuprqverbatim \markupsetcodequoteright - % Allow an option to not use regular directed right quote/apostrophe % (char 0x27), but instead the undirected quote from cmtt (char 0x0d). % The undirected quote is ugly, so don't make it the default, but it @@ -2922,7 +2865,7 @@ end } % @samp. -\def\samp#1{{\setupmarkupstyle{samp}\lq\tclose{#1}\rq\null}} +\def\samp#1{{\setcodequotes\lq\tclose{#1}\rq\null}} % @indicateurl is \samp, that is, with quotes. \let\indicateurl=\samp @@ -2965,8 +2908,7 @@ end \global\let'=\rq \global\let`=\lq % default definitions % \global\def\code{\begingroup - \setupmarkupstyle{code}% - % The following should really be moved into \setupmarkupstyle handlers. + \setcodequotes \catcode\dashChar=\active \catcode\underChar=\active \ifallowcodebreaks \let-\codedash @@ -3120,7 +3062,7 @@ end \urefcatcodes % \global\def\urefcode{\begingroup - \setupmarkupstyle{code}% + \setcodequotes \urefcatcodes \let&\urefcodeamp \let.\urefcodedot @@ -3241,8 +3183,8 @@ end \def\kbdsub#1#2#3\par{% \def\one{#1}\def\three{#3}\def\threex{??}% \ifx\one\xkey\ifx\threex\three \key{#2}% - \else{\tclose{\kbdfont\setupmarkupstyle{kbd}\look}}\fi - \else{\tclose{\kbdfont\setupmarkupstyle{kbd}\look}}\fi + \else{\tclose{\kbdfont\setcodequotes\look}}\fi + \else{\tclose{\kbdfont\setcodequotes\look}}\fi } % definition of @key that produces a lozenge. Doesn't adjust to text size. @@ -3259,7 +3201,7 @@ end % monospace, don't change it; that way, we respect @kbdinputstyle. But % if it isn't monospace, then use \tt. % -\def\key#1{{\setupmarkupstyle{key}% +\def\key#1{{\setregularquotes \nohyphenation \ifmonospace\else\tt\fi #1}\null} @@ -3389,16 +3331,20 @@ end {\obeylines \globaldefs=1 \envdef\displaymath{% -\tex +\tex% \def\thisenv{\displaymath}% +\begingroup\let\end\displaymathend% $$% } -\def\Edisplaymath{$$ +\def\displaymathend{$$\endgroup\end}% + +\def\Edisplaymath{% \def\thisenv{\tex}% \end tex }} + % @inlinefmt{FMTNAME,PROCESSED-TEXT} and @inlineraw{FMTNAME,RAW-TEXT}. % Ignore unless FMTNAME == tex; then it is like @iftex and @tex, % except specified as a normal braced arg, so no newlines to worry about. @@ -7163,7 +7109,7 @@ might help (with 'rm \jobname.?? \jobname.??s')% % But \@ or @@ will get a plain @ character. \envdef\tex{% - \setupmarkupstyle{tex}% + \setregularquotes \catcode `\\=0 \catcode `\{=1 \catcode `\}=2 \catcode `\$=3 \catcode `\&=4 \catcode `\#=6 \catcode `\^=7 \catcode `\_=8 \catcode `\~=\active \let~=\tie @@ -7389,7 +7335,7 @@ might help (with 'rm \jobname.?? \jobname.??s')% % If you want all examples etc. small: @set dispenvsize small. % If you want even small examples the full size: @set dispenvsize nosmall. % This affects the following displayed environments: -% @example, @display, @format, @lisp +% @example, @display, @format, @lisp, @verbatim % \def\smallword{small} \def\nosmallword{nosmall} @@ -7435,9 +7381,9 @@ might help (with 'rm \jobname.?? \jobname.??s')% % \maketwodispenvdef{lisp}{example}{% \nonfillstart - \tt\setupmarkupstyle{example}% + \tt\setcodequotes \let\kbdfont = \kbdexamplefont % Allow @kbd to do something special. - \gobble % eat return + \parsearg\gobble } % @display/@smalldisplay: same as @lisp except keep current font. % @@ -7595,7 +7541,7 @@ might help (with 'rm \jobname.?? \jobname.??s')% \def\setupverb{% \tt % easiest (and conventionally used) font for verbatim \def\par{\leavevmode\endgraf}% - \setupmarkupstyle{verb}% + \setcodequotes \tabeightspaces % Respect line breaks, % print special symbols as themselves, and @@ -7636,7 +7582,7 @@ might help (with 'rm \jobname.?? \jobname.??s')% \tt % easiest (and conventionally used) font for verbatim \def\par{\egroup\leavevmode\box\verbbox\endgraf\starttabbox}% \tabexpand - \setupmarkupstyle{verbatim}% + \setcodequotes % Respect line breaks, % print special symbols as themselves, and % make each space count. @@ -8055,7 +8001,7 @@ might help (with 'rm \jobname.?? \jobname.??s')% % leave the code in, but it's strange for @var to lead to typewriter. % Nowadays we recommend @code, since the difference between a ttsl hyphen % and a tt hyphen is pretty tiny. @code also disables ?` !`. - \def\var##1{{\setupmarkupstyle{var}\ttslanted{##1}}}% + \def\var##1{{\setregularquotes\ttslanted{##1}}}% #1% \sl\hyphenchar\font=45 } @@ -8164,11 +8110,18 @@ might help (with 'rm \jobname.?? \jobname.??s')% } \fi +\let\E=\expandafter + % Used at the time of macro expansion. % Argument is macro body with arguments substituted \def\scanmacro#1{% \newlinechar`\^^M - \def\xeatspaces{\eatspaces}% + % expand the expansion of \eatleadingcr twice to maybe remove a leading + % newline (and \else and \fi tokens), then call \eatspaces on the result. + \def\xeatspaces##1{% + \E\E\E\E\E\E\E\eatspaces\E\E\E\E\E\E\E{\eatleadingcr##1% + }}% + \def\xempty##1{}% % % Process the macro body under the current catcode regime. \scantokens{#1@comment}% @@ -8221,6 +8174,11 @@ might help (with 'rm \jobname.?? \jobname.??s')% \unbrace{\gdef\trim@@@ #1 } #2@{#1} } +{\catcode`\^^M=\other% +\gdef\eatleadingcr#1{\if\noexpand#1\noexpand^^M\else\E#1\fi}}% +% Warning: this won't work for a delimited argument +% or for an empty argument + % Trim a single trailing ^^M off a string. {\catcode`\^^M=\other \catcode`\Q=3% \gdef\eatcr #1{\eatcra #1Q^^MQ}% @@ -8387,6 +8345,7 @@ might help (with 'rm \jobname.?? \jobname.??s')% \let\hash\relax % \hash is redefined to `#' later to get it into definitions \let\xeatspaces\relax + \let\xempty\relax \parsemargdefxxx#1,;,% \ifnum\paramno<10\relax\else \paramno0\relax @@ -8398,9 +8357,11 @@ might help (with 'rm \jobname.?? \jobname.??s')% \else \let\next=\parsemargdefxxx \advance\paramno by 1 \expandafter\edef\csname macarg.\eatspaces{#1}\endcsname - {\xeatspaces{\hash\the\paramno}}% + {\xeatspaces{\hash\the\paramno\noexpand\xempty{}}}% \edef\paramlist{\paramlist\hash\the\paramno,}% \fi\next} +% the \xempty{} is to give \eatleadingcr an argument in the case of an +% empty macro argument. % \parsemacbody, \parsermacbody % @@ -9126,20 +9087,22 @@ might help (with 'rm \jobname.?? \jobname.??s')% % output the `[mynode]' via the macro below so it can be overridden. \xrefprintnodename\printedrefname % - % But we always want a comma and a space: - ,\space - % - % output the `page 3'. - \turnoffactive \putwordpage\tie\refx{#1-pg}{}% - % Add a , if xref followed by a space - \if\space\noexpand\tokenafterxref ,% - \else\ifx\ \tokenafterxref ,% @TAB - \else\ifx\*\tokenafterxref ,% @* - \else\ifx\ \tokenafterxref ,% @SPACE - \else\ifx\ - \tokenafterxref ,% @NL - \else\ifx\tie\tokenafterxref ,% @tie - \fi\fi\fi\fi\fi\fi + \expandafter\ifx\csname SETtxiomitxrefpg\endcsname\relax + % But we always want a comma and a space: + ,\space + % + % output the `page 3'. + \turnoffactive \putwordpage\tie\refx{#1-pg}{}% + % Add a , if xref followed by a space + \if\space\noexpand\tokenafterxref ,% + \else\ifx\ \tokenafterxref ,% @TAB + \else\ifx\*\tokenafterxref ,% @* + \else\ifx\ \tokenafterxref ,% @SPACE + \else\ifx\ + \tokenafterxref ,% @NL + \else\ifx\tie\tokenafterxref ,% @tie + \fi\fi\fi\fi\fi\fi + \fi \fi\fi \fi \endlink @@ -9569,7 +9532,7 @@ might help (with 'rm \jobname.?? \jobname.??s')% \def\imagexxx#1,#2,#3,#4,#5,#6\finish{\begingroup \catcode`\^^M = 5 % in case we're inside an example \normalturnoffactive % allow _ et al. in names - \def\xprocessmacroarg{\eatspaces}% in case we are being used via a macro + \makevalueexpandable % If the image is by itself, center it. \ifvmode \imagevmodetrue @@ -11622,7 +11585,7 @@ directory should work if nowhere else does.} \let> = \activegtr \let~ = \activetilde \let^ = \activehat - \markupsetuplqdefault \markupsetuprqdefault + \setregularquotes \let\b = \strong \let\i = \smartitalic % in principle, all other definitions in \tex have to be undone too. @@ -11681,8 +11644,7 @@ directory should work if nowhere else does.} @let|=@normalverticalbar @let~=@normaltilde @let\=@ttbackslash - @markupsetuplqdefault - @markupsetuprqdefault + @setregularquotes @unsepspaces } } @@ -11775,8 +11737,7 @@ directory should work if nowhere else does.} @c Do this last of all since we use ` in the previous @catcode assignments. @catcode`@'=@active @catcode`@`=@active -@markupsetuplqdefault -@markupsetuprqdefault +@setregularquotes @c Local variables: @c eval: (add-hook 'before-save-hook 'time-stamp) diff --git a/doc/wordlist b/doc/wordlist index 95ca8a75..be7655ec 100644 --- a/doc/wordlist +++ b/doc/wordlist @@ -321,6 +321,7 @@ NR NT NUMCUR NaN +NaNs Nachum Neacsu Neacsu's @@ -25,10 +25,8 @@ */ #include "awk.h" +#include <math.h> -extern double pow(double x, double y); -extern double modf(double x, double *yp); -extern double fmod(double x, double y); NODE **fcall_list = NULL; long fcall_count = 0; int currule = 0; @@ -1521,18 +1519,17 @@ eval_condition(NODE *t) return boolval(t); } -typedef enum { - SCALAR_EQ_NEQ, - SCALAR_RELATIONAL -} scalar_cmp_t; +static bool cmp_doubles(const NODE *t1, const NODE *t2, scalar_cmp_t comparison_type); +extern bool mpg_cmp_as_numbers(const NODE *t1, const NODE *t2, scalar_cmp_t comparison_type); /* cmp_scalars -- compare two nodes on the stack */ -static inline int +static bool cmp_scalars(scalar_cmp_t comparison_type) { NODE *t1, *t2; int di; + bool ret; t2 = POP_SCALAR(); t1 = TOP(); @@ -1540,12 +1537,91 @@ cmp_scalars(scalar_cmp_t comparison_type) DEREF(t2); fatal(_("attempt to use array `%s' in a scalar context"), array_vname(t1)); } - di = cmp_nodes(t1, t2, comparison_type == SCALAR_EQ_NEQ); + + if ((t1->flags & STRING) != 0 || (t2->flags & STRING) != 0) { + bool use_strcmp = (comparison_type == SCALAR_EQ || comparison_type == SCALAR_NEQ); + di = cmp_nodes(t1, t2, use_strcmp); + + switch (comparison_type) { + case SCALAR_EQ: + ret = (di == 0); + break; + case SCALAR_NEQ: + ret = (di != 0); + break; + case SCALAR_LT: + ret = (di < 0); + break; + case SCALAR_LE: + ret = (di <= 0); + break; + case SCALAR_GT: + ret = (di > 0); + break; + case SCALAR_GE: + ret = (di >= 0); + break; + } + } else { + fixtype(t1); + fixtype(t2); + +#ifdef HAVE_MPFR + if (do_mpfr) + ret = mpg_cmp_as_numbers(t1, t2, comparison_type); + else +#endif + ret = cmp_doubles(t1, t2, comparison_type); + } + DEREF(t1); DEREF(t2); - return di; + return ret; } + +/* cmp_doubles --- compare two doubles */ + +static bool +cmp_doubles(const NODE *t1, const NODE *t2, scalar_cmp_t comparison_type) +{ + /* + * This routine provides numeric comparisons that should work + * the same as in C. It should NOT be used for sorting. + */ + + bool t1_nan = isnan(t1->numbr); + bool t2_nan = isnan(t2->numbr); + int ret; + + if ((t1_nan || t2_nan) && comparison_type != SCALAR_NEQ) + return false; + + switch (comparison_type) { + case SCALAR_EQ: + ret = (t1->numbr == t2->numbr); + break; + case SCALAR_NEQ: + ret = (t1->numbr != t2->numbr); + break; + case SCALAR_LT: + ret = (t1->numbr < t2->numbr); + break; + case SCALAR_LE: + ret = (t1->numbr <= t2->numbr); + break; + case SCALAR_GT: + ret = (t1->numbr > t2->numbr); + break; + case SCALAR_GE: + ret = (t1->numbr >= t2->numbr); + break; + } + + return ret; +} + + /* op_assign --- assignment operators excluding = */ static void diff --git a/interpret.h b/interpret.h index 739f81eb..93a50f24 100644 --- a/interpret.h +++ b/interpret.h @@ -486,37 +486,37 @@ uninitialized_scalar: break; case Op_equal: - r = node_Boolean[cmp_scalars(SCALAR_EQ_NEQ) == 0]; + r = node_Boolean[cmp_scalars(SCALAR_EQ)]; UPREF(r); REPLACE(r); break; case Op_notequal: - r = node_Boolean[cmp_scalars(SCALAR_EQ_NEQ) != 0]; + r = node_Boolean[cmp_scalars(SCALAR_NEQ)]; UPREF(r); REPLACE(r); break; case Op_less: - r = node_Boolean[cmp_scalars(SCALAR_RELATIONAL) < 0]; + r = node_Boolean[cmp_scalars(SCALAR_LT)]; UPREF(r); REPLACE(r); break; case Op_greater: - r = node_Boolean[cmp_scalars(SCALAR_RELATIONAL) > 0]; + r = node_Boolean[cmp_scalars(SCALAR_GT)]; UPREF(r); REPLACE(r); break; case Op_leq: - r = node_Boolean[cmp_scalars(SCALAR_RELATIONAL) <= 0]; + r = node_Boolean[cmp_scalars(SCALAR_LE)]; UPREF(r); REPLACE(r); break; case Op_geq: - r = node_Boolean[cmp_scalars(SCALAR_RELATIONAL) >= 0]; + r = node_Boolean[cmp_scalars(SCALAR_GE)]; UPREF(r); REPLACE(r); break; @@ -476,6 +476,50 @@ mpg_cmp(const NODE *t1, const NODE *t2) return cmp_awknums(t1, t2); } +/* mpg_cmp_as_numbers --- compare two numbers, similar to doubles */ + +bool +mpg_cmp_as_numbers(const NODE *t1, const NODE *t2, scalar_cmp_t comparison_type) +{ + /* + * This routine provides numeric comparisons that should work + * the same as in C. It should NOT be used for sorting. + */ + + bool t1_nan = mpfr_nan_p(t1->mpg_numbr); + bool t2_nan = mpfr_nan_p(t2->mpg_numbr); + int ret; + + // MPFR is different than native doubles... + if (t1_nan || t2_nan) + return comparison_type == SCALAR_NEQ; + + int di = mpg_cmp(t1, t2); + + switch (comparison_type) { + case SCALAR_EQ: + ret = (di == 0); + break; + case SCALAR_NEQ: + ret = (di != 0); + break; + case SCALAR_LT: + ret = (di < 0); + break; + case SCALAR_LE: + ret = (di <= 0); + break; + case SCALAR_GT: + ret = (di > 0); + break; + case SCALAR_GE: + ret = (di >= 0); + break; + } + + return ret; +} + /* * mpg_update_var --- update NR or FNR. @@ -370,7 +370,7 @@ int cmp_awknums(const NODE *t1, const NODE *t2) { /* - * This routine is also used to sort numeric array indices or values. + * This routine is used to sort numeric array indices or values. * For the purposes of sorting, NaN is considered greater than * any other value, and all NaN values are considered equivalent and equal. * This isn't in compliance with IEEE standard, but compliance w.r.t. NaN @@ -390,7 +390,6 @@ cmp_awknums(const NODE *t1, const NODE *t2) return 1; } - /* make_str_node --- make a string node */ NODE * |