[B4X] Today - Pi Day

Star-Dust

Expert
Licensed User
Some B4X methods to calculate it

1) Formulas di Leibniz
B4X:
Dim N As Int = 1000 ' The greater the value, the greater the precision
Dim PiGreek As Double = 1
 
For i=1 To N
    PiGreek=PiGreek+Power(-1,i)/(2*i+1)
Next
 
Log(4*PiGreek)
2) Formulas di Machin
B4X:
Dim PiGreek As Double = 4*ATan(1/5)-ATan(1/239)

Log(4*PiGreek)
3) Formulas di Wallis
B4X:
Dim N As Int = 1000
Dim PiGreek As Double = 1

For i=1 To N
    PiGreek=PiGreek*((i*2)/((i-1)*2+1))*((i*2)/((i-1)*2+3))
Next

Log(2*PiGreek)
 
Last edited:

Erel

Administrator
Staff member
Licensed User
B4X:
Sub AppStart (Args() As String)
   Dim CountIn As Int
   Dim Total As Int = 100000000
   For i = 0 To Total - 1
       Dim r1 As Int = Rnd(0, 0x7fffffff)
       Dim r2 As Int = Rnd(0, 0x7fffffff)
       Dim x As Double = r1 / 0x7fffffff
       Dim y As Double = r2 / 0x7fffffff
       Dim distance2 As Double = Power(x - 0.5, 2) + Power(y - 0.5, 2)
       If distance2 <= 0.25 Then CountIn = CountIn + 1
   Next
   Log(CountIn / Total / 0.25)
End Sub
 

Star-Dust

Expert
Licensed User
Formulas di Basel
B4X:
Dim N As Int = 1000
Dim PiGreek As Double = 0
   
For i=1 To N
        PiGreek=PiGreek+1/Power(i,2)
Next
   
Log(Sqrt(PiGreek*6))
 

MarkusR

Well-Known Member
Licensed User
simplified ~ 22/7
 

MarkusR

Well-Known Member
Licensed User
Last edited:

Star-Dust

Expert
Licensed User
I'll talk about it with Euler :)
 
Top