Hi,
already discussed here few time. It's float precision problem. I think the
problem is inherited from C.
Yossi
"Yishay Weiss"
<yishayjobs at hotm To: perl at perl.org.il
ail.com> cc:
Sent by: Subject: [Israel.pm] math problem
perl-bounces at per
l.org.il
13/11/2005 12:43
Please respond
to Perl in
Israel
Hi,
This here is so basic I can't imagine it wasn't discussed before. Still,
does anyone care to tell me what's going on here? Can perl be failing to
subtract properly?
I run this script: (perl 5.8.4 on windows XP, but I also tried it with
5.8.0
on Linux)
========
$a = 0.3847;
$b = 0.4303;
$c = 0.0456;
$result = $b - $c;
print "a: $a\nresult: $result\n";
print "a == result ? ". ($a == $result)."\n";
=====
and I get:
=====
a: 0.3847
result: 0.3847
a == result ?
=======
Which is wrong. Then I run the same script with slightly bigger numbers:
========
$a = 0.3847 * 10;
$b = 0.4303 * 10;
$c = 0.0456 * 10;
$result = $b - $c;
print "a: $a\nresult: $result\n";
print "a == result ? ". ($a == $result)."\n";
=========
and get:
========
a: 3.847
result: 3.847
a == result ? 1
=======
Which makes perfect sense. Any ideas?
Yishay
_______________________________________________
Perl mailing list
Perl at perl.org.il
http://perl.org.il/mailman/listinfo/perl