Difference between revisions of "Alt e.pl"
From Organic Design wiki
m |
m |
||
Line 1: | Line 1: | ||
− | # Returns e^x from e( x, iterations ) | + | <perl> |
+ | # Returns e^x from e( x, iterations ) | ||
sub e { | sub e { | ||
$x = $y = shift; | $x = $y = shift; | ||
Line 10: | Line 11: | ||
return $top / $bot; | return $top / $bot; | ||
} | } | ||
+ | </perl> |
Revision as of 04:36, 21 December 2010
<perl>
- Returns e^x from e( x, iterations )
sub e { $x = $y = shift; $top = $bot = 1; for $n ( 1 .. shift ) { $y = $y + $x; $top = $top * $n + $y; $bot = $bot * $n; } return $top / $bot; } </perl>