Digits of PI

Just starting out? Need help? Post your questions and find answers here.
User avatar
matalog
Enthusiast
Enthusiast
Posts: 305
Joined: Tue Sep 05, 2017 10:07 am

Digits of PI

Post by matalog »

Who has used PureBasic to generate many digits of PI? Are there any advantages or disadvantages of using PureBasic to do this over other languages?

I assume at the level of 20 or more digits, that the numbers are stored in strings or memory locations?
firace
Addict
Addict
Posts: 947
Joined: Wed Nov 09, 2011 8:58 am

Re: Digits of PI

Post by firace »

Nice example found on Rosetta:

Code: Select all

#SCALE = 10000
#ARRINT=  2000

Procedure Pi(Digits)
  Protected First=#True, Text$
  Protected Carry, i, j, sum
  Dim Arr(Digits)
  For i=0 To Digits
    Arr(i)=#ARRINT
  Next
  i=Digits
  While i>0
    sum=0
    j=i
    While j>0
      sum*j+#SCALE*arr(j)
      Arr(j)=sum%(j*2-1)
      sum/(j*2-1)
      j-1
    Wend
    Text$ = RSet(Str(Carry+sum/#SCALE),4,"0")
    If First
      Text$ = ReplaceString(Text$,"3","3.")
      First = #False
    EndIf
    Print(Text$)
    Carry=sum%#SCALE
    i-14
  Wend
EndProcedure

OpenConsole()
Pi(200000)
Input()

TassyJim
Enthusiast
Enthusiast
Posts: 189
Joined: Sun Jun 16, 2013 6:27 am
Location: Tasmania (Australia)

Re: Digits of PI

Post by TassyJim »

User avatar
matalog
Enthusiast
Enthusiast
Posts: 305
Joined: Tue Sep 05, 2017 10:07 am

Re: Digits of PI

Post by matalog »

Thanks for those, guys. Brilliant.
Post Reply