def chisqprob(chisq, df):
    """
    Returns the (1-tailed) probability value associated with the provided
    chi-square value and df.  
    
    Originally adapted from Gary Perlman code by Gary Strangman.
    
    Usage:   chisqprob(chisq,df)
    """
    BIG = 20.0

    def ex(x):
        BIG = 20.0
        if x < -BIG:
            return 0.0
        else:
            return exp(x)

    if chisq <= 0 or df < 1:
        return 1.0

    a = 0.5 * chisq
    if df % 2 == 0:
        even = 1
    else:
        even = 0
    if df > 1:
        y = ex(-a)
    if even:
        s = y
    else:
        s = 2.0 * zprob(-sqrt(chisq))
    if (df > 2):
        chisq = 0.5 * (df - 1.0)
        if even:
            z = 1.0
        else:
            z = 0.5
        if a > BIG:
            if even:
                e = 0.0
            else:
                e = log(sqrt(pi))
            c = log(a)
            while (z <= chisq):
                e = log(z) + e
                s = s + ex(c * z - a - e)
                z = z + 1.0
            return s
        else:
            if even:
                e = 1.0
            else:
                e = 1.0 / sqrt(pi) / sqrt(a)
            c = 0.0
            while (z <= chisq):
                e = e * (float(z) / a)
                c = c + e
                z = z + 1.0
            return (c * y + s)
    else:
        return s
dataset/ETHPy150Open mixcloud/django-experiments/experiments/stats.py/chisqprob/swapped operands of `/`