def _eval_left_right(f, x, dx=1e-06):
    """Evaluate a function by taking the average of the values just above and
    below the x value. Used to avoid singularity/Inf/NaN.

    Args
    ----
    f : function
        Function handle.
    x : float
        Argument of function.
    dx : float, optional
        Step size.

    Returns
    ------
    float : Function value.

    """
    return (f(x + dx) + f(x - dx)) / 2
