[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Gawk] Bug in arithmetic comparisons
From: |
John Cowan |
Subject: |
Re: [Gawk] Bug in arithmetic comparisons |
Date: |
Sat, 11 Sep 2010 14:12:45 -0400 |
User-agent: |
Mutt/1.5.18 (2008-05-17) |
Seb scripsit:
> 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
Because you are inside a BEGIN block, the $1 and $2 variables are not yet
set to anything, so you are comparing '' to '' in the first two examples,
and '' to '0' in the third. If you omit the BEGIN, you get 1 in each
example, as expected.
--
Only do what only you can do. John Cowan <address@hidden>
--Edsger W. Dijkstra's advice
to a student in search of a thesis