Basicprogramming(.org) > Code and examples

Pi calculation

(1/2) > >>

Galileo:
I'm back.

Calculation of "some" pi digits.


--- Code: ---// Cálculo de pi --- Pi calculation
// Translation from Phix code to Yabasic by Galileo, 09/2018.

n = 35001 : a = 10000 : dim f(n)

for i = 1 to n : f(i) = 2000 : next i
 
for c = n to 14 step -14
d = 0
for b = c to 1 step -1
d = d * b
g = b * 2 - 1
d = d + f(b) * a
f(b) = mod(d, g)
d = int(d / g)
k = e + int(d / a)
next
k2$ = "000000" + str$(k)
print right$(k2$, 4);
e = mod(d, a)
next

print "\nTime insumed: ", peek("millisrunning") / 1000, " seconds."
--- End code ---

In my machine, delayed about 55 secs. Phix code about 21 secs.

Tomaaz:
It looks familiar. I think that the Pix code is a translation of my code.  ;)

Galileo:

--- Quote from: Tomaaz on September 05, 2018, 05:33:39 PM ---It looks familiar. I think that the Pix code is a translation of my code.  ;)

--- End quote ---

Could you show the code? What dialect did you use? What's the performance?

By the way, the same code in Lua 5.3 takes about 65 seconds (on my machine). I didn't expect it.

Tomaaz:
https://openeuphoria.org/forum/m/132983.wc

Euphoria and Lua.

Pirx == Tomaaz. I had problems with registering on that forum and tried several times. Finally they activated that Pirx account. Luajit less than 1 sec.

Galileo:
But LuaJIT doesn't belong in the same league. Or am I wrong?

Navigation

[0] Message Index

[#] Next page

Go to full version