summaryrefslogtreecommitdiff
path: root/Lib/decimal.py
diff options
context:
space:
mode:
authorMark Dickinson <mdickinson@enthought.com>2011-03-12 11:05:32 +0000
committerMark Dickinson <mdickinson@enthought.com>2011-03-12 11:05:32 +0000
commit2c8c62e64d3c8438f13774d275755ad77a516ad6 (patch)
tree64326985d9d97be86572fb22e54331ddf7d93edb /Lib/decimal.py
parentd4f016fb514d089d931b2dbca0bfa4e02cbab878 (diff)
downloadcpython-git-2c8c62e64d3c8438f13774d275755ad77a516ad6.tar.gz
Issue 11131: Fix sign of zero result on plus and minus operations in ROUND_FLOOR rounding mode.
Diffstat (limited to 'Lib/decimal.py')
-rw-r--r--Lib/decimal.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/Lib/decimal.py b/Lib/decimal.py
index feba3d7edd..102fc8e6e5 100644
--- a/Lib/decimal.py
+++ b/Lib/decimal.py
@@ -1068,14 +1068,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):
@@ -1088,14 +1090,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):