bug-gawk
[Top][All Lists]
Advanced

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

[bug-gawk] float conversion


From: Andreas Mueller
Subject: [bug-gawk] float conversion
Date: Thu, 10 Oct 2013 18:45:14 +0200
User-agent: Mutt/1.5.14 (2007-03-31)

Hello Group,

trying to figure out why my floor-implementation would not succeed I can
across some behaviour of gawk (and mawk for that matter). I am not sure
if it's a bug or just my lack of understanding float handling.
But I assume that it's an inconsistancy.

See this example:

$ gawk 'BEGIN { for (i = -1; i <= 1; i += 0.1) { print "int("i") = " int(i)} }'

int(-1) = -1
int(-0.9) = 0
int(-0.8) = 0
int(-0.7) = 0
int(-0.6) = 0
int(-0.5) = 0
int(-0.4) = 0
int(-0.3) = 0
int(-0.2) = 0
int(-0.1) = 0
int(-1.38778e-16) = 0
int(0.1) = 0
int(0.2) = 0
int(0.3) = 0
int(0.4) = 0
int(0.5) = 0
int(0.6) = 0
int(0.7) = 0
int(0.8) = 0
int(0.9) = 0
int(1) = 0

It seems gawk has trouble seeing this number as either integer or float.
Furthermore, printf("%d", i) would also show 0 instead of 1 in the last
iteration. Interrestingly plain "print i" gets 1 correctly (and other
numbers on a greater range) but not 0.

I am using GNU Awk 4.1.0, API: 1.0 (GNU MPFR 3.1.0, GNU MP 5.0.5).

I am not a member of this group, so please include me in CC.

Thanks,
Andreas.



reply via email to

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