Math errors in python
Bengt Richter
bokr at oz.net
Sun Sep 19 21:32:23 EDT 2004
On 19 Sep 2004 15:24:31 -0700, danb_83 at yahoo.com (Dan Bishop) wrote:
[...]
>There are, of course, reasonably accurate rational approximations of
>pi. For example, 355/113 (accurate to 6 decimal places), 312689/99532
>(9 decimal places), or 3126535/995207 (11 decimal places). Also, the
>IEEE 754 double-precision representation of pi is equal to the
>rational number 4503599627370496/281474976710656.
>>> divmod(4503599627370496,281474976710656)
(16L, 0L)
a little glitch somewhere ? ;-)
Others are nice though, but the last one shows up same way:
>>> print '%s\n%s' %(ED('312689/99532').round(11), ED(math.pi,11))
ED('3.14159265362')
ED('3.14159265359')
>>> print '%s\n%s' %(ED('3126535/995207').round(13), ED(math.pi,13))
ED('3.1415926535887')
ED('3.1415926535898')
>>> print '%s\n%s' %(ED('4503599627370496/281474976710656'), ED(math.pi,'all'))
ED('16')
ED('3.141592653589793115997963468544185161590576171875')
Regards,
Bengt Richter
More information about the Python-list
mailing list