could someone please explain this behaviour of the following snippet to me?
This prints on my 5.18.1 on Debian:for my $i (1..20) { print "$i: "; print (1-1/2000)**$i; print " - "; print (1-1/2000)**int($i); print " - "; print "" . (1-1/2000)**$i; print "\n"; }
So for some reason I get the correct numerical value of the expression (1-1/2000)**$i only when I force stringification...1: 0.9995 - 0.9995 - 0.9995 2: 0.9995 - 0.9995 - 0.99900025 3: 0.9995 - 0.9995 - 0.998500749875 4: 0.9995 - 0.9995 - 0.998001499500063 5: 0.9995 - 0.9995 - 0.997502498750313 6: 0.9995 - 0.9995 - 0.997003747500938 7: 0.9995 - 0.9995 - 0.996505245627187 8: 0.9995 - 0.9995 - 0.996006993004374 9: 0.9995 - 0.9995 - 0.995508989507872 10: 0.9995 - 0.9995 - 0.995011235013118 11: 0.9995 - 0.9995 - 0.994513729395611 12: 0.9995 - 0.9995 - 0.994016472530913 13: 0.9995 - 0.9995 - 0.993519464294648 14: 0.9995 - 0.9995 - 0.993022704562501 15: 0.9995 - 0.9995 - 0.99252619321022 16: 0.9995 - 0.9995 - 0.992029930113615 17: 0.9995 - 0.9995 - 0.991533915148558 18: 0.9995 - 0.9995 - 0.991038148190984 19: 0.9995 - 0.9995 - 0.990542629116888 20: 0.9995 - 0.9995 - 0.99004735780233
Why is that?
In reply to strange arithmetic by morgon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |