(x, eps_sign, prec, rnd)
For nonzero x, calculate x + eps with directed rounding, where
    eps < prec relatively and eps has the given sign (0 for
    positive, 1 for negative).

    With rounding to nearest, this is taken to simply normalize
    x to the given precision.
For nonzero x, calculate x + eps with directed rounding, where
    eps < prec relatively and eps has the given sign (0 for
    positive, 1 for negative).
For nonzero x calculate x + eps with directed rounding where eps < prec relatively and eps has the given sign ( 0 for positive 1 for negative ) .
def mpf_perturb(x, eps_sign, prec, rnd):
    """
    For nonzero x, calculate x + eps with directed rounding, where
    eps < prec relatively and eps has the given sign (0 for
    positive, 1 for negative).

    With rounding to nearest, this is taken to simply normalize
    x to the given precision.
    """
    if rnd == round_nearest:
        return mpf_pos(x, prec, rnd)
    sign, man, exp, bc = x
    eps = (eps_sign, MPZ_ONE, exp+bc-prec-1, 1)
    if sign:
        away = (rnd in (round_down, round_ceiling)) ^ eps_sign
    else:
        away = (rnd in (round_up, round_ceiling)) ^ eps_sign
    if away:
        return mpf_add(x, eps, prec, rnd)
    else:
        return mpf_pos(x, prec, rnd)
def mpf_perturb ( x , eps_sign , prec , rnd ) : if rnd == round_nearest : return mpf_pos ( x , prec , rnd ) sign , man , exp , bc = x eps = ( eps_sign , MPZ_ONE , exp + bc - prec - 1 , 1 ) if sign : away = ( rnd in ( round_down , round_ceiling ) ) ^ eps_sign else : away = ( rnd in ( round_up , round_ceiling ) ) ^ eps_sign if away : return mpf_add ( x , eps , prec , rnd ) else : return mpf_pos ( x , prec , rnd )