def contfractbeta(
    a: float, b: float, x: float, ITMAX: int = 5000, EPS: float = 1.0e-7
) -> float:
    """Continued fraction form of the incomplete Beta function.

    Code translated from: Numerical Recipes in C.

    Example kindly taken from blog:
    https://malishoaib.wordpress.com/2014/04/15/the-beautiful-beta-functions-in-raw-python/

    :param float a: a
    :param float b: b
    :param float x: x
    :param int ITMAX: max number of iterations, default is 5000.
    :param float EPS: epsilon precision parameter, default is 1e-7.
    :returns: continued fraction form
    :rtype: float
    """
    az = 1.0
    bm = 1.0
    am = 1.0
    qab = a + b
    qap = a + 1.0
    qam = a - 1.0
    bz = 1.0 - qab * x / qap

    for i in range(ITMAX + 1):
        em = float(i + 1)
        tem = em + em
        d = em * (b - em) * x / ((qam + tem) * (a + tem))
        ap = az + d * am
        bp = bz + d * bm
        d = -(a + em) * (qab + em) * x / ((qap + tem) * (a + tem))
        app = ap + d * az
        bpp = bp + d * bz
        aold = az
        am = ap / bpp
        bm = bp / bpp
        az = app / bpp
        bz = 1.0
        if abs(az - aold) < EPS * abs(az):
            return az

    raise ValueError(
        "a={0:f} or b={1:f} too large, or ITMAX={2:d} too small to compute incomplete beta function.".format(
            a, b, ITMAX
        )
    )