home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!math.fu-berlin.de!news.netmbx.de!Germany.EU.net!mcsun!sun4nl!cwi.nl!dik
- From: dik@cwi.nl (Dik T. Winter)
- Newsgroups: sci.math
- Subject: Re: Calculating pi: help!
- Message-ID: <7557@charon.cwi.nl>
- Date: 14 Oct 92 02:28:33 GMT
- References: <Bw304E.LKu@mentor.cc.purdue.edu>
- Sender: news@cwi.nl
- Organization: CWI, Amsterdam
- Lines: 24
-
- In article <Bw304E.LKu@mentor.cc.purdue.edu> falatic@mentor.cc.purdue.edu (MacGyver) writes:
- >
- > Just a quick query: I need a program, in either Unix C or Borland/
- > Turbo C, that will calculate Pi as far as I want... I can get it to 17
- > digits, but I want to get it to an UNLIMITED number of digits (I know, it'd
- > be slow, but I just want to do it.
- If you calculate it to 5 billion digits you will be famous. (The current
- record is 2.16 billion digits). As far as I know there is currently no
- reasonably fast algorithm that will give you any number of digits. Current
- algorithms are designed to calculate a predefined number of digits, you
- can get less, but not more. Just today I attended a lecture by Kanada
- (Prof. Pi) who calculated pi to 1 billion digits, it took (if I remember
- right) 7 hours on a Hitac 820; which is a Japanese supercomputer from
- Hitachi; 2 nsec. cycle time.
- But below you will find a short C program that will give you
- pi to 800 digits:
-
- int a=10000,b,c=2800,d,e,f[2801],g;main(){for(;b-c;)f[b++]=a/5;for(;d=0,g=c*2;c
- -=14,printf("%.4d",e+d/a),e=d%a)for(b=c;d+=f[b]*a,f[b]=d%--g,d/=g--,--b;d*=b);}
-
- It takes less than a second on a high-end work-station.
- --
- dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland
- home: bovenover 215, 1025 jn amsterdam, nederland; e-mail: dik@cwi.nl
-