bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] Interesting floating point behavior


From: Davide Brini
Subject: Re: [bug-gawk] Interesting floating point behavior
Date: Fri, 20 Jan 2012 17:04:55 +0100

On Fri, 20 Jan 2012 08:35:16 -0600, Robert Kennedy
<address@hidden> wrote:

> # gawk --version
> GNU Awk 4.0.0
> 
> # echo -e "Input\t*10000\t%100"; for i in 0.67 0.68 0.69 0.70; do echo
> $i |gawk '{a=$1; b=a*10000; c=b%100; print a,"\t",b,"\t",c}'; done
> 
> Input *10000  %100
> 0.67   6700    0
> 0.68   6800    9.09495e-13
> 0.69   6900    100
> 0.70   7000    0
> 
> The very-close-to-zero number for 0.68 is not surprising, the result
> of the modulo for the 0.69 input seems... strange. You can see this
> happen at .57 as well:
> 
> echo -e "Input\t*10000\t%100"; for i in $(seq -w 00 99); do echo
> "0.$i" |gawk '{a=$1; b=a*10000; c=b%100; print a,"\t",b,"\t",c}'; done
> 
> This has been around since the 3.1 days at least.  Any ideas?

Change it as follows and hopefully you'll see what's going on:

for i in 0.67 0.68 0.69 0.70; do echo "$i" |gawk '{a=$1; b=a*10000;
c=b%100; printf "%.20f\t%.20f\t%.20f\n", a, b, c}'; done

-- 
D.



reply via email to

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