Jan-08-2018, 05:08 AM
(Jan-08-2018, 04:23 AM)Skaperen Wrote: ah! in C code. that's why my search didn't find it. FYI, here is how my C code defines Pi so it can work with some higher precision architectures with long double:
#define Pi (8552228672519733982877442985294966266405.0L/2722258935367507707706996859454145691648.0L)
basically that is Pi scaled up by 2**131 divided by 2**131.
Unfortunately, your fraction only provides 53 bits of accuracy, not the 64 bits required by long double.
>>> import math >>> math.pi 3.141592653589793 >>> >>> import gmpy2 >>> gmpy2.get_context().precision=200 >>> gmpy2.const_pi() mpfr('3.1415926535897932384626433832795028841971693993751058209749445',200) >>> a=gmpy2.mpfr(8552228672519733982877442985294966266405.0) >>> b=gmpy2.mpfr(2722258935367507707706996859454145691648.0) >>> a/b mpfr('3.141592653589793115997963468544185161590576171875',200) >>> # Incorrect after ^You can check the bit patterns of the the mantissa in gmpy2.
>>> a mpfr('8552228672519733649496873820484995645440.0',200) >>> b mpfr('2722258935367507707706996859454145691648.0',200) >>> (a/b).digits(2) ('11001001000011111101101010100010001000010110100011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', 2, 200) >>> gmpy2.const_pi(precision=64).digits(2) ('1100100100001111110110101010001000100001011010001100001000110101', 2, 64) >>> gmpy2.const_pi(precision=53).digits(2) ('11001001000011111101101010100010001000010110100011000', 2, 53) >>>casevh