in reply to Re^3: Why does perl math suck?
in thread Why does perl math suck?
A more specific and illustrative example is $small+$huge1-$huge2 where ($small+$huge1)-$huge2 is easily much less accurate than $small+($huge1-$huge2) (where parens imply order of evaluation, which isn't always the case).
For example:
#!/usr/bin/perl -lw use strict; my $h1= my $h2= 1e20; my $s= 1.2345; print $s+$h1-$h2; print $s+($h1-$h2); __END__ 0 1.2345
(I'd actually be surprised to see an example where the difference you proposed, ($a+$b+$c)/$d vs $a/$d+$b/$d+$c/$d, made more than a couple of least-significant bits of difference in the result -- though that would be enough to thwart the use of ==, of course.)
- tye
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Why does perl math suck? (order)
by ikegami (Patriarch) on Jan 13, 2011 at 18:09 UTC | |
|
Re^5: Why does perl math suck? (order)
by ikegami (Patriarch) on Jan 13, 2011 at 17:06 UTC |