[Purdue-pm] Computing Euler's Number (Perl Weekly Challenge 21)

Dave Jacoby jacoby.david at gmail.com
Mon Aug 12 11:32:31 PDT 2019

> Write a script to calculate the value of e, also known as Euler’s number
and Napier’s constant.

Which is 1 + ( 1 / $n ) )**$n , where $n approaches infinity.

It is easy to put that in a subroutine compute_euler ( $n ), and then
increment $n until you blow off the top of Perl 5's integer.

I think the closest you could get without getting into Math::BigFloat would
be 2.71828182845904 , and I'm not seeing clear enough documentation to
really work on it. I suspect that $x = Math::BigFloat->new( 1 + ( 1 / $n )
)**$n ) wouldn't work as intended, not because of problems with
Math::Float, but because Perl 5 can't handle the equation within the new()
well enough to give a Math::BigFloat result.

Meanwhile, another site says:

> But it is known to over 1 trillion digits of accuracy!

So, when is it "done"? When we get to billions of digits? The 50 digits
listed on the wiki page? compute_euler( 2 ** 53 ) to get the largest int
Perl can handle without BigInt?

I think this question is underspecified. Thoughts? Suggestions?
Dave Jacoby
jacoby.david at gmail.com

I deal with my software the way I treat my eldritch abomination:
 It's not human, it's not even alive in the natural sense.
 It's nightmare-born and nightmare-shaped, and nightmares don't die easy.
  -- @yenzie
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.pm.org/pipermail/purdue-pm/attachments/20190812/4e64dfad/attachment.html>

More information about the Purdue-pm mailing list