import mpmath


def var(xi, mu=0, sigma=1):
    """
    Variance of the generalized extreme value distribution.
    """
    xi = mpmath.mpf(xi)
    mu = mpmath.mpf(mu)
    sigma = mpmath.mpf(sigma)

    if xi == 0:
        return sigma**2 * mpmath.pi**2 / 6
    elif 2*xi < 1:
        g1 = mpmath.gamma(mpmath.mp.one - xi)
        g2 = mpmath.gamma(mpmath.mp.one - 2*xi)
        return sigma**2 * (g2 - g1**2) / xi**2
    else:
        return mpmath.inf