|
Post by matthew on Apr 29, 2011 16:01:03 GMT -5
Based on the programs in this thread on the Ubuntu Forum, I thought I would recreate them in Basic4GL. More about the mathematics involved can be found here. It takes about 30 seconds to calculate on my computer. TextMode(TEXT_BUFFERED)
dim k, frac#, sum# dim startTime# = 0.0, endTime# = 0.0
startTime# = tickcount()
for k = 0 to 10000000 ' Takes about 30 seconds on my computer
frac# = 0.0 frac# = 4 * pow(-1.0, k) / (2.0 * k + 1) sum# = sum# + frac# next
endTime# = tickCount()
printr "Pi: " ; sum# printr "Pi: " ; M_PI printr "Time: " ; (endTime# - startTime#) / 1000.0 ; " Seconds"
DrawText()
beep()
|
|
|
Post by shadow008 on Apr 29, 2011 23:10:55 GMT -5
35.4 Seconds here. Nice program But a quick exact calculation for pi is: PI = ATand(1) * (M_PI/180) * 4 ... Wait, that has an M_PI in it... Oh well, im not sure where the direct compatibility for radians are in B4GL so...
|
|
|
Post by matthew on Apr 30, 2011 6:14:46 GMT -5
Oh for sure there are easier & more accurate ways of generating Pi in Basic4GL, such as the following code.
cls : printr 4 * atn(1) : drawtext()
I was just showing a different way of calculating it - it might be good to use this thread to show all the different techniques that can be used to generate Pi.
|
|
|
Post by PeterMaria on Apr 30, 2011 7:05:51 GMT -5
This is simplest. Attachments:
|
|
|
Post by matthew on Apr 30, 2011 7:34:20 GMT -5
ROFL nice try peter
|
|
|
Post by Darkjester on May 1, 2011 19:01:30 GMT -5
wheres my like button! 12.5 seconds
|
|
|
Post by Nicky Peter Hollyoake on May 1, 2011 20:10:10 GMT -5
This is simplest. LOL 17.5 seconds. - Nicky
|
|