continuedFractionEval
continuedFractionEval(
fraction,options?):ConvergenceResult<number>
Defined in: packages/math-analysis/src/continued-fraction-eval.ts:79
Evaluates a continued fraction — an expression of the form b₀ + a₁/(b₁ + a₂/(b₂ + ⋯)) that in principle never ends.
Many functions have a continued fraction that converges far faster than their
power series, especially away from the origin, which is why the incomplete
gamma and beta in this package are built on one. This evaluates such a
fraction without having to decide up front how deep to go: the running value
is multiplied by a factor tending to 1, and the iteration stops when that
factor is within tolerance of 1.
It reports rather than throws. A fraction that exhausts maxIterations still
returns its best estimate, with converged: false — check it before trusting
the value.
O(maxIterations) calls to each of ContinuedFraction.numerator and
ContinuedFraction.denominator, and the same count of divisions. O(1)
memory: the coefficients are functions of the index, so an unbounded fraction
needs no array.
Parameters
Section titled “Parameters”fraction
Section titled “fraction”The partial numerators and denominators.
options?
Section titled “options?”Termination criteria. tolerance is compared against the
distance from 1 of the multiplicative update, so it is relative; it
defaults to Number.EPSILON and maxIterations to 300.
Returns
Section titled “Returns”ConvergenceResult<number>
The fraction’s value, the iteration count, and whether the tolerance was met.
Example
Section titled “Example” // 1 + 1/(1 + 1/(1 + ⋯)) is the golden ratio. const phi = continuedFractionEval({ numerator: () => 1, denominator: () => 1, }); phi.value; // 1.618033988749895 phi.iterations; // 38 phi.converged; // true ```;
## See
[Continued fractions](https://anthochamp.pages.grenadine.io/node-essentials/topics/math/calculus/series/)