AlienFetus
Programmer
Hi,
The best way to demonstrate the problem is with this example:
1: $a = 2.01 * 100;
2: print $a,"\n";
// prints: 201
3: print int($a),"\n";
// prints: 200
Now, obviously, Perl is hiding some massive number of 9s after the decimal point at (2). But even though it should be a whole number after (1), it isn't. I know deep down this is due to some minor floating point inaccuracy, but can someone explain to me why Perl isn't handling 3 significant digits accurately? And is there any way to tell when this inaccuracy arises? I've noticed that 18.15 does the same thing, for example, and 18.31.
How do I resolve this except making sure I use the Math::Round module everytime I do arithmetic?
I am using v5.8.0 built for i386-linux-thread-multi, with locally applied patches:
MAINT18379
Thanks,
Don.
The best way to demonstrate the problem is with this example:
1: $a = 2.01 * 100;
2: print $a,"\n";
// prints: 201
3: print int($a),"\n";
// prints: 200
Now, obviously, Perl is hiding some massive number of 9s after the decimal point at (2). But even though it should be a whole number after (1), it isn't. I know deep down this is due to some minor floating point inaccuracy, but can someone explain to me why Perl isn't handling 3 significant digits accurately? And is there any way to tell when this inaccuracy arises? I've noticed that 18.15 does the same thing, for example, and 18.31.
How do I resolve this except making sure I use the Math::Round module everytime I do arithmetic?
I am using v5.8.0 built for i386-linux-thread-multi, with locally applied patches:
MAINT18379
Thanks,
Don.