bug-gawk
[Top][All Lists]
Advanced

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

[bug-gawk] Special Comparisons


From: Daniel Pettet
Subject: [bug-gawk] Special Comparisons
Date: Sun, 6 Aug 2017 17:59:59 -0700

Hello,

I've spotted a couple of comparison issues in gawk 4.1.4 that need to be fixed.

1.  A NaN is never equal to anything - including another NaN.  The following illustrate the problem

BEGIN {
    nan = 0 * 1e400
    print nan               # nan
    print nan == nan        # 1     should be 0
}

2.  Array indices should always be treated as strings - including nil (undefined) values.  The following code illustrates the issue.

BEGIN {
    a[i] = "null"                       # i is initially undefined
    for (i in a) {                      # i is null string
        print length(i), a[i]           # 0 null
        print i==0, i==""               # 1 1  should be  0 1
    }
    print a[""]                         # null
    print a[0]                          #
}

The nil (uninitialized) value compares true with zero and the null string but the null string should compare false with zero.

print  v == 0           # 1     v is not set
print  v == ""          # 1
print  0 == ""          # 0

This implies that i in 'print i==0, i==""' is undefined and not the null string.  i should be set by the array loop to null.

Thanks.  Dan.



reply via email to

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