[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] float conversion
From: |
Andreas Mueller |
Subject: |
Re: [bug-gawk] float conversion |
Date: |
Thu, 10 Oct 2013 20:39:33 +0200 |
User-agent: |
Mutt/1.5.14 (2007-03-31) |
Hi,
Andrew J. Schorr wrote:
> Hi,
>
> On Thu, Oct 10, 2013 at 06:45:14PM +0200, Andreas Mueller wrote:
> > $ gawk 'BEGIN { for (i = -1; i <= 1; i += 0.1) { print "int("i") = "
> > int(i)} }'
>
> By default, gawk stores numbers in IEEE floating-point representation.
> Does this clarify what's going on?
After some looking into it again it suddenly does.
> ...
> If you want true fixed-point arithmetic, you should probably simulate it using
> integers:
v>
> bash-4.1$ gawk 'BEGIN { for (i = -10; i <= 10; i += 1) { print "int("i/10") =
> " int(i/10)} }'
Thanks, I'll keep that in mind.
What bothered me was that 'print i' would show "1" in the final iteration while
'printf("%d\n", i)' and 'print int(i)' would show "0". But apparently it's
because of OFMT.
Thanks and regards,
Andreas