pi script for your pi needs

  • QuanTech
    5th Mar 2017 Member 1 Permalink

    Hey guys, I got bored and decided to create a script that generates pi to arbitrary precision. I know lua already has math.pi, but I got bored! Anyways, it uses an infinite product series. Here:

    len = 2^20 --this sets precision. Anything higher slows the script down.
    a = {}
    b = {}
    for j=2,len do a[j]=2*math.floor(j/2) end --generate a series of even numbers in table a
    for k=2,len do b[k]=(2*math.floor(k/2))+1 end --generate a series of odd numbers in table b
    pie = 1
    for i=2,len do pie=pie*(a[i]*b[i-1]) pi=pie*2 end
    The result is stored in variable pi. Note that to calculate pi again, you must reset variable "pie" to 1.

    EDIT: It seems I've pasted the wrong code. When I tested one, it worked, but I think I pasted this one differently. It doesn't work. Please ignore...

    Edited 3 times by QuanTech. Last: 5th Mar 2017