bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-gawk] Gawk and NaN values


From: Hermann Peifer
Subject: [bug-gawk] Gawk and NaN values
Date: Wed, 31 Aug 2011 19:38:37 +0200
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:6.0) Gecko/20110812 Thunderbird/6.0

Hi,

The manual states on p. 346 about nan and inf:

--- snip ---
gawk interprets the four strings ‘+inf’, ‘-inf’, ‘+nan’, and ‘-nan’ specially, producing the corresponding special numeric values. The leading sign acts a signal to gawk (and the user) that the value is really numeric... For example:

$ echo +nan | gawk '{ print $1 + 0 }'
-| nan
--- snip ---

The result above is 'nan', i.e. a string without a leading sign which means that subsequent awk processing will not detect that this is meant to be a special value. Simplified example:

$ echo "1 -nan" | awk '{ print $1, $1 / $2 }'
1 nan

$ echo "1 -nan" | awk '{ print $1, $1 / $2 }' | awk '{print $1 / $2}'
awk: cmd. line:1: (FILENAME=- FNR=1) fatal: division by zero attempted

This might well be a feature rather than anything else. I just came across it today and thought it could be worth reporting.

Hermann



reply via email to

[Prev in Thread] Current Thread [Next in Thread]