in reply to e with continued fractions

The output of the obfuscated code seems to be good for about 45 places (at least on my box running Perl v5.8.3 built for i386-linux-thread-multi) before it differs from the reference values from the On-Line Encyclopedia of Integer Sequences.

If you want more precision, you might be interested in Unbounded Spigot Algorithms for the Digits of π by Jeremy Gibbons. It's a fun read, and you can adapt the methods presented in his paper to computing e digit by digit.

  • Comment on Good to about 45 places; spigot algorithm

Replies are listed 'Best First'.
Re: Good to about 45 places; spigot algorithm
by jdalbec (Deacon) on Jul 22, 2004 at 03:06 UTC

    The inaccuracy appears to be the result of roundoff error; use bigint; or use Math::BigInt ':constant'; (as suggested by tachyon and bageler) fixes that also.

    Also, my algorithm is streaming in Gibbons' sense. It represents the continued fraction as a composition of linear fractional transformations.