There's no need to memorize the digits of Pi. Just remember -1.
#!/usr/bin/perl
use Math::Complex;
use constant PI => -1 * log(-1) * sqrt(-1); printf "Pi is %.12f\n", PI;
use constant PI => 4 * atan(1);
pi = 2*(pi/2) = 2*atan( 1/0 ) = 2*atan(+Inf)
ferreira on 2006-04-21T23:59:58
use constant PI => 2 * atan2(1, 0);
Re:A more boring alternative...
brian_d_foy on 2006-04-21T19:22:32
No need for Math::Triig there, since it actually gets pi() from Math::Complex, which implements it assub pi () { 4 * CORE::atan2(1, 1) }If you want a few more digits...
runrig on 2006-04-21T19:25:36
use Math::NumberCruncher qw($PI);
print PI, "\n";Re:If you want a few more digits...
brian_d_foy on 2006-04-21T20:13:34
Math::NumberCruncher just hard-codes it. I can't post it here because there is some filter in Slashcode to block posts with "awful long string of letters". Feh$PI = new Math::BigFloat "3.141592653589793...";Re:If you want a few more digits...
runrig on 2006-04-21T22:53:02
Math::NumberCruncher just hard-codes it.Yeah, I knew that. So it was in a way an answer even more boring than the post I replied to
:-) Nothing exciting like using log(-1) = -πi
. But, having worked on the module, I just had to mention it:-) Re:If you want a few more digits...
brian_d_foy on 2006-04-21T22:58:07
Now I'm kinda wondering if I can coerce Math::BigNum into my solution somehow so it gets a couple hundred decimal places....
When I need to approximate PI, I just remember the sequence [1 1 3 3 5 5], rearranging its two halves to get:
which is correct to the first seven decimal places.my $PI = 355/113;
That's sufficiently accurate to compute the circumference of the Earth from its radius with an error of about 3 metres (out of 40 million metres). Close enough for most everyday calculations.
Re:My personal favorite...
brian_d_foy on 2006-04-21T22:39:55
It's probably exactly the circumference of the earth if you pick the right spot. Short by 3 meters? Just move a bit off the mountain.:)
since it relates the 5 most important constants. I hadn't realized if one solved this equation for pi that all the coefficients were -1, that's so cool.e ** pi * i + 1 = 0