Continued fraction: Difference between revisions
→{{header|F_Sharp|F#}}
Line 978:
===The Functions===
<lang fsharp>
// I provide
// cf2S general purpose continued fraction to sequence of float approximations
// cN2S Normal continued fractions (a-series always 1)
// cfSqRt uses cf2S to calculate sqrt of float
// π takes a sequence of b values returning the next until the list is exhausted after which it injects infinity
// Nigel Galloway: December 19th., 2018
let cf2S α β=let n0,g1,n1,g2=β(),α(),β(),β()
Line 987 ⟶ 988:
let cN2S = cf2S (fun()->1M)
let cfSqRt n=(cf2S (fun()->n-1M) (let mutable n=false in fun()->if n then 2M else (n<-true; 1M)))
</lang>
===The Tasks===
Line 1,058 ⟶ 1,060:
</pre>
<lang fsharp>
let
cN2S
▲ (fun ()->match π with h::t->π<-t; h |_->9999999999999999999999999999M)
▲cN2S (π()) |> Seq.take 10 |> Seq.pairwise |> Seq.iter(fun(n,g)->printfn "%1.14f < π < %1.14f" (min n g) (max n g))
</lang>
{{out}}
|