Occasionally, it is useful to have a rational approximation for Pi.
Some environments immediately come to mind:
*Pedantry requires pointing out that floats use rational approximations of Pi as well; with the restriction that the denominator is a negative power of some radix--10 if you're a human, 2 if you're a computer....*
[This may be true, but with a floating point package it's possible to just write 3.14159 as a constant. In the absence of floats, this is not possible and you must either divide or use scaled integers.]
Using the expression pi ~= a/b, here are some values for (a) and (b) that yield more-or-less usable values for Pi:
*Did you use continued fractions to approximate the decimal value, or some other trick?*
As much as I would like to take credit for this, no. This is compiled from data extracted from a number of sources, some of whom did indeed use continued fractions. -- GarryHamilton
*Does the table have the property for that for every (A/B) listed, there is no closer approximation (A'/B') for which B' <= B?*
Yes, that's why those selected values were chosen. There are intermediate values (like 25/8) that are "in the ball park" but for which a lower value of B' exists that produces a more accurate estimate of Pi.
*25/8 is useful in that 8 is a power of two, so the result can be performed with bit-shifting. This is useful if you're working with a primitive microprocessor, where it's easier to shift bits than to divide integers. 101/32 and 201/64 get a little closer, and 201/64 only requires two shifts left and throwing away the least significant byte to perform the division. --NickBensema*

See ContinuedFractions for a demonstration of a small piece of code that finds the "best" rational approximation to pi, e, sqrt(2), etc. -- DougMerritt See also ValueOfPi

CategoryMath

- you don't have floating point math available but need to calculate with Pi
- you don't want the overhead of loading the floating point package

( a ) ( b ) ~pi value error (abs(pi - a/b)) 3 1 3 .141592645 ... 19 6 3.166666666666666 .0250740130 ... 22 7 3.142857142857142 .0012644892 ... ** 179 57 3.140350877192982 .0012417763 ... 201 64 3.140625000000000 .0009676535 ... 223 71 3.140845070422535 .0007475831 ... 245 78 3.141025641025641 .0005670125 ... 267 85 3.141176470588235 .0004161830 ... 289 92 3.141304347826086 .0002883057 ... 311 99 3.141414141414141 .0001785121 ... 333 106 3.141509433962264 .0000832196 ... 355 113 3.141592920353982 .0000002667 ... *** 52163 16604 3.141592387376535 .0000002662 ... 3 1 3 .14 25 8 3.125 .017 101 32 3.15625 .01466 201 64 3.140625 .000967 3217 1024 3.1416015625 .0000089 ...The fraction 22/7 is probably the easiest to remember, but the most useful of these is arguably 355/113 since it is good to more than 5 places and requires only 3 digits for both (a) and (b), and is fairly easy to memorize. If you take the digits 113355, cut in the middle, and swap them, you have 355/113; an easy memory trick.

See ContinuedFractions for a demonstration of a small piece of code that finds the "best" rational approximation to pi, e, sqrt(2), etc. -- DougMerritt See also ValueOfPi

CategoryMath

View edit of April 28, 2008 or FindPage with title or text search