'Remainder nearest to 0-  abs(remainder-near) <= other/2'

def remainder_near(self, other, context=None):

    other = _convert_other(other)
    if (self._is_special or other._is_special):
        ans = self._check_nans(other, context)
        if ans:
            return ans
    if (self and (not other)):
        return context._raise_error(InvalidOperation, 'x    %    0')
    if (context is None):
        context = getcontext()
    context = context._shallow_copy()
    flags = context._ignore_flags(Rounded, Inexact)
    (side, r) = self.__divmod__(other, context=context)
    if r._isnan():
        context._regard_flags(*flags)
        return r
    context = context._shallow_copy()
    rounding = context._set_rounding_decision(NEVER_ROUND)
    if other._sign:
        comparison = other.__div__(Decimal((-2)), context=context)
    else:
        comparison = other.__div__(Decimal(2), context=context)
    context._set_rounding_decision(rounding)
    context._regard_flags(*flags)
    (s1, s2) = (r._sign, comparison._sign)
    (r._sign, comparison._sign) = (0, 0)
    if (r < comparison):
        (r._sign, comparison._sign) = (s1, s2)
        self.__divmod__(other, context=context)
        return r._fix(context)
    (r._sign, comparison._sign) = (s1, s2)
    rounding = context._set_rounding_decision(NEVER_ROUND)
    (side, r) = self.__divmod__(other, context=context)
    context._set_rounding_decision(rounding)
    if r._isnan():
        return r
    decrease = (not side._iseven())
    rounding = context._set_rounding_decision(NEVER_ROUND)
    side = side.__abs__(context=context)
    context._set_rounding_decision(rounding)
    (s1, s2) = (r._sign, comparison._sign)
    (r._sign, comparison._sign) = (0, 0)
    if ((r > comparison) or (decrease and (r == comparison))):
        (r._sign, comparison._sign) = (s1, s2)
        context.prec += 1
        if (len(side.__add__(Decimal(1), context=context)._int) >= context.prec):
            context.prec -= 1
            return context._raise_error(DivisionImpossible)[1]
        context.prec -= 1
        if (self._sign == other._sign):
            r = r.__sub__(other, context=context)
        else:
            r = r.__add__(other, context=context)
    else:
        (r._sign, comparison._sign) = (s1, s2)
    return r._fix(context)
