Difference between revisions of "Alt e.pl"
From Organic Design wiki
m |
m (fix up code blocks) |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
| − | # Returns e^x from e( x, iterations ) | + | <source lang="perl"> |
| + | # Returns e^x from e( x, iterations ) | ||
sub e { | sub e { | ||
$x = $y = shift; | $x = $y = shift; | ||
| Line 7: | Line 8: | ||
$top = $top * $n + $y; | $top = $top * $n + $y; | ||
$bot = $bot * $n; | $bot = $bot * $n; | ||
| − | + | } | |
return $top / $bot; | return $top / $bot; | ||
| − | + | } | |
| + | </source> | ||
| + | [[Category:PERL]] | ||
Latest revision as of 17:09, 22 May 2015
# 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;
}



