diff options
author | Mark Dickinson <mdickinson@enthought.com> | 2011-03-12 11:17:26 +0000 |
---|---|---|
committer | Mark Dickinson <mdickinson@enthought.com> | 2011-03-12 11:17:26 +0000 |
commit | a7f0dffb8d690ea00bbe99098be5a601835ec267 (patch) | |
tree | 81abe3ef23aaa34e7571c3ba019aba510f20825e /Lib/decimal.py | |
parent | e858bca35648bfdd817c51bbea53cb968b626a8d (diff) | |
parent | 37a79fb75b8f6d1833caee16c777d07b9338938f (diff) | |
download | cpython-git-a7f0dffb8d690ea00bbe99098be5a601835ec267.tar.gz |
Merge #11131
Diffstat (limited to 'Lib/decimal.py')
-rw-r--r-- | Lib/decimal.py | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/Lib/decimal.py b/Lib/decimal.py index c387de60b6..ea8f1d6aba 100644 --- a/Lib/decimal.py +++ b/Lib/decimal.py @@ -1045,14 +1045,16 @@ class Decimal(object): if ans: return ans - if not self: - # -Decimal('0') is Decimal('0'), not Decimal('-0') + if context is None: + context = getcontext() + + if not self and context.rounding != ROUND_FLOOR: + # -Decimal('0') is Decimal('0'), not Decimal('-0'), except + # in ROUND_FLOOR rounding mode. ans = self.copy_abs() else: ans = self.copy_negate() - if context is None: - context = getcontext() return ans._fix(context) def __pos__(self, context=None): @@ -1065,14 +1067,15 @@ class Decimal(object): if ans: return ans - if not self: - # + (-0) = 0 + if context is None: + context = getcontext() + + if not self and context.rounding != ROUND_FLOOR: + # + (-0) = 0, except in ROUND_FLOOR rounding mode. ans = self.copy_abs() else: ans = Decimal(self) - if context is None: - context = getcontext() return ans._fix(context) def __abs__(self, round=True, context=None): |