bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] Gawk and NaN values


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

Nelson,

Thanks for your feedback. You wrote:

Notice that the sign of an input NaN is always optional, and
scripting language implementations should certainly not
behave differently, because most are themselves implemented
in the C language.


As stated in the GAWK manual on p.346, the leading sign is not optional for GAWK, but acts a signal to gawk that the value is really numeric...

I gave the example:

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

Obviously, the error can be avoided by using the --posix switch:

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

However, my main issue was that gawk is able to identify -nan as a special Not-a-Number value, gawk does some calculations and then produces an output value which it can't identify as a special value (at least not without the --posix switch).

Hermann



reply via email to

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