home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ogicse!uwm.edu!zaphod.mps.ohio-state.edu!news.acns.nwu.edu!nucsrl!kaufman
- From: kaufman@eecs.nwu.edu (Michael L. Kaufman)
- Newsgroups: sci.math
- Subject: Here's a program to compute pi quickly
- Message-ID: <1992Oct16.153942.28398@eecs.nwu.edu>
- Date: 16 Oct 92 15:39:42 GMT
- Article-I.D.: eecs.1992Oct16.153942.28398
- Sender: kaufman@eecs.nwu.edu (Michael L. Kaufman)
- Organization: EECS Department, Northwestern University
- Lines: 42
-
- Since I asked the question in the first place, I thought I would post an
- answer. I found this in David Wells's book _The Penguin Dictionary of
- Curious and Intersting Numbers_. (The book by the way is quite interesting,
- although I have found a few mistakes in it.) The method, goes like this:
-
- #include <math.h>
- main()
- {
- float x,y,a,b,c;
- int ch = 1;
-
- a = x = 1.0;
- c = 0.25;
- b = 1 / sqrt(2);
-
-
- while(ch != 'q')
- {
- y = a;
- a = (a + b) / 2.0;
- b = sqrt(b * y);
- c = c - x * (a - y) * (a - y);
- x = 2.0 * x;
-
- printf("%10g\n", (a + b) * (a + b) / (4 * c));
- ch = getchar();
- }
- }
-
-
-
- Each pass through the loop doubles the number of digits you have.
-
- Anyhow, thanks to the people who helped me, and I hope this helps someone else.
-
- Michael
-
- --
- Michael Kaufman | I've seen things you people wouldn't believe. Attack ships on
- kaufman | fire off the shoulder of Orion. I watched C-beams glitter in
- @eecs.nwu.edu | the dark near the Tannhauser gate. All those moments will be
- | lost in time - like tears in rain. Time to die. Roy Batty
-