Jump to content

Pi: Difference between revisions

935 bytes added ,  26 days ago
m
Add SML
m (→‎{{header|Wren}}: Minor tidy)
m (Add SML)
Line 6,081:
2000568127145263560827785771342757789609
...</pre>
 
=={{header|Standard ML}}==
 
{{works with|Poly/ML}}
{{works with|SML/NJ}}
{{works with|MLton}}
 
<syntaxhighlight lang="sml">(* https://www.cs.ox.ac.uk/people/jeremy.gibbons/publications/spigot.pdf *)
 
fun gibbons _ _ _ _ _ _ 0 = ()
| gibbons q r t k n l count =
let
val (q',r',t',k',n',l',count') =
if 4*q+r-t < n*t
then (10*q,10*(r-n*t),t,k,(10*(3*q+r)) div t-10*n,l,count-1) before print (IntInf.toString n)
else (q*k,(2*q+r)*l,t*l,k+1,(q*(7*k+2)+r*l) div (t*l),l+2,count)
in
gibbons q' r' t' k' n' l' count'
end
 
fun doGibbons n = gibbons 1 0 1 1 3 3 n
 
fun timeGibbons n =
let
val timer1 = Timer.startCPUTimer ()
val () = doGibbons n
val {usr=usr, sys=sys} = Timer.checkCPUTimer timer1
in
print "\n----------------------\n";
print ("usr: " ^ Time.toString usr ^ "\n");
print ("sys: " ^ Time.toString sys ^ "\n")
end
 
fun main () = timeGibbons 5000
</syntaxhighlight>
 
=={{header|Tailspin}}==
23

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.