bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] Special Comparisons: nan == nan


From: Daniel Pettet
Subject: Re: [bug-gawk] Special Comparisons: nan == nan
Date: Mon, 7 Aug 2017 17:10:08 -0700

Andrew,

I don't know which version I saw this or how complete the treatment of NaNs was.  You could try back before version 4.0.0.  The distinction between comparing two NaNs and comparing a NaN with itself is interesting.

Thanks.  Dan.

On 7 August 2017 at 16:25, Andrew J. Schorr <address@hidden> wrote:
Hi,

On Mon, Aug 07, 2017 at 03:11:36PM -0700, Daniel Pettet wrote:
> Thanks for the prompt replies.  I think gawk had this one right several
> versions back.

What version might that be? The quick exit in eval.c:cmp_nodes has been
there since the beginning, but perhaps you are thinking of a different
case where you are comparing two different variables.

The node.c:cmp_awknums logic with the special treatment of NaNs
dates to 2012-03-19. Using gawk-4.0.0, I see this:

bash-4.2$ ./gawk '
> BEGIN {
>     nan = 0 * 1e400
>     print nan               # nan
>     print nan == nan        # 1     should be 0
> }
> '
-nan
1

But this works as you'd prefer:

bash-4.2$ ./gawk '
> BEGIN {
>     nan = 0 * 1e400
>     nan2 = nan-1
>     print nan, nan2               # nan
>     print nan == nan2        # 1     should be 0
> }
> '
-nan -nan
0

By gawk-4.1.0, the second case was also indicating equality:

bash-4.2$ ./gawk '
> BEGIN {
>     nan = 0 * 1e400
>     nan2 = nan-1
>     print nan, nan2               # nan
>     print nan == nan2        # 1     should be 0
> }
> '
-nan -nan
1

Regards,
Andy


reply via email to

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