diff options
-rw-r--r-- | ChangeLog | 13 | ||||
-rw-r--r-- | NEWS | 8 | ||||
-rw-r--r-- | awk.h | 9 | ||||
-rw-r--r-- | builtin.c | 4 | ||||
-rw-r--r-- | doc/ChangeLog | 6 | ||||
-rw-r--r-- | doc/gawk.info | 1276 | ||||
-rw-r--r-- | doc/gawk.texi | 74 | ||||
-rw-r--r-- | doc/gawktexi.in | 74 | ||||
-rw-r--r-- | doc/wordlist | 2 | ||||
-rw-r--r-- | eval.c | 96 | ||||
-rw-r--r-- | interpret.h | 12 | ||||
-rw-r--r-- | mpfr.c | 44 | ||||
-rw-r--r-- | node.c | 5 |
13 files changed, 949 insertions, 674 deletions
@@ -1,5 +1,18 @@ 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 --------------------------- @@ -1574,6 +1574,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); @@ -4293,11 +4293,11 @@ format_nan_inf(NODE *n, char format) return NULL; else if (is_mpg_float(n)) { if (mpfr_nan_p(n->mpg_numbr)) { - strcpy(buf, mpfr_sgn(n->mpg_numbr) < 0 ? "-nan" : "+nan"); + strcpy(buf, mpfr_signbit(n->mpg_numbr) ? "-nan" : "+nan"); 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 f2afd299..13b6cdf3 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,9 @@ +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-10-31 Arnold D. Robbins <arnold@skeeve.com> * texinfo.tex: Updated from GNULIB. diff --git a/doc/gawk.info b/doc/gawk.info index 03c3a883..244bbd8c 100644 --- a/doc/gawk.info +++ b/doc/gawk.info @@ -546,6 +546,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. @@ -6926,8 +6927,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 @@ -12819,7 +12820,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()' @@ -24153,18 +24154,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. @@ -24223,11 +24216,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 @@ -24320,6 +24308,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 @@ -24384,7 +24373,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 .......................... @@ -24432,6 +24421,58 @@ 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 infinity. + + 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. + + ---------- 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 @@ -37934,602 +37975,603 @@ Index Tag Table: Node: Top1200 -Node: Foreword344474 -Node: Foreword448916 -Node: Preface50448 -Ref: Preface-Footnote-153307 -Ref: Preface-Footnote-253416 -Ref: Preface-Footnote-353650 -Node: History53792 -Node: Names56144 -Ref: Names-Footnote-157248 -Node: This Manual57395 -Ref: This Manual-Footnote-164034 -Node: Conventions64134 -Node: Manual History66503 -Ref: Manual History-Footnote-169500 -Ref: Manual History-Footnote-269541 -Node: How To Contribute69615 -Node: Acknowledgments70541 -Node: Getting Started75478 -Node: Running gawk77917 -Node: One-shot79107 -Node: Read Terminal80370 -Node: Long82363 -Node: Executable Scripts83876 -Ref: Executable Scripts-Footnote-186509 -Node: Comments86612 -Node: Quoting89096 -Node: DOS Quoting94622 -Node: Sample Data Files96678 -Node: Very Simple99273 -Node: Two Rules105375 -Node: More Complex107260 -Node: Statements/Lines109592 -Ref: Statements/Lines-Footnote-1114076 -Node: Other Features114341 -Node: When115277 -Ref: When-Footnote-1117031 -Node: Intro Summary117096 -Node: Invoking Gawk117980 -Node: Command Line119494 -Node: Options120292 -Ref: Options-Footnote-1138206 -Ref: Options-Footnote-2138437 -Node: Other Arguments138462 -Node: Naming Standard Input142473 -Node: Environment Variables143683 -Node: AWKPATH Variable144241 -Ref: AWKPATH Variable-Footnote-1147653 -Ref: AWKPATH Variable-Footnote-2147687 -Node: AWKLIBPATH Variable148058 -Ref: AWKLIBPATH Variable-Footnote-1149755 -Node: Other Environment Variables150130 -Node: Exit Status153951 -Node: Include Files154628 -Node: Loading Shared Libraries158318 -Node: Obsolete159746 -Node: Undocumented160438 -Node: Invoking Summary160735 -Node: Regexp163576 -Node: Regexp Usage165030 -Node: Escape Sequences167067 -Node: Regexp Operators173308 -Node: Regexp Operator Details173793 -Ref: Regexp Operator Details-Footnote-1180225 -Node: Interval Expressions180372 -Ref: Interval Expressions-Footnote-1181793 -Node: Bracket Expressions181891 -Ref: table-char-classes184367 -Node: Leftmost Longest187693 -Node: Computed Regexps188996 -Node: GNU Regexp Operators192423 -Node: Case-sensitivity196160 -Ref: Case-sensitivity-Footnote-1199026 -Ref: Case-sensitivity-Footnote-2199261 -Node: Regexp Summary199369 -Node: Reading Files200835 -Node: Records203104 -Node: awk split records204179 -Node: gawk split records209454 -Ref: gawk split records-Footnote-1214187 -Node: Fields214224 -Node: Nonconstant Fields216965 -Ref: Nonconstant Fields-Footnote-1219201 -Node: Changing Fields219405 -Node: Field Separators225436 -Node: Default Field Splitting228134 -Node: Regexp Field Splitting229252 -Node: Single Character Fields232605 -Node: Command Line Field Separator233665 -Node: Full Line Fields236883 -Ref: Full Line Fields-Footnote-1238405 -Ref: Full Line Fields-Footnote-2238451 -Node: Field Splitting Summary238552 -Node: Constant Size240626 -Node: Fixed width data241358 -Node: Skipping intervening244825 -Node: Allowing trailing data245623 -Node: Fields with fixed data246660 -Node: Splitting By Content248178 -Ref: Splitting By Content-Footnote-1251961 -Node: More CSV252124 -Node: Testing field creation253434 -Node: Multiple Line255059 -Node: Getline261336 -Node: Plain Getline263805 -Node: Getline/Variable266378 -Node: Getline/File267529 -Node: Getline/Variable/File268917 -Ref: Getline/Variable/File-Footnote-1270522 -Node: Getline/Pipe270610 -Node: Getline/Variable/Pipe273314 -Node: Getline/Coprocess274449 -Node: Getline/Variable/Coprocess275716 -Node: Getline Notes276458 -Node: Getline Summary279255 -Ref: table-getline-variants279679 -Node: Read Timeout280427 -Ref: Read Timeout-Footnote-1284333 -Node: Retrying Input284391 -Node: Command-line directories285590 -Node: Input Summary286496 -Node: Input Exercises289668 -Node: Printing290102 -Node: Print291936 -Node: Print Examples293393 -Node: Output Separators296173 -Node: OFMT298190 -Node: Printf299546 -Node: Basic Printf300331 -Node: Control Letters301905 -Node: Format Modifiers307069 -Node: Printf Examples313084 -Node: Redirection315570 -Node: Special FD322411 -Ref: Special FD-Footnote-1325579 -Node: Special Files325653 -Node: Other Inherited Files326270 -Node: Special Network327271 -Node: Special Caveats328131 -Node: Close Files And Pipes329080 -Ref: table-close-pipe-return-values335987 -Ref: Close Files And Pipes-Footnote-1336800 -Ref: Close Files And Pipes-Footnote-2336948 -Node: Nonfatal337100 -Node: Output Summary339438 -Node: Output Exercises340660 -Node: Expressions341339 -Node: Values342527 -Node: Constants343205 -Node: Scalar Constants343896 -Ref: Scalar Constants-Footnote-1346406 -Node: Nondecimal-numbers346656 -Node: Regexp Constants349657 -Node: Using Constant Regexps350183 -Node: Standard Regexp Constants350805 -Node: Strong Regexp Constants353993 -Node: Variables357005 -Node: Using Variables357662 -Node: Assignment Options359572 -Node: Conversion362043 -Node: Strings And Numbers362567 -Ref: Strings And Numbers-Footnote-1365630 -Node: Locale influences conversions365739 -Ref: table-locale-affects368497 -Node: All Operators369115 -Node: Arithmetic Ops369744 -Node: Concatenation372460 -Ref: Concatenation-Footnote-1375307 -Node: Assignment Ops375414 -Ref: table-assign-ops380405 -Node: Increment Ops381718 -Node: Truth Values and Conditions385178 -Node: Truth Values386252 -Node: Typing and Comparison387300 -Node: Variable Typing388120 -Ref: Variable Typing-Footnote-1394583 -Ref: Variable Typing-Footnote-2394655 -Node: Comparison Operators394732 -Ref: table-relational-ops395151 -Node: POSIX String Comparison398646 -Ref: POSIX String Comparison-Footnote-1400341 -Ref: POSIX String Comparison-Footnote-2400480 -Node: Boolean Ops400564 -Ref: Boolean Ops-Footnote-1405046 -Node: Conditional Exp405138 -Node: Function Calls406874 -Node: Precedence410751 -Node: Locales414410 -Node: Expressions Summary416042 -Node: Patterns and Actions418615 -Node: Pattern Overview419735 -Node: Regexp Patterns421412 -Node: Expression Patterns421954 -Node: Ranges425735 -Node: BEGIN/END428843 -Node: Using BEGIN/END429604 -Ref: Using BEGIN/END-Footnote-1432358 -Node: I/O And BEGIN/END432464 -Node: BEGINFILE/ENDFILE434777 -Node: Empty438008 -Node: Using Shell Variables438325 -Node: Action Overview440599 -Node: Statements442924 -Node: If Statement444772 -Node: While Statement446267 -Node: Do Statement448295 -Node: For Statement449443 -Node: Switch Statement452614 -Node: Break Statement455055 -Node: Continue Statement457147 -Node: Next Statement458974 -Node: Nextfile Statement461357 -Node: Exit Statement464009 -Node: Built-in Variables466412 -Node: User-modified467545 -Node: Auto-set475312 -Ref: Auto-set-Footnote-1492119 -Ref: Auto-set-Footnote-2492325 -Node: ARGC and ARGV492381 -Node: Pattern Action Summary496594 -Node: Arrays499024 -Node: Array Basics500353 -Node: Array Intro501197 -Ref: figure-array-elements503172 -Ref: Array Intro-Footnote-1505876 -Node: Reference to Elements506004 -Node: Assigning Elements508468 -Node: Array Example508959 -Node: Scanning an Array510718 -Node: Controlling Scanning513740 -Ref: Controlling Scanning-Footnote-1520196 -Node: Numeric Array Subscripts520512 -Node: Uninitialized Subscripts522696 -Node: Delete524315 -Ref: Delete-Footnote-1527067 -Node: Multidimensional527124 -Node: Multiscanning530219 -Node: Arrays of Arrays531810 -Node: Arrays Summary536578 -Node: Functions538671 -Node: Built-in539709 -Node: Calling Built-in540790 -Node: Numeric Functions542786 -Ref: Numeric Functions-Footnote-1546814 -Ref: Numeric Functions-Footnote-2547462 -Ref: Numeric Functions-Footnote-3547510 -Node: String Functions547782 -Ref: String Functions-Footnote-1571923 -Ref: String Functions-Footnote-2572051 -Ref: String Functions-Footnote-3572299 -Node: Gory Details572386 -Ref: table-sub-escapes574177 -Ref: table-sub-proposed575696 -Ref: table-posix-sub577059 -Ref: table-gensub-escapes578600 -Ref: Gory Details-Footnote-1579423 -Node: I/O Functions579577 -Ref: table-system-return-values586031 -Ref: I/O Functions-Footnote-1588111 -Ref: I/O Functions-Footnote-2588259 -Node: Time Functions588379 -Ref: Time Functions-Footnote-1599050 -Ref: Time Functions-Footnote-2599118 -Ref: Time Functions-Footnote-3599276 -Ref: Time Functions-Footnote-4599387 -Ref: Time Functions-Footnote-5599499 -Ref: Time Functions-Footnote-6599726 -Node: Bitwise Functions599992 -Ref: table-bitwise-ops600586 -Ref: Bitwise Functions-Footnote-1606649 -Ref: Bitwise Functions-Footnote-2606822 -Node: Type Functions607013 -Node: I18N Functions609876 -Node: User-defined611527 -Node: Definition Syntax612339 -Ref: Definition Syntax-Footnote-1618033 -Node: Function Example618104 -Ref: Function Example-Footnote-1621026 -Node: Function Calling621048 -Node: Calling A Function621636 -Node: Variable Scope622594 -Node: Pass By Value/Reference625588 -Node: Function Caveats628232 -Ref: Function Caveats-Footnote-1630279 -Node: Return Statement630399 -Node: Dynamic Typing633378 -Node: Indirect Calls634308 -Ref: Indirect Calls-Footnote-1644560 -Node: Functions Summary644688 -Node: Library Functions647393 -Ref: Library Functions-Footnote-1651000 -Ref: Library Functions-Footnote-2651143 -Node: Library Names651314 -Ref: Library Names-Footnote-1654981 -Ref: Library Names-Footnote-2655204 -Node: General Functions655290 -Node: Strtonum Function656393 -Node: Assert Function659415 -Node: Round Function662741 -Node: Cliff Random Function664281 -Node: Ordinal Functions665297 -Ref: Ordinal Functions-Footnote-1668360 -Ref: Ordinal Functions-Footnote-2668612 -Node: Join Function668822 -Ref: Join Function-Footnote-1670592 -Node: Getlocaltime Function670792 -Node: Readfile Function674534 -Node: Shell Quoting676511 -Node: Data File Management677912 -Node: Filetrans Function678544 -Node: Rewind Function682640 -Node: File Checking684549 -Ref: File Checking-Footnote-1685883 -Node: Empty Files686084 -Node: Ignoring Assigns688063 -Node: Getopt Function689613 -Ref: Getopt Function-Footnote-1704824 -Node: Passwd Functions705024 -Ref: Passwd Functions-Footnote-1713863 -Node: Group Functions713951 -Ref: Group Functions-Footnote-1721849 -Node: Walking Arrays722056 -Node: Library Functions Summary725064 -Node: Library Exercises726470 -Node: Sample Programs726935 -Node: Running Examples727705 -Node: Clones728433 -Node: Cut Program729657 -Node: Egrep Program739586 -Node: Id Program748597 -Node: Split Program758544 -Ref: Split Program-Footnote-1768318 -Node: Tee Program768491 -Node: Uniq Program771281 -Node: Wc Program778845 -Node: Bytes vs. Characters779242 -Node: Using extensions780790 -Node: wc program781548 -Node: Miscellaneous Programs786413 -Node: Dupword Program787626 -Node: Alarm Program789656 -Node: Translate Program794511 -Ref: Translate Program-Footnote-1799076 -Node: Labels Program799346 -Ref: Labels Program-Footnote-1802697 -Node: Word Sorting802781 -Node: History Sorting806853 -Node: Extract Program809078 -Node: Simple Sed817132 -Node: Igawk Program820206 -Ref: Igawk Program-Footnote-1834537 -Ref: Igawk Program-Footnote-2834739 -Ref: Igawk Program-Footnote-3834861 -Node: Anagram Program834976 -Node: Signature Program838038 -Node: Programs Summary839285 -Node: Programs Exercises840499 -Ref: Programs Exercises-Footnote-1844629 -Node: Advanced Features844715 -Node: Nondecimal Data846705 -Node: Array Sorting848296 -Node: Controlling Array Traversal848996 -Ref: Controlling Array Traversal-Footnote-1857364 -Node: Array Sorting Functions857482 -Ref: Array Sorting Functions-Footnote-1862573 -Node: Two-way I/O862769 -Ref: Two-way I/O-Footnote-1870490 -Ref: Two-way I/O-Footnote-2870677 -Node: TCP/IP Networking870759 -Node: Profiling873877 -Node: Advanced Features Summary883191 -Node: Internationalization885035 -Node: I18N and L10N886515 -Node: Explaining gettext887202 -Ref: Explaining gettext-Footnote-1893094 -Ref: Explaining gettext-Footnote-2893279 -Node: Programmer i18n893444 -Ref: Programmer i18n-Footnote-1898393 -Node: Translator i18n898442 -Node: String Extraction899236 -Ref: String Extraction-Footnote-1900368 -Node: Printf Ordering900454 -Ref: Printf Ordering-Footnote-1903240 -Node: I18N Portability903304 -Ref: I18N Portability-Footnote-1905760 -Node: I18N Example905823 -Ref: I18N Example-Footnote-1909098 -Ref: I18N Example-Footnote-2909171 -Node: Gawk I18N909280 -Node: I18N Summary909929 -Node: Debugger911270 -Node: Debugging912270 -Node: Debugging Concepts912711 -Node: Debugging Terms914520 -Node: Awk Debugging917095 -Ref: Awk Debugging-Footnote-1918040 -Node: Sample Debugging Session918172 -Node: Debugger Invocation918706 -Node: Finding The Bug920092 -Node: List of Debugger Commands926566 -Node: Breakpoint Control927899 -Node: Debugger Execution Control931593 -Node: Viewing And Changing Data934955 -Node: Execution Stack938496 -Node: Debugger Info940133 -Node: Miscellaneous Debugger Commands944204 -Node: Readline Support949266 -Node: Limitations950162 -Node: Debugging Summary952716 -Node: Namespaces953995 -Node: Global Namespace955106 -Node: Qualified Names956504 -Node: Default Namespace957503 -Node: Changing The Namespace958244 -Node: Naming Rules959858 -Node: Internal Name Management961706 -Node: Namespace Example962748 -Node: Namespace And Features965310 -Node: Namespace Summary966745 -Node: Arbitrary Precision Arithmetic968222 -Node: Computer Arithmetic969709 -Ref: table-numeric-ranges973475 -Ref: table-floating-point-ranges973968 -Ref: Computer Arithmetic-Footnote-1974626 -Node: Math Definitions974683 -Ref: table-ieee-formats977999 -Ref: Math Definitions-Footnote-1978602 -Node: MPFR features978707 -Node: FP Math Caution980425 -Ref: FP Math Caution-Footnote-1981497 -Node: Inexactness of computations981866 -Node: Inexact representation982826 -Node: Comparing FP Values984186 -Node: Errors accumulate985427 -Node: Getting Accuracy986860 -Node: Try To Round989570 -Node: Setting precision990469 -Ref: table-predefined-precision-strings991166 -Node: Setting the rounding mode992996 -Ref: table-gawk-rounding-modes993370 -Ref: Setting the rounding mode-Footnote-1997301 -Node: Arbitrary Precision Integers997480 -Ref: Arbitrary Precision Integers-Footnote-11000655 -Node: Checking for MPFR1000804 -Node: POSIX Floating Point Problems1002278 -Ref: POSIX Floating Point Problems-Footnote-11006563 -Node: Floating point summary1006601 -Node: Dynamic Extensions1008791 -Node: Extension Intro1010344 -Node: Plugin License1011610 -Node: Extension Mechanism Outline1012407 -Ref: figure-load-extension1012846 -Ref: figure-register-new-function1014411 -Ref: figure-call-new-function1015503 -Node: Extension API Description1017565 -Node: Extension API Functions Introduction1019278 -Ref: table-api-std-headers1021114 -Node: General Data Types1025363 -Ref: General Data Types-Footnote-11033993 -Node: Memory Allocation Functions1034292 -Ref: Memory Allocation Functions-Footnote-11038793 -Node: Constructor Functions1038892 -Node: API Ownership of MPFR and GMP Values1042358 -Node: Registration Functions1043671 -Node: Extension Functions1044371 -Node: Exit Callback Functions1049693 -Node: Extension Version String1050943 -Node: Input Parsers1051606 -Node: Output Wrappers1064327 -Node: Two-way processors1068839 -Node: Printing Messages1071104 -Ref: Printing Messages-Footnote-11072275 -Node: Updating ERRNO1072428 -Node: Requesting Values1073167 -Ref: table-value-types-returned1073904 -Node: Accessing Parameters1074840 -Node: Symbol Table Access1076077 -Node: Symbol table by name1076589 -Ref: Symbol table by name-Footnote-11079613 -Node: Symbol table by cookie1079741 -Ref: Symbol table by cookie-Footnote-11083926 -Node: Cached values1083990 -Ref: Cached values-Footnote-11087526 -Node: Array Manipulation1087679 -Ref: Array Manipulation-Footnote-11088770 -Node: Array Data Types1088807 -Ref: Array Data Types-Footnote-11091465 -Node: Array Functions1091557 -Node: Flattening Arrays1096055 -Node: Creating Arrays1103031 -Node: Redirection API1107798 -Node: Extension API Variables1110631 -Node: Extension Versioning1111342 -Ref: gawk-api-version1111771 -Node: Extension GMP/MPFR Versioning1113502 -Node: Extension API Informational Variables1115130 -Node: Extension API Boilerplate1116203 -Node: Changes from API V11120177 -Node: Finding Extensions1121749 -Node: Extension Example1122308 -Node: Internal File Description1123106 -Node: Internal File Ops1127186 -Ref: Internal File Ops-Footnote-11138536 -Node: Using Internal File Ops1138676 -Ref: Using Internal File Ops-Footnote-11141059 -Node: Extension Samples1141333 -Node: Extension Sample File Functions1142862 -Node: Extension Sample Fnmatch1150511 -Node: Extension Sample Fork1151998 -Node: Extension Sample Inplace1153216 -Node: Extension Sample Ord1156842 -Node: Extension Sample Readdir1157678 -Ref: table-readdir-file-types1158567 -Node: Extension Sample Revout1159634 -Node: Extension Sample Rev2way1160223 -Node: Extension Sample Read write array1160963 -Node: Extension Sample Readfile1162905 -Node: Extension Sample Time1164000 -Node: Extension Sample API Tests1165752 -Node: gawkextlib1166244 -Node: Extension summary1169162 -Node: Extension Exercises1172864 -Node: Language History1174106 -Node: V7/SVR3.11175762 -Node: SVR41177914 -Node: POSIX1179348 -Node: BTL1180729 -Node: POSIX/GNU1181458 -Node: Feature History1187236 -Node: Common Extensions1203555 -Node: Ranges and Locales1204838 -Ref: Ranges and Locales-Footnote-11209454 -Ref: Ranges and Locales-Footnote-21209481 -Ref: Ranges and Locales-Footnote-31209716 -Node: Contributors1209939 -Node: History summary1215936 -Node: Installation1217316 -Node: Gawk Distribution1218260 -Node: Getting1218744 -Node: Extracting1219707 -Node: Distribution contents1221345 -Node: Unix Installation1227825 -Node: Quick Installation1228507 -Node: Shell Startup Files1230921 -Node: Additional Configuration Options1232010 -Node: Configuration Philosophy1234325 -Node: Non-Unix Installation1236694 -Node: PC Installation1237154 -Node: PC Binary Installation1237992 -Node: PC Compiling1238427 -Node: PC Using1239544 -Node: Cygwin1243097 -Node: MSYS1244321 -Node: VMS Installation1244923 -Node: VMS Compilation1245714 -Ref: VMS Compilation-Footnote-11246943 -Node: VMS Dynamic Extensions1247001 -Node: VMS Installation Details1248686 -Node: VMS Running1250939 -Node: VMS GNV1255218 -Node: VMS Old Gawk1255953 -Node: Bugs1256424 -Node: Bug address1257087 -Node: Usenet1260069 -Node: Maintainers1261073 -Node: Other Versions1262258 -Node: Installation summary1269346 -Node: Notes1270555 -Node: Compatibility Mode1271349 -Node: Additions1272131 -Node: Accessing The Source1273056 -Node: Adding Code1274493 -Node: New Ports1280712 -Node: Derived Files1285087 -Ref: Derived Files-Footnote-11290747 -Ref: Derived Files-Footnote-21290782 -Ref: Derived Files-Footnote-31291380 -Node: Future Extensions1291494 -Node: Implementation Limitations1292152 -Node: Extension Design1293362 -Node: Old Extension Problems1294506 -Ref: Old Extension Problems-Footnote-11296024 -Node: Extension New Mechanism Goals1296081 -Ref: Extension New Mechanism Goals-Footnote-11299445 -Node: Extension Other Design Decisions1299634 -Node: Extension Future Growth1301747 -Node: Notes summary1302353 -Node: Basic Concepts1303511 -Node: Basic High Level1304192 -Ref: figure-general-flow1304474 -Ref: figure-process-flow1305159 -Ref: Basic High Level-Footnote-11308460 -Node: Basic Data Typing1308645 -Node: Glossary1311973 -Node: Copying1343858 -Node: GNU Free Documentation License1381401 -Node: Index1406521 +Node: Foreword344553 +Node: Foreword448995 +Node: Preface50527 +Ref: Preface-Footnote-153386 +Ref: Preface-Footnote-253495 +Ref: Preface-Footnote-353729 +Node: History53871 +Node: Names56223 +Ref: Names-Footnote-157327 +Node: This Manual57474 +Ref: This Manual-Footnote-164113 +Node: Conventions64213 +Node: Manual History66582 +Ref: Manual History-Footnote-169579 +Ref: Manual History-Footnote-269620 +Node: How To Contribute69694 +Node: Acknowledgments70620 +Node: Getting Started75557 +Node: Running gawk77996 +Node: One-shot79186 +Node: Read Terminal80449 +Node: Long82442 +Node: Executable Scripts83955 +Ref: Executable Scripts-Footnote-186588 +Node: Comments86691 +Node: Quoting89175 +Node: DOS Quoting94701 +Node: Sample Data Files96757 +Node: Very Simple99352 +Node: Two Rules105454 +Node: More Complex107339 +Node: Statements/Lines109671 +Ref: Statements/Lines-Footnote-1114155 +Node: Other Features114420 +Node: When115356 +Ref: When-Footnote-1117110 +Node: Intro Summary117175 +Node: Invoking Gawk118059 +Node: Command Line119573 +Node: Options120371 +Ref: Options-Footnote-1138285 +Ref: Options-Footnote-2138516 +Node: Other Arguments138541 +Node: Naming Standard Input142552 +Node: Environment Variables143762 +Node: AWKPATH Variable144320 +Ref: AWKPATH Variable-Footnote-1147732 +Ref: AWKPATH Variable-Footnote-2147766 +Node: AWKLIBPATH Variable148137 +Ref: AWKLIBPATH Variable-Footnote-1149834 +Node: Other Environment Variables150209 +Node: Exit Status154030 +Node: Include Files154707 +Node: Loading Shared Libraries158397 +Node: Obsolete159825 +Node: Undocumented160517 +Node: Invoking Summary160814 +Node: Regexp163655 +Node: Regexp Usage165109 +Node: Escape Sequences167146 +Node: Regexp Operators173387 +Node: Regexp Operator Details173872 +Ref: Regexp Operator Details-Footnote-1180304 +Node: Interval Expressions180451 +Ref: Interval Expressions-Footnote-1181872 +Node: Bracket Expressions181970 +Ref: table-char-classes184446 +Node: Leftmost Longest187772 +Node: Computed Regexps189075 +Node: GNU Regexp Operators192502 +Node: Case-sensitivity196239 +Ref: Case-sensitivity-Footnote-1199105 +Ref: Case-sensitivity-Footnote-2199340 +Node: Regexp Summary199448 +Node: Reading Files200914 +Node: Records203183 +Node: awk split records204258 +Node: gawk split records209533 +Ref: gawk split records-Footnote-1214266 +Node: Fields214303 +Node: Nonconstant Fields217044 +Ref: Nonconstant Fields-Footnote-1219280 +Node: Changing Fields219484 +Node: Field Separators225515 +Node: Default Field Splitting228213 +Node: Regexp Field Splitting229331 +Node: Single Character Fields232684 +Node: Command Line Field Separator233744 +Node: Full Line Fields236962 +Ref: Full Line Fields-Footnote-1238484 +Ref: Full Line Fields-Footnote-2238530 +Node: Field Splitting Summary238631 +Node: Constant Size240705 +Node: Fixed width data241437 +Node: Skipping intervening244904 +Node: Allowing trailing data245702 +Node: Fields with fixed data246739 +Node: Splitting By Content248257 +Ref: Splitting By Content-Footnote-1252040 +Node: More CSV252203 +Node: Testing field creation253513 +Node: Multiple Line255138 +Node: Getline261415 +Node: Plain Getline263884 +Node: Getline/Variable266457 +Node: Getline/File267608 +Node: Getline/Variable/File268996 +Ref: Getline/Variable/File-Footnote-1270601 +Node: Getline/Pipe270689 +Node: Getline/Variable/Pipe273393 +Node: Getline/Coprocess274528 +Node: Getline/Variable/Coprocess275795 +Node: Getline Notes276537 +Node: Getline Summary279334 +Ref: table-getline-variants279758 +Node: Read Timeout280506 +Ref: Read Timeout-Footnote-1284412 +Node: Retrying Input284470 +Node: Command-line directories285669 +Node: Input Summary286575 +Node: Input Exercises289747 +Node: Printing290181 +Node: Print292015 +Node: Print Examples293472 +Node: Output Separators296252 +Node: OFMT298269 +Node: Printf299625 +Node: Basic Printf300410 +Node: Control Letters301984 +Node: Format Modifiers307146 +Node: Printf Examples313161 +Node: Redirection315647 +Node: Special FD322488 +Ref: Special FD-Footnote-1325656 +Node: Special Files325730 +Node: Other Inherited Files326347 +Node: Special Network327348 +Node: Special Caveats328208 +Node: Close Files And Pipes329157 +Ref: table-close-pipe-return-values336064 +Ref: Close Files And Pipes-Footnote-1336877 +Ref: Close Files And Pipes-Footnote-2337025 +Node: Nonfatal337177 +Node: Output Summary339515 +Node: Output Exercises340737 +Node: Expressions341416 +Node: Values342604 +Node: Constants343282 +Node: Scalar Constants343973 +Ref: Scalar Constants-Footnote-1346483 +Node: Nondecimal-numbers346733 +Node: Regexp Constants349734 +Node: Using Constant Regexps350260 +Node: Standard Regexp Constants350882 +Node: Strong Regexp Constants354070 +Node: Variables357082 +Node: Using Variables357739 +Node: Assignment Options359649 +Node: Conversion362120 +Node: Strings And Numbers362644 +Ref: Strings And Numbers-Footnote-1365707 +Node: Locale influences conversions365816 +Ref: table-locale-affects368574 +Node: All Operators369192 +Node: Arithmetic Ops369821 +Node: Concatenation372537 +Ref: Concatenation-Footnote-1375384 +Node: Assignment Ops375491 +Ref: table-assign-ops380482 +Node: Increment Ops381795 +Node: Truth Values and Conditions385255 +Node: Truth Values386329 +Node: Typing and Comparison387377 +Node: Variable Typing388197 +Ref: Variable Typing-Footnote-1394660 +Ref: Variable Typing-Footnote-2394732 +Node: Comparison Operators394809 +Ref: table-relational-ops395228 +Node: POSIX String Comparison398723 +Ref: POSIX String Comparison-Footnote-1400418 +Ref: POSIX String Comparison-Footnote-2400557 +Node: Boolean Ops400641 +Ref: Boolean Ops-Footnote-1405123 +Node: Conditional Exp405215 +Node: Function Calls406951 +Node: Precedence410828 +Node: Locales414487 +Node: Expressions Summary416119 +Node: Patterns and Actions418692 +Node: Pattern Overview419812 +Node: Regexp Patterns421489 +Node: Expression Patterns422031 +Node: Ranges425812 +Node: BEGIN/END428920 +Node: Using BEGIN/END429681 +Ref: Using BEGIN/END-Footnote-1432435 +Node: I/O And BEGIN/END432541 +Node: BEGINFILE/ENDFILE434854 +Node: Empty438085 +Node: Using Shell Variables438402 +Node: Action Overview440676 +Node: Statements443001 +Node: If Statement444849 +Node: While Statement446344 +Node: Do Statement448372 +Node: For Statement449520 +Node: Switch Statement452691 +Node: Break Statement455132 +Node: Continue Statement457224 +Node: Next Statement459051 +Node: Nextfile Statement461434 +Node: Exit Statement464086 +Node: Built-in Variables466489 +Node: User-modified467622 +Node: Auto-set475389 +Ref: Auto-set-Footnote-1492196 +Ref: Auto-set-Footnote-2492402 +Node: ARGC and ARGV492458 +Node: Pattern Action Summary496671 +Node: Arrays499101 +Node: Array Basics500430 +Node: Array Intro501274 +Ref: figure-array-elements503249 +Ref: Array Intro-Footnote-1505953 +Node: Reference to Elements506081 +Node: Assigning Elements508545 +Node: Array Example509036 +Node: Scanning an Array510795 +Node: Controlling Scanning513817 +Ref: Controlling Scanning-Footnote-1520273 +Node: Numeric Array Subscripts520589 +Node: Uninitialized Subscripts522773 +Node: Delete524392 +Ref: Delete-Footnote-1527144 +Node: Multidimensional527201 +Node: Multiscanning530296 +Node: Arrays of Arrays531887 +Node: Arrays Summary536655 +Node: Functions538748 +Node: Built-in539786 +Node: Calling Built-in540867 +Node: Numeric Functions542863 +Ref: Numeric Functions-Footnote-1546889 +Ref: Numeric Functions-Footnote-2547537 +Ref: Numeric Functions-Footnote-3547585 +Node: String Functions547857 +Ref: String Functions-Footnote-1571998 +Ref: String Functions-Footnote-2572126 +Ref: String Functions-Footnote-3572374 +Node: Gory Details572461 +Ref: table-sub-escapes574252 +Ref: table-sub-proposed575771 +Ref: table-posix-sub577134 +Ref: table-gensub-escapes578675 +Ref: Gory Details-Footnote-1579498 +Node: I/O Functions579652 +Ref: table-system-return-values586106 +Ref: I/O Functions-Footnote-1588186 +Ref: I/O Functions-Footnote-2588334 +Node: Time Functions588454 +Ref: Time Functions-Footnote-1599125 +Ref: Time Functions-Footnote-2599193 +Ref: Time Functions-Footnote-3599351 +Ref: Time Functions-Footnote-4599462 +Ref: Time Functions-Footnote-5599574 +Ref: Time Functions-Footnote-6599801 +Node: Bitwise Functions600067 +Ref: table-bitwise-ops600661 +Ref: Bitwise Functions-Footnote-1606724 +Ref: Bitwise Functions-Footnote-2606897 +Node: Type Functions607088 +Node: I18N Functions609951 +Node: User-defined611602 +Node: Definition Syntax612414 +Ref: Definition Syntax-Footnote-1618108 +Node: Function Example618179 +Ref: Function Example-Footnote-1621101 +Node: Function Calling621123 +Node: Calling A Function621711 +Node: Variable Scope622669 +Node: Pass By Value/Reference625663 +Node: Function Caveats628307 +Ref: Function Caveats-Footnote-1630354 +Node: Return Statement630474 +Node: Dynamic Typing633453 +Node: Indirect Calls634383 +Ref: Indirect Calls-Footnote-1644635 +Node: Functions Summary644763 +Node: Library Functions647468 +Ref: Library Functions-Footnote-1651075 +Ref: Library Functions-Footnote-2651218 +Node: Library Names651389 +Ref: Library Names-Footnote-1655056 +Ref: Library Names-Footnote-2655279 +Node: General Functions655365 +Node: Strtonum Function656468 +Node: Assert Function659490 +Node: Round Function662816 +Node: Cliff Random Function664356 +Node: Ordinal Functions665372 +Ref: Ordinal Functions-Footnote-1668435 +Ref: Ordinal Functions-Footnote-2668687 +Node: Join Function668897 +Ref: Join Function-Footnote-1670667 +Node: Getlocaltime Function670867 +Node: Readfile Function674609 +Node: Shell Quoting676586 +Node: Data File Management677987 +Node: Filetrans Function678619 +Node: Rewind Function682715 +Node: File Checking684624 +Ref: File Checking-Footnote-1685958 +Node: Empty Files686159 +Node: Ignoring Assigns688138 +Node: Getopt Function689688 +Ref: Getopt Function-Footnote-1704899 +Node: Passwd Functions705099 +Ref: Passwd Functions-Footnote-1713938 +Node: Group Functions714026 +Ref: Group Functions-Footnote-1721924 +Node: Walking Arrays722131 +Node: Library Functions Summary725139 +Node: Library Exercises726545 +Node: Sample Programs727010 +Node: Running Examples727780 +Node: Clones728508 +Node: Cut Program729732 +Node: Egrep Program739661 +Node: Id Program748672 +Node: Split Program758619 +Ref: Split Program-Footnote-1768393 +Node: Tee Program768566 +Node: Uniq Program771356 +Node: Wc Program778920 +Node: Bytes vs. Characters779317 +Node: Using extensions780865 +Node: wc program781623 +Node: Miscellaneous Programs786488 +Node: Dupword Program787701 +Node: Alarm Program789731 +Node: Translate Program794586 +Ref: Translate Program-Footnote-1799151 +Node: Labels Program799421 +Ref: Labels Program-Footnote-1802772 +Node: Word Sorting802856 +Node: History Sorting806928 +Node: Extract Program809153 +Node: Simple Sed817207 +Node: Igawk Program820281 +Ref: Igawk Program-Footnote-1834612 +Ref: Igawk Program-Footnote-2834814 +Ref: Igawk Program-Footnote-3834936 +Node: Anagram Program835051 +Node: Signature Program838113 +Node: Programs Summary839360 +Node: Programs Exercises840574 +Ref: Programs Exercises-Footnote-1844704 +Node: Advanced Features844790 +Node: Nondecimal Data846780 +Node: Array Sorting848371 +Node: Controlling Array Traversal849071 +Ref: Controlling Array Traversal-Footnote-1857439 +Node: Array Sorting Functions857557 +Ref: Array Sorting Functions-Footnote-1862648 +Node: Two-way I/O862844 +Ref: Two-way I/O-Footnote-1870565 +Ref: Two-way I/O-Footnote-2870752 +Node: TCP/IP Networking870834 +Node: Profiling873952 +Node: Advanced Features Summary883266 +Node: Internationalization885110 +Node: I18N and L10N886590 +Node: Explaining gettext887277 +Ref: Explaining gettext-Footnote-1893169 +Ref: Explaining gettext-Footnote-2893354 +Node: Programmer i18n893519 +Ref: Programmer i18n-Footnote-1898468 +Node: Translator i18n898517 +Node: String Extraction899311 +Ref: String Extraction-Footnote-1900443 +Node: Printf Ordering900529 +Ref: Printf Ordering-Footnote-1903315 +Node: I18N Portability903379 +Ref: I18N Portability-Footnote-1905835 +Node: I18N Example905898 +Ref: I18N Example-Footnote-1909173 +Ref: I18N Example-Footnote-2909246 +Node: Gawk I18N909355 +Node: I18N Summary910004 +Node: Debugger911345 +Node: Debugging912345 +Node: Debugging Concepts912786 +Node: Debugging Terms914595 +Node: Awk Debugging917170 +Ref: Awk Debugging-Footnote-1918115 +Node: Sample Debugging Session918247 +Node: Debugger Invocation918781 +Node: Finding The Bug920167 +Node: List of Debugger Commands926641 +Node: Breakpoint Control927974 +Node: Debugger Execution Control931668 +Node: Viewing And Changing Data935030 +Node: Execution Stack938571 +Node: Debugger Info940208 +Node: Miscellaneous Debugger Commands944279 +Node: Readline Support949341 +Node: Limitations950237 +Node: Debugging Summary952791 +Node: Namespaces954070 +Node: Global Namespace955181 +Node: Qualified Names956579 +Node: Default Namespace957578 +Node: Changing The Namespace958319 +Node: Naming Rules959933 +Node: Internal Name Management961781 +Node: Namespace Example962823 +Node: Namespace And Features965385 +Node: Namespace Summary966820 +Node: Arbitrary Precision Arithmetic968297 +Node: Computer Arithmetic969784 +Ref: table-numeric-ranges973550 +Ref: table-floating-point-ranges974043 +Ref: Computer Arithmetic-Footnote-1974701 +Node: Math Definitions974758 +Ref: table-ieee-formats977734 +Node: MPFR features978301 +Node: FP Math Caution980019 +Ref: FP Math Caution-Footnote-1981091 +Node: Inexactness of computations981460 +Node: Inexact representation982491 +Node: Comparing FP Values983851 +Node: Errors accumulate985092 +Node: Strange values986548 +Ref: Strange values-Footnote-1988828 +Node: Getting Accuracy988933 +Node: Try To Round991643 +Node: Setting precision992542 +Ref: table-predefined-precision-strings993239 +Node: Setting the rounding mode995069 +Ref: table-gawk-rounding-modes995443 +Ref: Setting the rounding mode-Footnote-1999374 +Node: Arbitrary Precision Integers999553 +Ref: Arbitrary Precision Integers-Footnote-11002728 +Node: Checking for MPFR1002877 +Node: POSIX Floating Point Problems1004351 +Ref: POSIX Floating Point Problems-Footnote-11008636 +Node: Floating point summary1008674 +Node: Dynamic Extensions1010864 +Node: Extension Intro1012417 +Node: Plugin License1013683 +Node: Extension Mechanism Outline1014480 +Ref: figure-load-extension1014919 +Ref: figure-register-new-function1016484 +Ref: figure-call-new-function1017576 +Node: Extension API Description1019638 +Node: Extension API Functions Introduction1021351 +Ref: table-api-std-headers1023187 +Node: General Data Types1027436 +Ref: General Data Types-Footnote-11036066 +Node: Memory Allocation Functions1036365 +Ref: Memory Allocation Functions-Footnote-11040866 +Node: Constructor Functions1040965 +Node: API Ownership of MPFR and GMP Values1044431 +Node: Registration Functions1045744 +Node: Extension Functions1046444 +Node: Exit Callback Functions1051766 +Node: Extension Version String1053016 +Node: Input Parsers1053679 +Node: Output Wrappers1066400 +Node: Two-way processors1070912 +Node: Printing Messages1073177 +Ref: Printing Messages-Footnote-11074348 +Node: Updating ERRNO1074501 +Node: Requesting Values1075240 +Ref: table-value-types-returned1075977 +Node: Accessing Parameters1076913 +Node: Symbol Table Access1078150 +Node: Symbol table by name1078662 +Ref: Symbol table by name-Footnote-11081686 +Node: Symbol table by cookie1081814 +Ref: Symbol table by cookie-Footnote-11085999 +Node: Cached values1086063 +Ref: Cached values-Footnote-11089599 +Node: Array Manipulation1089752 +Ref: Array Manipulation-Footnote-11090843 +Node: Array Data Types1090880 +Ref: Array Data Types-Footnote-11093538 +Node: Array Functions1093630 +Node: Flattening Arrays1098128 +Node: Creating Arrays1105104 +Node: Redirection API1109871 +Node: Extension API Variables1112704 +Node: Extension Versioning1113415 +Ref: gawk-api-version1113844 +Node: Extension GMP/MPFR Versioning1115575 +Node: Extension API Informational Variables1117203 +Node: Extension API Boilerplate1118276 +Node: Changes from API V11122250 +Node: Finding Extensions1123822 +Node: Extension Example1124381 +Node: Internal File Description1125179 +Node: Internal File Ops1129259 +Ref: Internal File Ops-Footnote-11140609 +Node: Using Internal File Ops1140749 +Ref: Using Internal File Ops-Footnote-11143132 +Node: Extension Samples1143406 +Node: Extension Sample File Functions1144935 +Node: Extension Sample Fnmatch1152584 +Node: Extension Sample Fork1154071 +Node: Extension Sample Inplace1155289 +Node: Extension Sample Ord1158915 +Node: Extension Sample Readdir1159751 +Ref: table-readdir-file-types1160640 +Node: Extension Sample Revout1161707 +Node: Extension Sample Rev2way1162296 +Node: Extension Sample Read write array1163036 +Node: Extension Sample Readfile1164978 +Node: Extension Sample Time1166073 +Node: Extension Sample API Tests1167825 +Node: gawkextlib1168317 +Node: Extension summary1171235 +Node: Extension Exercises1174937 +Node: Language History1176179 +Node: V7/SVR3.11177835 +Node: SVR41179987 +Node: POSIX1181421 +Node: BTL1182802 +Node: POSIX/GNU1183531 +Node: Feature History1189309 +Node: Common Extensions1205628 +Node: Ranges and Locales1206911 +Ref: Ranges and Locales-Footnote-11211527 +Ref: Ranges and Locales-Footnote-21211554 +Ref: Ranges and Locales-Footnote-31211789 +Node: Contributors1212012 +Node: History summary1218009 +Node: Installation1219389 +Node: Gawk Distribution1220333 +Node: Getting1220817 +Node: Extracting1221780 +Node: Distribution contents1223418 +Node: Unix Installation1229898 +Node: Quick Installation1230580 +Node: Shell Startup Files1232994 +Node: Additional Configuration Options1234083 +Node: Configuration Philosophy1236398 +Node: Non-Unix Installation1238767 +Node: PC Installation1239227 +Node: PC Binary Installation1240065 +Node: PC Compiling1240500 +Node: PC Using1241617 +Node: Cygwin1245170 +Node: MSYS1246394 +Node: VMS Installation1246996 +Node: VMS Compilation1247787 +Ref: VMS Compilation-Footnote-11249016 +Node: VMS Dynamic Extensions1249074 +Node: VMS Installation Details1250759 +Node: VMS Running1253012 +Node: VMS GNV1257291 +Node: VMS Old Gawk1258026 +Node: Bugs1258497 +Node: Bug address1259160 +Node: Usenet1262142 +Node: Maintainers1263146 +Node: Other Versions1264331 +Node: Installation summary1271419 +Node: Notes1272628 +Node: Compatibility Mode1273422 +Node: Additions1274204 +Node: Accessing The Source1275129 +Node: Adding Code1276566 +Node: New Ports1282785 +Node: Derived Files1287160 +Ref: Derived Files-Footnote-11292820 +Ref: Derived Files-Footnote-21292855 +Ref: Derived Files-Footnote-31293453 +Node: Future Extensions1293567 +Node: Implementation Limitations1294225 +Node: Extension Design1295435 +Node: Old Extension Problems1296579 +Ref: Old Extension Problems-Footnote-11298097 +Node: Extension New Mechanism Goals1298154 +Ref: Extension New Mechanism Goals-Footnote-11301518 +Node: Extension Other Design Decisions1301707 +Node: Extension Future Growth1303820 +Node: Notes summary1304426 +Node: Basic Concepts1305584 +Node: Basic High Level1306265 +Ref: figure-general-flow1306547 +Ref: figure-process-flow1307232 +Ref: Basic High Level-Footnote-11310533 +Node: Basic Data Typing1310718 +Node: Glossary1314046 +Node: Copying1345931 +Node: GNU Free Documentation License1383474 +Node: Index1408594 End Tag Table diff --git a/doc/gawk.texi b/doc/gawk.texi index 2a1e65c3..6c1f4091 100644 --- a/doc/gawk.texi +++ b/doc/gawk.texi @@ -919,6 +919,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. @@ -8413,7 +8414,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. As with @code{FS}, the @code{IGNORECASE} variable (@pxref{User-modified}) @@ -10063,7 +10064,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 @@ -18298,7 +18299,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. @@ -33586,21 +33587,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 @@ -33769,6 +33758,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 @@ -33890,6 +33880,54 @@ $ @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 infinity. + +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) +This 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. + @node Getting Accuracy @subsection Getting the Accuracy You Need diff --git a/doc/gawktexi.in b/doc/gawktexi.in index e733c4ec..eca3bead 100644 --- a/doc/gawktexi.in +++ b/doc/gawktexi.in @@ -914,6 +914,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. @@ -7966,7 +7967,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. As with @code{FS}, the @code{IGNORECASE} variable (@pxref{User-modified}) @@ -9616,7 +9617,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 @@ -17523,7 +17524,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. @@ -32552,21 +32553,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 @@ -32735,6 +32724,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 @@ -32856,6 +32846,54 @@ $ @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 infinity. + +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) +This 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. + @node Getting Accuracy @subsection Getting the Accuracy You Need diff --git a/doc/wordlist b/doc/wordlist index c93eda53..9ce31188 100644 --- a/doc/wordlist +++ b/doc/wordlist @@ -316,6 +316,7 @@ NR NT NUMCUR NaN +NaNs Nachum Neacsu Neacsu's @@ -483,6 +484,7 @@ VT Versioning Vinschen WIPO +WONTFIX Walamazoo Wallin Watchpoint @@ -24,10 +24,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; @@ -1520,18 +1518,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(); @@ -1539,12 +1536,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 fedf5255..40dd39d6 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; @@ -433,6 +433,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. @@ -25,7 +25,7 @@ */ #include "awk.h" -#include "math.h" +#include <math.h> #include "floatmagic.h" /* definition of isnan */ static int is_ieee_magic_val(const char *val); @@ -367,7 +367,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 @@ -387,7 +387,6 @@ cmp_awknums(const NODE *t1, const NODE *t2) return 1; } - /* make_str_node --- make a string node */ NODE * |