bug-gawk
[Top][All Lists]
Advanced

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

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


From: arnold
Subject: Re: [bug-gawk] Strings "nan" and "inf" not recognized as nan or inf
Date: Thu, 28 Jun 2018 00:29:02 -0600
User-agent: Heirloom mailx 12.4 7/29/08

Hello.

Thank you for submitting a bug report.

You are correct, gawk does not treat plain "nan" and "inf" as numeric
values. Making it do so is not necessarily the right thing to do. This
is discussed in the manual. See:
https://www.gnu.org/software/gawk/manual/html_node/POSIX-Floating-Point-Problems.html#POSIX-Floating-Point-Problems

It is true that gawk prints plain "inf" and "nan" if such values
are generated and then output.  This is something of an oversight on
my part, which I am currently thinking about how to remedy.

The issue of comparisons among such values is also thorny.  I need to
think about it some also (and document it better).  The Stack Overflow
discussion seems to be pretty thorough, except for having missed the above
bit in the documentation. It will help me once I start working on this.

Thanks,

Arnold

Klaas Vantournhout <address@hidden> wrote:

> 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`
> <http://git.savannah.gnu.org/cgit/gawk.git/tree/node.c?h=gawk-4.1.3>
> 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]