From http://www.pi314.net/eng/goutte.php
We use this function (it is 3 times faster than the one we use there https://georgekarras.blogspot.com/2018/07/18-93-pi.html
The program has an object to redirect output to screen and to a file together. My laptop has a Celeron 11th generation and M2000 run in one thread.
This is the Output.txt file:
Compute 4 Pi digits
Pi=3.1415
Compute 28 Pi digits
Pi=3.14159 26535 89793 23846 26433 832
Decimal type pi = 3.1415926535897932384626433832
Compute 150 Pi digits
Pi=3.14159 26535 89793 23846 26433 83279 50288 41971 69399 37510
58209 74944 59230 78164 06286 20899 86280 34825 34211 70679
82148 08651 32823 06647 09384 46095 50582 23172 53594 08128
Time to compute 150 digits:9.96sec
Compute 500 Pi digits
Pi=3.14159 26535 89793 23846 26433 83279 50288 41971 69399 37510
58209 74944 59230 78164 06286 20899 86280 34825 34211 70679
82148 08651 32823 06647 09384 46095 50582 23172 53594 08128
48111 74502 84102 70193 85211 05559 64462 29489 54930 38196
44288 10975 66593 34461 28475 64823 37867 83165 27120 19091
45648 56692 34603 48610 45432 66482 13393 60726 02491 41273
72458 70066 06315 58817 48815 20920 96282 92540 91715 36436
78925 90360 01133 05305 48820 46652 13841 46951 94151 16094
33057 27036 57595 91953 09218 61173 81932 61179 31051 18548
07446 23799 62749 56735 18857 52724 89122 79381 83011 94912
Time to compute 500 digits:106.14sec
Form 80, 32
Module Checkpi {
Locale 1033
' locale$(14) is dot "." for Locale 1033
Module FindPi (D as integer, f as Group){
Long k, q, n
d++
n=Int(d/0.9)
PlusOne=Lambda a=0, b=-1 -> {=a*b:a++:b+=2} ' first would change to zero
PlusTwo=Lambda a=1, b=2 -> {=a*b*3:a+=3:b+=3}
Init=Lambda a=3 -> {=a:a+=5}
Dim A(n) as Decimal<<PlusOne(), B(n) as Decimal<<PlusTwo(), mul10() as Decimal
Dim Ten(n) as Decimal, CarrierOver(n) as Decimal, Sum(n) as Decimal, Remainder(n) as Decimal<<Init()
OutPutDigits=D
Predigits=Stack
F.Lmargin 8
F.OutStr "Pi="
While D
CarrierOver=0
For k=n-1 to 1
Ten(k)=Remainder(k)*10
CarrierOver(k)=CarrierOver
Sum(k)=Ten(k)+CarrierOver(k)
q=Sum(k) div B(k)
Remainder(k)=Sum(k)-B(k)*q
CarrierOver=A(k)*q
Next
Ten(0)=Remainder(0)*10
CarrierOver(0)=CarrierOver
Sum(0)=Ten(0)+CarrierOver(0)
q=Sum(0) div 10
Remainder(0)=Sum(0)-10*q
if q<>9 and q<>10 then
Stack Predigits {
While not empty
F.out
if D>0 then D--
If D=0 then flush ' empty stack
End While
Push q
}
Else.if q=9 Then
Stack Predigits { Data q }
Else
Stack Predigits {
While not empty
F.Out (Number+1) mod 10
if D>0 then D--
If D=0 then flush ' empty stack
End While
Push 0
}
End if
End While
}
Class HandleOutput {
boolean fl=true
long f, Chars, p, w=80
Module LMargin {
.p<=number
if .p<pos then print : ? #.f
}
Module OutStr (s as string){
if .p>0 and pos<.p then a=string$(" ", pos-.p): ?#.f, a;: ? a;
? #.f,s;:? s;
}
Module OutTitle (a as string){
if pos>0 then .p<=0: .Cr
if len(a)>78 then a=" "+left$(a, 78) else a=string$(" ", (80-len(a)) div 2)+a
? #.f,a:? a
}
Module Cr {
string a=string$(" ", .p)
? #.f: ?#.f,a;
? : ? a;
}
Module Out (x) {
? #.f, x;:? x;
.Chars++
If .fl then
? #.f, Locale$(14); : ? Locale$(14); : .fl<=false : .Chars<=0
.p<=pos: exit
Else.If .Chars=50 then
.Cr : .Chars<=0:refresh
Else.if .Chars mod 5%=0 then
? #.f, " ";:? " ";:refresh
End if
}
class:
module HandleOutput (.f) {
}
}
set fast !
open "output.txt" for wide output as #file
F=HandleOutput(file)
F.OutTitle "Compute 4 Pi digits"
FindPi 4, F
F.Lmargin 0
F.Cr
F.OutTitle "Compute 28 Pi digits"
FindPi 28, F
F.Lmargin 0
F.OutTitle "Decimal type pi = "+pi
F.Cr
L=(150, 500)
M=each(L)
While M
n=Array(M)
F.OutTitle "Compute "+(n)+" Pi digits"
profiler
FindPi n, F
t=timecount
string r=(Round(t/1000,2))+"sec"
F.Lmargin 0
F.OutTitle "Time to compute "+n+" digits:"+r
F.Cr
End While
close #file
win "notepad", dir$+"output.txt"
Set fast
}
Flush
CheckPi
Δεν υπάρχουν σχόλια:
Δημοσίευση σχολίου
You can feel free to write any suggestion, or idea on the subject.