Pi Is Rational?
Approximations
It is almost
Pi Day, the celebration of everyone’s favorite
irrational number, as well as my birthday. To celebrate, I was messing around with some code that would generate closer and closer
rational approximations of pi. I originally set the while loop to run forever just to watch more results come in until I felt like stopping it, but noticed something interesting. Once it got to the 180th approximation, the error dropped to 0.0. This means that according to python, there is absolutely no difference between $\frac{245850922}{78256779}$ and pi itself. Pi is rational after all! Of course, this isn’t true. What is actually happening is that the value of pi that I am comparing my approximation to: math.pi from python’s
math library, is only an approximation itself. It is represented by an
IEEE 754 double-precision binary floating-point number, AKA a double. Doubles are only capable of storing about 15 or so decimal digits, which my approximation achieves. When including math.pi in the standard library, they get as close as possible within the limits of an IEEE 754 double to the true value with the approximation 3.141592653589793
.