mirror of
https://github.com/python/cpython.git
synced 2025-10-09 08:31:26 +00:00
Issue 11131: Fix sign of zero result on decimal.Decimal plus and minus operations in ROUND_FLOOR rounding mode.
This commit is contained in:
parent
abd4a05561
commit
37a79fb75b
3 changed files with 84 additions and 8 deletions
|
@ -1040,14 +1040,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):
|
||||
|
@ -1060,14 +1062,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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue