pete wrote:

> (E-Mail Removed) wrote:

>

> > #define PI 3.142857

>

> #define PI 3.14159265

>

> I consider most mnemonics for PI digits, to be idiotic.

>

> shekharpati is using twenty two sevenths.

> To use that, you have to remember a two digit number,

> a one digit number, an operation, and the fact that it

> only gets you three significant figures.
355/113 gives you seven sig. digits. Some other interesting nums:

312689 / 99532 = 3.141592653618936 error 0.000000000029144

833719 / 265381 = 3.141592653581078 error 0.000000000008715

1146408 / 364913 = 3.141592653591404 error 0.000000000001611

4272943 / 1360120 = 3.141592653589389 error 0.000000000000404

5419351 / 1725033 = 3.141592653589815 error 0.000000000000022

58466453 / 18610450 = 3.141592653589784 error 0.000000000000009

74724506 / 23785549 = 3.141592653589791 error 0.000000000000002

80143857 / 25510582 = 3.141592653589793 error 0.000000000000000

Output from ratpi.c, following:

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

#include <float.h>

/* Public domain by C.B Falconer, 2003-06-04 */

int main(int argc, char **argv)

{

int num, approx, bestnum, bestdenom;

int lastnum = 500;

double error, leasterr, pi, criterion;

pi = 4 * atan(1.0);

criterion = 2 * pi * DBL_EPSILON;

if (argc > 1) lastnum = strtol(argv[1], NULL, 10);

if (lastnum <= 0) lastnum = 500;

printf("Usage: ratpi [maxnumerator]\n"

"Rational approximation to PI = %.*f\n", DBL_DIG, pi);

for (leasterr = pi, num = 3; num < lastnum; num++) {

approx = (int)(num / pi + 0.5);

error = fabs((double)num / approx - pi);

if (error < leasterr) {

bestnum = num;

bestdenom = approx;

leasterr = error;

printf("%8d / %-8d = %.*f error %.*f\n",

bestnum, bestdenom,

DBL_DIG, (double)bestnum / bestdenom,

DBL_DIG, leasterr);

if (leasterr <= criterion) break;

}

}

return 0;

} /* main */

My machine takes 25 sec. to evaluate ratpi 99999999. Probably a

useful benchmark. Here it is virtually immune to gcc optimization,

except -Os which bumps it to 31 sec.

--

"If you want to post a followup via groups.google.com, don't use

the broken "Reply" link at the bottom of the article. Click on

"show options" at the top of the article, then click on the

"Reply" at the bottom of the article headers." - Keith Thompson