Page 1 of 1
Digits of PI
Posted: Sat Aug 10, 2024 10:42 pm
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?
Re: Digits of PI
Posted: Sun Aug 11, 2024 8:32 am
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()
Re: Digits of PI
Posted: Sun Aug 11, 2024 8:55 am
by TassyJim
Re: Digits of PI
Posted: Tue Aug 13, 2024 9:03 pm
by matalog
Thanks for those, guys. Brilliant.