in reply to Exponential Function Programming
# exp. $n = 2; $e_n = exp($n); print "e^$n = $e_n\n"; sub my_factorial { my $n = shift; my $s=1; my $r=1; while ($s <= $n) { $r *= $s; $s++; } if($n == 0) { $r=0; } return $r; } sub my_exp_x { my $x = shift; my $max_iterations = shift; my $result = 1 + $x; my $i = 2; while ($i < $max_iterations) { $result += ($x ** ($i)) / (my_factorial($i)); $i++; } return $result; } print "test: ", my_exp_x($n,1000);


Replies are listed 'Best First'.  

Re^2: Exponential Function Programming
by Dominus (Parson) on Nov 23, 2007 at 19:45 UTC  
by blazar (Canon) on Nov 24, 2007 at 13:42 UTC  
Re^2: Exponential Function Programming
by Abulil (Initiate) on Nov 22, 2007 at 15:57 UTC  
by okram (Monk) on Nov 22, 2007 at 16:03 UTC  
by ikegami (Patriarch) on Nov 22, 2007 at 19:38 UTC  

In Section
Seekers of Perl Wisdom