pi
Blitz3D Forums/Blitz3D Beginners Area/pi
| ||
How can I right a program which will work out pie for aslong as it runs I would think it would be quite simple! I found some formulas c/d ; A/r2 4arctan1 4(4arctan1/5 - arctan1/239) 4(2arctan1/3 + arctan1/7) 4(5arctan1/7 + 2arctan3/79) 4(4arctan1/5 - arctan1/70 + arctan1/99) 4(45/[360/2Pi]) sqr {6 [1/(12) + 1/(22) + 1/(32)]} sqr {6 [22/(22-1) * 32/(32-1) * 52/(52-1) * 72/(72-1) * 112/(112-1) * ...]} cuberoot {32 [1/(13) - 1/(33) + 1/(53) - 1/(73) ...]} fourthroot {90 [1/(14)+ 1/(24) + 1/(34) + ...]} 2(3/2*5/6*7/6*11/10*13/14*17/18*19/18*23/22*...) sqr(12Li2[1/2] + 6[ln2]2) |
| ||
If you want to work out the value of pi, just use:- pi = 22.0 / 7.0 |
| ||
It should be noted that 22/7 is only accurate enough for estimation purposes, as the value is not truly Pi. And it's probably not as easy as you think... See How Pi Works (and the links below). |
| ||
Make sure the variable you use is a floating point variable too, otherwise it will just come out as 3. |
| ||
mmmmm, pie |
| ||
const pi = 3.1415926536 Works for me. :) |
| ||
Erm, the Pi constant is built in blitz already.Print Pi.Crazy, eh? |
| ||
I think what is required here is an iterative process to calculate Pi... to more than the accuracy of the built-in value. I doubt that BB is the best language to try this in though, as you would need to define your own number types to get around the limited accuracy of floats or the max/min values for long ints. [e.g. by the time you are calculating small differences of 0.0000000000000001, you are probably stressing the accuracy of internally stored values.] This kind of problem would normally be tried in a language like FORTRAN that has more scope for defining the precision of variables. I do remember seeing a BBC Basic program to do this many years ago... I will do a quick search to see what I can find... Good options might be... The Monte Carlo method (similar to Count Bouffon's if memory serves me right !) would make a good 'visual' calcualtion of Pi as you show which 'darts' thrown at a circle in a square are 'hits' or 'misses' http://www.ticalc.org/archives/news/articles/2/28/28666.html and some others including the Gregory series as downloadable VB code... http://www.vb-helper.com/howto_calculate_pi_series.html |
| ||
o |
| ||
I think what is required here is an iterative process to calculate Pi... to more than the accuracy of the built-in value What's the point, in the end it will be stored in a float value, and you won't get any additional accuracy. To have a better accuracy you'd need higher precision floating points values.You *can't* have a more accurate value for Pi if you store it in a simple float variable. |
| ||
there are double presision floats in 'C' 64bit floats ,, how acurate does it need to be |
| ||
40*Atan[1] (not the Atan in Blitz, though) returns a few digits. I'm interested in seeing how this progresses. http://www.cecm.sfu.ca/projects/ISC/dataB/isc/C/pi10000.txt If you just want pi though, that's worth a look. Not that many digits, but probably more than you need for your standard tasks. |
| ||
pi is infinite :) i love pi |
| ||
I had a program once that did pi to any number of decimal points as long as your memory could hold it. I believe it was on the Amiga, I know there is a formula that you just iterate over and over again to get as much accuracy as you want. Keep looking. I remember pi off by heart to a few decimal points. 3.141592653589793236 I think that is right. I used to know it to 40 decimal points but forgot. I did run that program I had and printed pi out to 1000 decimal points. So I know it works, just don't remember the formula. I do seem to remember it used 2 sets of values and flipped back and forth between them. |