in reply to Re: Exponential Function Programming
in thread Exponential Function Programming
$ret - $d != $ret is interesting. One would think it's the same as $d (in boolean context), but it isn't. By testing the effect of $d ($ret - $d != $ret) instead of $d itself, the loop can be ended sooner.
my $ret = 1; for my $d (1e-15, 1e-20) { printf("%g %d %d\n", $d, ( $d )?1:0, ( $ret-$d != $ret )?1:0, ); }
1e-015 1 1 # Often equivalent. 1e-020 1 0 # But not when there's an underflow.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Exponential Function Programming
by pajout (Curate) on Nov 23, 2007 at 18:21 UTC | |
by ikegami (Patriarch) on Nov 23, 2007 at 18:44 UTC | |
by pajout (Curate) on Nov 23, 2007 at 19:05 UTC |
In Section
Seekers of Perl Wisdom