def continuants(contfrac):
    """Continuants of a continued fraction.

    contfrac must yield an infinite sequence (n0, d0), (n1, d1), (n2,
    d2), ..., representing the continued fraction

                n0
        ------------------
                  n1
        d0 + -------------
                     n2
             d1 + --------
                  d2 + ...

    The kth continuant is the numerator and denominator of the
    continued fraction truncated at the kth term, i.e. with zero
    instead of the rest in the ellipsis.

    If the numerator or denominator grows large in magnitude, both are
    multiplied by the machine epsilon, leaving their quotient
    unchanged.
    """
    p0 = 1.
    q0 = 0.
    p = 0.
    q = 1.
    for n, d in contfrac:
        p0, q0, p, q = p, q, d*p + n*p0, d*q + n*q0
        if p <= EPSINV or q >= EPSINV:
            p0 *= EPSILON
            q0 *= EPSILON
            p *= EPSILON
            q *= EPSILON
        assert q != 0
        yield p, q
dataset/ETHPy150Open probcomp/bayeslite/src/math_util.py/continuants/operator `>=` -> `<=`