'Rescales so that the exponent is exp.
exp = exp to scale to (an integer)
rounding = rounding version
watchexp: if set (default) an error is returned if exp is greater
than Emax or less than Etiny.'

def _rescale(self, exp, rounding=None, context=None, watchexp=1):

    if (context is None):
        context = getcontext()
    if self._is_special:
        if self._isinfinity():
            return context._raise_error(InvalidOperation, 'rescale    with    an    INF')
        ans = self._check_nans(context=context)
        if ans:
            return ans
    if (watchexp and ((context.Emax < exp) or (context.Etiny() > exp))):
        return context._raise_error(InvalidOperation, 'rescale(a,    INF)')
    if (not self):
        ans = Decimal(self)
        ans._int = (0,)
        ans._exp = exp
        return ans
    diff = (self._exp - exp)
    digits = (len(self._int) + diff)
    if (watchexp and (digits > context.prec)):
        return context._raise_error(InvalidOperation, 'Rescale    >    prec')
    tmp = Decimal(self)
    tmp._int = ((0,) + tmp._int)
    digits += 1
    if (digits < 0):
        tmp._exp = ((- digits) + tmp._exp)
        tmp._int = (0, 1)
        digits = 1
    tmp = tmp._round(digits, rounding, context=context)
    if ((tmp._int[0] == 0) and (len(tmp._int) > 1)):
        tmp._int = tmp._int[1:]
    tmp._exp = exp
    tmp_adjusted = tmp.adjusted()
    if (tmp and (tmp_adjusted < context.Emin)):
        context._raise_error(Subnormal)
    elif (tmp and (tmp_adjusted > context.Emax)):
        return context._raise_error(InvalidOperation, 'rescale(a,    INF)')
    return tmp
