home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #23 / NN_1992_23.iso / spool / sci / math / 13145 < prev    next >
Encoding:
Text File  |  1992-10-13  |  1.6 KB  |  36 lines

  1. Path: sparky!uunet!math.fu-berlin.de!news.netmbx.de!Germany.EU.net!mcsun!sun4nl!cwi.nl!dik
  2. From: dik@cwi.nl (Dik T. Winter)
  3. Newsgroups: sci.math
  4. Subject: Re: Calculating pi: help!
  5. Message-ID: <7557@charon.cwi.nl>
  6. Date: 14 Oct 92 02:28:33 GMT
  7. References: <Bw304E.LKu@mentor.cc.purdue.edu>
  8. Sender: news@cwi.nl
  9. Organization: CWI, Amsterdam
  10. Lines: 24
  11.  
  12. In article <Bw304E.LKu@mentor.cc.purdue.edu> falatic@mentor.cc.purdue.edu (MacGyver) writes:
  13.  > 
  14.  >     Just a quick query: I need a program, in either Unix C or Borland/
  15.  > Turbo C, that will calculate Pi as far as I want... I can get it to 17 
  16.  > digits, but I want to get it to an UNLIMITED number of digits (I know, it'd
  17.  > be slow, but I just want to do it.
  18. If you calculate it to 5 billion digits you will be famous.  (The current
  19. record is 2.16 billion digits).  As far as I know there is currently no
  20. reasonably fast algorithm that will give you any number of digits.  Current
  21. algorithms are designed to calculate a predefined number of digits, you
  22. can get less, but not more.  Just today I attended a lecture by Kanada
  23. (Prof. Pi) who calculated pi to 1 billion digits, it took (if I remember
  24. right) 7 hours on a Hitac 820; which is a Japanese supercomputer from
  25. Hitachi; 2 nsec. cycle time.
  26. But below you will find a short C program that will give you
  27. pi to 800 digits:
  28.  
  29. 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
  30. -=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);}
  31.  
  32. It takes less than a second on a high-end work-station.
  33. -- 
  34. dik t. winter, cwi, kruislaan 413, 1098 sj  amsterdam, nederland
  35. home: bovenover 215, 1025 jn  amsterdam, nederland; e-mail: dik@cwi.nl
  36.