21.07.2015 Views

GAWK: Effective AWK Programming

GAWK: Effective AWK Programming

GAWK: Effective AWK Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Appendix D: Basic <strong>Programming</strong> Concepts 3051. With the ‘--posix’ command-line option, gawk becomes “hands off.” String values arepassed directly to the system library’s strtod() function, and if it successfuly returnsa numeric value, that is what’s used. By definition, the results are not portable acrossdifferent systems. 3 They are also a little surprising:$ echo nanny | gawk --posix ’{ print $1 + 0 }’⊣ nan$ echo 0xDeadBeef | gawk --posix ’{ print $1 + 0 }’⊣ 37359285592. Without ‘--posix’, gawk interprets the four strings ‘+inf’, ‘-inf’, ‘+nan’, and ‘-nan’specially, producing the corresponding special numeric values. The leading sign actsa signal to gawk (and the user) that the value is really numeric. Hexadecimal floatingpoint is not supported (unless you also use ‘--non-decimal-data’, which is notrecommended). For example:$ echo nanny | gawk ’{ print $1 + 0 }’⊣ 0$ echo +nan | gawk ’{ print $1 + 0 }’⊣ nan$ echo 0xDeadBeef | gawk ’{ print $1 + 0 }’⊣ 0gawk does ignore case distinction in the four special values. Thus ‘+nan’ and ‘+NaN’ arethe same.3 You asked for it, you got it.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!