[issue26324] sum() incorrect on negative zeros

Mark Dickinson report at bugs.python.org
Wed Feb 10 01:50:31 EST 2016


Mark Dickinson added the comment:

For what it's worth, NumPy has exactly the same behaviour:

>>> np.array([-0.0, -0.0]).sum()
0.0

... which is a bit surprising, given that this is a much easier problem to fix when you know the type of everything in the array in advance.

The Decimal type has similar issues here, resulting from that implicit addition of 0:

>>> from decimal import Decimal, getcontext
>>> getcontext().prec = 5
>>> x = Decimal('3.1415926535893')
>>> sum([x])
Decimal('3.1416')

Fixing this would involve major changes to the way that sum works, or some horrible DWIM special-casing; I think it's best left as it is.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26324>
_______________________________________


More information about the Python-bugs-list mailing list