Author Topic: Pi calculation  (Read 2556 times)

Galileo

  • Guest
Pi calculation
« on: September 05, 2018, 05:26:51 PM »
I'm back.

Calculation of "some" pi digits.

Code: [Select]
// 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."

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

Tomaaz

  • Guest
Re: Pi calculation
« Reply #1 on: September 05, 2018, 05:33:39 PM »
It looks familiar. I think that the Pix code is a translation of my code.  ;)

Galileo

  • Guest
Re: Pi calculation
« Reply #2 on: September 05, 2018, 05:51:04 PM »
It looks familiar. I think that the Pix code is a translation of my code.  ;)

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

  • Guest
Re: Pi calculation
« Reply #3 on: September 05, 2018, 05:55:16 PM »
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.
« Last Edit: September 05, 2018, 05:59:46 PM by Tomaaz »

Galileo

  • Guest
Re: Pi calculation
« Reply #4 on: September 06, 2018, 03:05:05 PM »
But LuaJIT doesn't belong in the same league. Or am I wrong?

Tomaaz

  • Guest
Re: Pi calculation
« Reply #5 on: September 06, 2018, 04:58:12 PM »
But LuaJIT doesn't belong in the same league.

And why would that be?

ZXDunny

  • Guest
Re: Pi calculation
« Reply #6 on: September 06, 2018, 10:00:31 PM »
About the only reason I can think of is that LuaJIT executes compiled code (in the form of a dynarec) as opposed to a bytecode or pure interpreting engine.

Tomaaz

  • Guest
Re: Pi calculation
« Reply #7 on: September 06, 2018, 10:26:09 PM »
About the only reason I can think of is that LuaJIT executes compiled code (in the form of a dynarec) as opposed to a bytecode or pure interpreting engine.

Yes, but by accepting this point of view you agree that we can't compare almost anything. BaCon, Pure Basic, NaaLaa, Yabasic, Luajit - they all do things in a different way. You can't even compare 32-bit version of FreeBASIC to it's 64-bit equivalent, cause one translates to C and use C compiler, while the other don't (forgive me, if I'm wrong). And I think it's more interesting to compare different things than to compare similar things.

ZXDunny

  • Guest
Re: Pi calculation
« Reply #8 on: September 07, 2018, 12:09:30 PM »
To be honest, I've been thinking about using a Dynarec for SpecBAS. There's only so far a stack-based bytecode implementation will take you for speed concerns. But then, SpecBAS doesn't really need it as nobody is using it for CPU-intensive tasks (and that's not a job for a BASIC in any case, IMO), and as all the heavy lifting is done via my library of support routines, the language itself is just a method for calling that at the end of the day.

To be fair, I suppose if LuaJIT is BASIC-alike enough in its language implementation (and that's a very, very wide field these days - we have strayed so, so far from Dartmouth) then it can indeed be compared to others.

Galileo

  • Guest
Re: Pi calculation
« Reply #9 on: September 07, 2018, 05:49:00 PM »
Phix-to-Yabasic conversion again. Little faster.

Code: [Select]
t1 = peek("millisrunning")

chki = 1
a = 10000
c = 35000 // 8400
fr = int(a / 5)
dim f(c)

for i = 1 to c : f(i) = fr : next

while(c > 0)
    g = 2 * c
    d = 0
    b = c
    while(b > 0)
        d = d + f(b) * a
        g = g - 1
        f(b) = mod(d, g)
        d = int(d / g)
        g = g - 1
        b = b - 1
        if not(b = 0) d = d * b
    wend
    c = c - 14
    n4$ = str$(e + int(d / a),"%04g")
    print n4$;
    e = mod(d, a)
wend

print "\nTime elapsed: ", (peek("millisrunning") - t1) / 1000, " seconds"