Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83 (MC830713); site vu44.UUCP Path: utzoo!watmath!clyde!cbosgd!ihnp4!zehntel!hplabs!hao!seismo!mcvax!vu44!tstorm From: tstorm@vu44.UUCP (Theo van der Storm) Newsgroups: net.math Subject: Re: multiple-precision arithmetic Message-ID: <518@vu44.UUCP> Date: Sun, 9-Dec-84 11:26:36 EST Article-I.D.: vu44.518 Posted: Sun Dec 9 11:26:36 1984 Date-Received: Tue, 11-Dec-84 04:49:21 EST References: <163@faron.UUCP> <732@reed.UUCP> <6213@mcvax.UUCP> Organization: VU Informatica, Amsterdam Lines: 48 Here is another (faster) algorithm to calculate pi. The algorithm that was posted by mcvax!steven seems to be working with unnecessary big numbers, although it is in some sense "incremental". This algorithm is not "incremental". ::::::::::::::::::::::::::: First a B implementation of the algorithm: ::::::::::::::::::::::::::: HOW'TO PI n: \ Print the first n decimals of pi. mcvax!vu44!tstorm WRITE 'Approximation of pi in `n` digits' / WRITE (arcam(48,18,n))+(arcam(32,57,n))+(arcam(-20,239,n)) / YIELD arcam(a, m, n): \ Calculate (10**n)*a*arctan(1/m), mcvax!vu44!tstorm PUT floor(((10**n)*a)/m), -m*m, 0, 1, 0 IN t, mc, s, kk, i WHILE t<>0: PUT s+floor(t/kk) IN s PUT floor(t/mc), kk+2, i+1 IN t, kk, i IF m=18: WRITE 'Error < `i+i` units of the last decimal' / RETURN s+ceiling(i/2) ::::::::::::::::::::::::::: And now a BC implementation Old BC versions use the =OP notation the version I'm working with uses OP= notation. Change line 5 if necessary. ::::::::::::::::::::::::::: define t(a, m, n){ /* calculate (10^n)*a*arctan(1/m), mcvax!vu44!tstorm */ t = ((10^n)*a)/m; c = -m*m; s = 0; k = 1 while (t != 0){ s += t/k; t /= c; k += 2 } return(s) } define p(n){ "Approximation of pi. Number of digits: "; n scale = 0; return(t(48, 18, n)+t(32, 57, n)+t(-20, 239, n)) } ::::::::::::::::::::::::::: -- Theo van der Storm, 52 20'N / 4 52'E, {seismo|decvax}!mcvax!vu44!tstorm