[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: apparent array reference bug
From: |
Stepan Kasal |
Subject: |
Re: apparent array reference bug |
Date: |
Tue, 26 Aug 2003 07:32:13 +0200 |
User-agent: |
Mutt/1.2.5.1i |
Hello Michael,
thank you for your bug report.
On Mon, Aug 25, 2003 at 07:49:56PM -0000, michael humphrey wrote:
> 1) references to the variable hyr[wn], where wn == 1,
> return the incorrect value of 0.
Actually, wn == 1.5, not 1. Awk does all computation in double, so
pn = 0; qn = 3
wn = (pn + qn) / 2
is not what you want. The following would be better:
wn = int((pn + qn) / 2)
Unfortunately, awk is not so close to C as you seem to suppose.
When you printf %d, the number is converted to int, ie. truncated.
The following commands would reveal the true value of wn, though:
print wn
printf("%s\n, wn)
Each of these commands forces conversion to string, not to integer, which
doesn't hide the fraction part.
Hope this helps,
Stepan Kasal