How is pi (π) calculated?

In calculus there is a thing called Taylor Series which provides an easy way to calculate many irrational values to arbitrary precision. Pi/4 = 1 – 1/3 + 1/5 – 1/7 + … (from http://www.math.hmc.edu/funfacts/ffiles/30001.1-3.shtml ) Keep adding those terms until the number of digits of precision you want stabilize. Taylor’s theorem is a powerful … Read more

How to printf long long

%lld is the standard C99 way, but that doesn’t work on the compiler that I’m using (mingw32-gcc v4.6.0). The way to do it on this compiler is: %I64d So try this: if(e%n==0)printf(“%15I64d -> %1.16I64d\n”,e, 4*pi); and scanf(“%I64d”, &n); The only way I know of for doing this in a completely portable way is to use … Read more

Why does Python’s hash of infinity have the digits of π?

Summary: It’s not a coincidence; _PyHASH_INF is hardcoded as 314159 in the default CPython implementation of Python, and was picked as an arbitrary value (obviously from the digits of π) by Tim Peters in 2000. The value of hash(float(‘inf’)) is one of the system-dependent parameters of the built-in hash function for numeric types, and is … Read more