bug-gawk
[Top][All Lists]
Advanced

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

[bug-gawk] Strings "nan" and "inf" not recognized as nan or inf


From: Klaas Vantournhout
Subject: [bug-gawk] Strings "nan" and "inf" not recognized as nan or inf
Date: Thu, 28 Jun 2018 02:35:52 +0200

VERSION : 4.2.1 (compiled on fedora 27)
OS : LINUX

After encountering an interesting question on Stack Exchange, I was puzzled do discover that
the strings "nan" and "inf" are not recognised as such. An adopted version of the test case
delivered with the source :

$ awk 'BEGIN { s = "1.0 +nan 0.0 -1 +inf -0.0 1 1.0 -nan -inf 2.0 nan inf"; split(s, a)
       PROCINFO
["sorted_in"] = "@val_num_asc"
      
for (i in a) printf a[i] OFS; printf "\n" }'
-inf -1 -0.0 0.0 inf nan 1 1.0 1.0 2.0 +inf +nan -nan
From this we see that the strings "nan" and "inf" are converted to ZERO.
This seems to be related to the function `is_ieee_magic_val` which is
part of core.c.
Is this expected behaviour? I.e. are "nan" and "inf" to be understood as
strings and not strings with magic ieee values such as "+nan", or is this
an oversight? I'm thinking here about the following case :

$ awk 'BEGIN{print -sqrt(-1)}'
which outputs "nan" and not "+nan".
Link to Stack Overflow question :
https://stackoverflow.com/q/51056836/8344060

With kind regards,
Klaas





reply via email to

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