Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Exponential Function Programming

by fenLisesi (Priest)
on Nov 22, 2007 at 17:21 UTC ( #652421=note: print w/replies, xml ) Need Help??

in reply to Exponential Function Programming

#!/usr/bin/perl -wTl use strict; use warnings; use bignum 'bexp'; ## get the latest from CPAN use Memoize; use constant MAX_POWER => 30; use constant MAX_DIGITS => 50; my $X = shift || 1; memoize('my_factorial'); my $best = bexp( $X, MAX_DIGITS ); my $estimate = 1; for my $i (1 .. MAX_POWER) { $estimate += ($X ** $i) / my_factorial( $i ); print join "\n", ($i, $best, $estimate, abs( $best - $estimate ), q()); } exit( 0 ); ##--------------------------------------------------+ sub my_factorial { my ($n) = @_; return 1 if $n == 1; $n * my_factorial( $n - 1 ); }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://652421]
[LanX]: ha the Cuban experience
[LanX]: one strange thing I heard was that pharmacies in Vietnam are run by Russians
[LanX]: still can't believe this, must h have been a misunderstanding
[choroba]: fortunately, I haven't the need to verify this
[choroba]: haven't had

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2017-02-26 04:55 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (371 votes). Check out past polls.