[issue26324] sum() incorrect on negative zeros

2016-02-10 Thread Jim Jewett

Jim Jewett added the comment:

Even if Ethan's argument about an explicit start value were not convincing, 
Mark + Raymond would count as authoritative for floats.

Anyone can reopen if needed; I just don't want the issue to languish forever if 
there is at least grudging agreement.

--
nosy: +Jim.Jewett
resolution:  -> not a bug
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26324] sum() incorrect on negative zeros

2016-02-09 Thread Antoine Pitrou

New submission from Antoine Pitrou:

>>> sum([-0.0,-0.0])
0.0

--
components: Interpreter Core
messages: 259961
nosy: eric.smith, lemburg, mark.dickinson, pitrou, stutzbach
priority: low
severity: normal
status: open
title: sum() incorrect on negative zeros
type: behavior
versions: Python 2.7, Python 3.5, Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26324] sum() incorrect on negative zeros

2016-02-09 Thread Antoine Pitrou

Antoine Pitrou added the comment:

"Expect" is a strong word here ;-) The problem is the start value is implicit 
and is supposed to be a "good default". Of course, solving this consistently 
may not be trivial.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26324] sum() incorrect on negative zeros

2016-02-09 Thread Emanuel Barry

Emanuel Barry added the comment:

This is consistent with the advertised equivalence of sum():

>>> -0.0 + -0.0 + 0
0.0

This works as you'd expect:

>>> sum([-0.0, -0.0], -0.0)
-0.0

It has a start value of 0, and I don't think we should special-case this.

--
nosy: +ebarry

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26324] sum() incorrect on negative zeros

2016-02-09 Thread Emanuel Barry

Emanuel Barry added the comment:

"Not trivial" might be an understatement. You need the start value to begin 
summing the items, but you may face with a non-repeatable generator with 
side-effects. Sure, you could special-case some builtins, but I'm not too keen 
on adding special cases for such an uncommon case. Feel free to prove me wrong, 
though!

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26324] sum() incorrect on negative zeros

2016-02-09 Thread Ethan Furman

Ethan Furman added the comment:

If one is using sum on floats, and a list of -0.0's is a possibility, and the 
sign matters... well, I would hope that one is using -0.0 as the start value.

I don't think this is worth "fixing".

--
nosy: +ethan.furman

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26324] sum() incorrect on negative zeros

2016-02-09 Thread Mark Dickinson

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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26324] sum() incorrect on negative zeros

2016-02-09 Thread Raymond Hettinger

Raymond Hettinger added the comment:

> I think it's best left as it is

I concur.

--
nosy: +rhettinger

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com