import mpmath


def cdf(x, dfn, dfd):
    """
    Cumulative distribution function of the F distribution.

    `dfn` and `dfd` are the numerator and denominator degrees of freedom, resp.
    """
    if x <= 0:
        return mpmath.mp.zero
    with mpmath.mp.extradps(5):
        x = mpmath.mp.mpf(x)
        dfn = mpmath.mp.mpf(dfn)
        dfd = mpmath.mp.mpf(dfd)
        dfnx = dfn * x
        return mpmath.betainc(dfn/2, dfd/2, x2=dfnx/(dfnx + dfd),
                              regularized=True)