If I try this oneliner:
perl -e "$a=-50.123456;for($i=0;$i<20;$i++){print qq!$i $a\n!;$a+=0.01}"I get this:
0 -50.123456 1 -50.113456 2 -50.103456 3 -50.093456 4 -50.083456 5 -50.073456 6 -50.063456 7 -50.053456 8 -50.043456 9 -50.033456 10 -50.023456 11 -50.013456 12 -50.003456 13 -49.993456 14 -49.983456 15 -49.973456 16 -49.963456 17 -49.953456 18 -49.943456 19 -49.933456
But if I try this one:
perl -e "$a=-71.123456;for($i=0;$i<20;$i++){print qq!$i $a\n!;$a+=0.01}"I get this:
0 -71.123456 1 -71.113456 2 -71.103456 3 -71.093456 4 -71.083456 5 -71.073456 6 -71.063456 7 -71.053456 8 -71.043456 9 -71.033456 10 -71.023456 11 -71.0134559999999 12 -71.0034559999999 13 -70.9934559999999 14 -70.9834559999999 15 -70.9734559999999 16 -70.9634559999999 17 -70.9534559999999 18 -70.9434559999999 19 -70.9334559999999
What's going on here?
Thanks!
In reply to Floating point issue by vitoco
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |