Why is math.pi slightly wrong?

Andrew Lee fiacre.patrick at gmail.com
Fri May 23 01:44:17 EDT 2008


Dan Upton wrote:
> On Thu, May 22, 2008 at 2:53 PM, Mensanator <mensanator at aol.com> wrote:
>> On May 22, 11:32 am, "Dutton, Sam" <Sam.Dut... at itn.co.uk> wrote:
>>> I've noticed that the value of math.pi -- just entering it at the interactive prompt -- is returned as 3.1415926535897931, whereas (as every pi-obsessive knows) the value is 3.1415926535897932... (Note the 2 at the end.)
>>>
>>> Is this a precision issue, or from the underlying C, or something else? How is math.pi calculated?
>> If you actually need that many digits, use a different library.
>>
>>>>> import gmpy
>>>>> print gmpy.pi(64) # 64 bit precision
>> 3.14159265358979323846
>>>>> print gmpy.pi(128) # 128 bit precision
>> 3.141592653589793238462643383279502884197
>>>>> print gmpy.pi(16384) # 16384 bit precision
>> 3.14159265358979323846264338327950288419716939937510582097494459

...

> 
> Who wants to verify that that's correct to that many digits? ;)


Ramanujan?

http://numbers.computation.free.fr/Constants/Pi/piramanujan.html




More information about the Python-list mailing list