On Sat, Mar 13, 1999 at 01:57:58PM +0800, ivan wrote: > > Check out sci.math & the sci.math FAQ (lost the url-sorry) - the faq has > extensive descriptions of several different algorithms for calculating pi.
I don't know if it's there, but I like the Monte Carlo method the best. You draw a circle in a square (diameter two, square has edges of length two, too). Then you throw stones and count the nr of stones in the circle, C, and the number of stones in the square but not in the circle, S, (stones outside of the square don't count at all --- ignore them). Then 4*C/(C+S) is near pi. Of course, you would need a good random number generator to implement this. /dev/urandom will be slow, but a good choice. Also, to implement this, I would use coordinates that go diagonally through the square (then a stone is inside the square iff |x+y| <= 1, which is hopefully faster then |x|<=1 and |y|<=1, and in the circle, iff x²+y²<=1, which is fast, too) If you use < or <= shouldn't matter, because a line has no area (the limit should be the same). But then, this is not the best method to calculate PI, but it has interesting philosophical implications if you try to define it this way (or even if you want to proof that this definition is equal to other). Sorry, I was carried away :) Maybe we need debian-math. Marcus -- `Rhubarb is no Egyptian god.' Debian http://www.debian.org finger brinkmd@ Marcus Brinkmann GNU http://www.gnu.org master.debian.org [EMAIL PROTECTED] for public PGP Key http://homepage.ruhr-uni-bochum.de/Marcus.Brinkmann/ PGP Key ID 36E7CD09