~ubuntu-branches/ubuntu/oneiric/python2.6/oneiric

« back to all changes in this revision

Viewing changes to Lib/decimal.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-08-07 20:03:08 UTC
  • mfrom: (10.1.27 sid)
  • Revision ID: james.westby@ubuntu.com-20100807200308-bwsyymoc4donr9a9
Tags: 2.6.6~rc1-1ubuntu1
* Merge with Debian; remaining changes:
  - Regenerate the control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1918
1918
        # case where xc == 1: result is 10**(xe*y), with xe*y
1919
1919
        # required to be an integer
1920
1920
        if xc == 1:
1921
 
            if ye >= 0:
1922
 
                exponent = xe*yc*10**ye
1923
 
            else:
1924
 
                exponent, remainder = divmod(xe*yc, 10**-ye)
1925
 
                if remainder:
1926
 
                    return None
 
1921
            xe *= yc
 
1922
            # result is now 10**(xe * 10**ye);  xe * 10**ye must be integral
 
1923
            while xe % 10 == 0:
 
1924
                xe //= 10
 
1925
                ye += 1
 
1926
            if ye < 0:
 
1927
                return None
 
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)
2201
 
            exact = True
 
2201
            if ans is not None:
 
2202
                if result_sign == 1:
 
2203
                    ans = _dec_from_triple(1, ans._int, ans._exp)
 
2204
                exact = True
2202
2205
 
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.
 
3695
        try:
 
3696
            dc = DefaultContext
 
3697
        except NameError:
 
3698
            pass
 
3699
 
 
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
 
3706
 
 
3707
        if _ignored_flags is None:
 
3708
            self._ignored_flags = []
 
3709
        else:
 
3710
            self._ignored_flags = _ignored_flags
 
3711
 
 
3712
        if traps is None:
 
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)
 
3716
        else:
 
3717
            self.traps = traps
 
3718
 
3690
3719
        if flags is None:
3691
 
            flags = []
3692
 
        if _ignored_flags is None:
3693
 
            _ignored_flags = []
3694
 
        if not isinstance(flags, dict):
3695
 
            flags = dict([(s, int(s in flags)) for s in _signals])
3696
 
            del s
3697
 
        if traps is not None and not isinstance(traps, dict):
3698
 
            traps = dict([(s, int(s in traps)) for s in _signals])
3699
 
            del s
3700
 
        for name, val in locals().items():
3701
 
            if val is None:
3702
 
                setattr(self, name, _copy.copy(getattr(DefaultContext, name)))
3703
 
            else:
3704
 
                setattr(self, name, val)
3705
 
        del self.self
 
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)
 
3723
        else:
 
3724
            self.flags = flags
3706
3725
 
3707
3726
    def __repr__(self):
3708
3727
        """Show the current context."""