bug-gnu-utils
[Top][All Lists]
Advanced

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

Re: [Gawk] Bug in arithmetic comparisons


From: Davide Brini
Subject: Re: [Gawk] Bug in arithmetic comparisons
Date: Sat, 11 Sep 2010 19:14:07 +0100

On Sat, 11 Sep 2010 19:19:13 +0200 Seb <address@hidden> wrote:

> I think there is a bug in the comparisons that gawk (3.1.8) makes in
> numeric context. Here is an example of what I get :
> 
> $ echo "12.10 12.10" | awk 'BEGIN{print ($1 == $2) ? 1 : 0}'
>   1
> $ echo "12.10 12.1" | awk 'BEGIN{print ($1 == $2) ? 1 : 0}'
>   1
> $ echo "12.10 12.1" | awk 'BEGIN{print ($1 == $2+0) ? 1 : 0}'
>   0
> 
> I don't know why, but in the third example, the addition seems to change
> the type of "12.1" from strnum into string, so that the comparison is a
> string comparison and is hence false.
> 
> The manual (section 5.10.1) specifies that strnum is the type of input
> strings that can be taken as numeric (verified in the second example) and
> that once a type is attributed, it can't be changed. So I think it's a
> bug somewhere (even if I misunderstood the manual, I think "$2+0" should
> accordingly to POSIX be of numeric type, so that the comparison is strnum
> vs. numeric, which is resolved in a numeric context). Am I wrong ? :)

Remove the BEGIN.

-- 
D.



reply via email to

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