1918
1918
# case where xc == 1: result is 10**(xe*y), with xe*y
1919
1919
# required to be an integer
1922
exponent = xe*yc*10**ye
1924
exponent, remainder = divmod(xe*yc, 10**-ye)
1922
# result is now 10**(xe * 10**ye); xe * 10**ye must be integral
1928
exponent = xe * 10**ye
1927
1929
if y.sign == 1:
1928
1930
exponent = -exponent
1929
1931
# if other is a nonnegative integer, use ideal exponent
2196
2198
# try for an exact result with precision +1
2197
2199
if ans is None:
2198
2200
ans = self._power_exact(other, context.prec + 1)
2199
if ans is not None and result_sign == 1:
2200
ans = _dec_from_triple(1, ans._int, ans._exp)
2202
if result_sign == 1:
2203
ans = _dec_from_triple(1, ans._int, ans._exp)
2203
2206
# usual case: inexact result, x**y computed directly as exp(y*log(x))
2204
2207
if ans is None:
3687
3690
Emin=None, Emax=None,
3688
3691
capitals=None, _clamp=0,
3689
3692
_ignored_flags=None):
3693
# Set defaults; for everything except flags and _ignored_flags,
3694
# inherit from DefaultContext.
3700
self.prec = prec if prec is not None else dc.prec
3701
self.rounding = rounding if rounding is not None else dc.rounding
3702
self.Emin = Emin if Emin is not None else dc.Emin
3703
self.Emax = Emax if Emax is not None else dc.Emax
3704
self.capitals = capitals if capitals is not None else dc.capitals
3705
self._clamp = _clamp if _clamp is not None else dc._clamp
3707
if _ignored_flags is None:
3708
self._ignored_flags = []
3710
self._ignored_flags = _ignored_flags
3713
self.traps = dc.traps.copy()
3714
elif not isinstance(traps, dict):
3715
self.traps = dict((s, int(s in traps)) for s in _signals)
3690
3719
if flags is None:
3692
if _ignored_flags is None:
3694
if not isinstance(flags, dict):
3695
flags = dict([(s, int(s in flags)) for s in _signals])
3697
if traps is not None and not isinstance(traps, dict):
3698
traps = dict([(s, int(s in traps)) for s in _signals])
3700
for name, val in locals().items():
3702
setattr(self, name, _copy.copy(getattr(DefaultContext, name)))
3704
setattr(self, name, val)
3720
self.flags = dict.fromkeys(_signals, 0)
3721
elif not isinstance(flags, dict):
3722
self.flags = dict((s, int(s in flags)) for s in _signals)
3707
3726
def __repr__(self):
3708
3727
"""Show the current context."""