repl.txt (2216B)
1 2 {{alias}}( generator[, options] ) 3 Evaluates the continued fraction approximation for the supplied series 4 generator using the modified Lentz algorithm. 5 6 `generator` can be either a function which returns an array with two 7 elements, the `a` and `b` terms of the fraction, or an ES6 Generator object. 8 9 By default, the function computes 10 11 a1 12 --------------- 13 b1 + a2 14 ---------- 15 b2 + a3 16 ----- 17 b3 + ... 18 19 To evaluate 20 21 b0 + a1 22 --------------- 23 b1 + a2 24 ---------- 25 b2 + a3 26 ----- 27 b3 + ... 28 29 set the `keep` option to `true`. 30 31 Parameters 32 ---------- 33 generator: Function 34 Function returning terms of continued fraction expansion. 35 36 options: Object (optional) 37 Options. 38 39 options.maxIter: integer (optional) 40 Maximum number of iterations. Default: `1000000`. 41 42 options.tolerance: number (optional) 43 Further terms are only added as long as the next term is greater than 44 current term times the tolerance. Default: `2.22e-16`. 45 46 options.keep: boolean (optional) 47 Boolean indicating whether to keep the `b0` term in the continued 48 fraction. Default: `false`. 49 50 Returns 51 ------- 52 out: number 53 Value of continued fraction. 54 55 Examples 56 -------- 57 // Continued fraction for (e-1)^(-1): 58 > function closure() { 59 ... var i = 0; 60 ... return function() { 61 ... i += 1; 62 ... return [ i, i ]; 63 ... }; 64 ... }; 65 > var gen = closure(); 66 > var out = {{alias}}( gen ) 67 ~0.582 68 69 // Using an ES6 generator: 70 > function* generator() { 71 ... var i = 0; 72 ... while ( true ) { 73 ... i += 1; 74 ... yield [ i, i ]; 75 ... } 76 ... }; 77 > gen = generator(); 78 > out = {{alias}}( gen ) 79 ~0.582 80 81 // Set options: 82 > out = {{alias}}( generator(), { 'keep': true } ) 83 ~1.718 84 > out = {{alias}}( generator(), { 'maxIter': 10 } ) 85 ~0.582 86 > out = {{alias}}( generator(), { 'tolerance': 1e-1 } ) 87 ~0.579 88 89 See Also 90 -------- 91