Perl - 35 bytes
$\=$\/(2*$_-1)*$_+2for-46..-1;print
Produces full floating point precision. A derivation of the formula used can be seen elsewhere.
Sample usage:
$ perl pi.pl
3.14159265358979
Arbitrary Precision Version
use bignum a,99;$\=$\/(2*$_-1)*$_+2for-329..-1;print
Extend as needed. The length of the iteration (e.g. -329..-1
) should be adjusted to be approximately log2(10) ≈ 3.322 times the number of digits.
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211707
Or, using bigint
instead:
use bigint;$\=$\/(2*$_-1)*$_+2e99for-329..-1;print
This runs noticably faster, but doesn't include a decimal point.
3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067