Re: Why is math.pi slightly wrong?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew Lee

    Re: Why is math.pi slightly wrong?

    Dan Upton wrote:
    On Thu, May 22, 2008 at 2:53 PM, Mensanator <mensanator@aol .comwrote:
    >On May 22, 11:32 am, "Dutton, Sam" <Sam.Dut...@itn .co.ukwrote:
    >>I've noticed that the value of math.pi -- just entering it at the interactive prompt -- is returned as 3.1415926535897 931, whereas (as every pi-obsessive knows) the value is 3.1415926535897 932... (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.141592653589 79323846
    >>>>print gmpy.pi(128) # 128 bit precision
    >3.141592653589 793238462643383 279502884197
    >>>>print gmpy.pi(16384) # 16384 bit precision
    >3.141592653589 793238462643383 279502884197169 399375105820974 94459
    ....
    >
    Who wants to verify that that's correct to that many digits? ;)

    Ramanujan?



  • Dutton, Sam

    #2
    RE: Why is math.pi slightly wrong?

    Thanks for all the answers and comments.
    >math.pi is exactly equal to 884279719003555/281474976710656 , which is the closest C double to the actual value of pi
    So much for poor old 22/7...

    Sam






    SAM DUTTON
    SENIOR SITE DEVELOPER

    200 GRAY'S INN ROAD
    LONDON
    WC1X 8XZ
    UNITED KINGDOM
    T +44 (0)20 7430 4496
    F
    E Sam.Dutton@itn. co.uk


    P Please consider the environment. Do you really need to print this email?
    Please Note:



    Any views or opinions are solely those of the author and do not necessarilyrepr esent
    those of Independent Television News Limited unless specifically stated.
    This email and any files attached are confidential and intended solely for the use of the individual
    or entity to which they are addressed.
    If you have received this email in error, please notify postmaster@itn. co.uk

    Please note that to ensure regulatory compliance and for the protection of our clients and business,
    we may monitor and read messages sent to and from our systems.

    Thank You.


    Comment

    • inhahe

      #3
      Re: Why is math.pi slightly wrong?

      """
      "Dutton, Sam" <Sam.Dutton@itn .co.ukwrote in message
      news:mailman.15 01.1211543292.1 2834.python-list@python.org ...
      Thanks for all the answers and comments.
      >math.pi is exactly equal to 884279719003555/281474976710656 , which is the
      >closest C double to the actual value of pi
      So much for poor old 22/7...

      Sam
      """

      The biblically correct version:

      import math
      math.pi = 3









      Comment

      Working...