def bisect(rlo, rhi, acc, tol, fun, **kwargs):
    """ 
        Performs a bisection search.

        **Input**:
            - fun -- a function such that fun(r)==True iff x_0>r, where x_0 is the value to be found.
    """
    while rhi - rlo > acc:
        r = 0.5 * (rhi + rlo)
        if kwargs:
            isvalid = fun(r, tol, **kwargs)
        else:
            isvalid = fun(r, tol)
        if isvalid:
            rlo = r
        else:
            rhi = r
    return rlo
