Difference between revisions of "Alt e.pl"

From Organic Design wiki
m (fix up code blocks)
 
Line 1: Line 1:
<perl>
+
<source lang="perl">
 
# Returns e^x from e( x, iterations )
 
# Returns e^x from e( x, iterations )
 
sub e {
 
sub e {
Line 11: Line 11:
 
return $top / $bot;
 
return $top / $bot;
 
}
 
}
</perl>
+
</source>
 
[[Category:PERL]]
 
[[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;
}