Tim Peters <t...@python.org> added the comment:

I assumed Mark would tell us what's up with the arange() oddity, so let's see 
whether he does.  There is no truly good way to generate "evenly spaced" binary 
floats using a non-representable conceptual decimal delta.  The dumbass ;-) way 
doesn't show a discrepancy in pure Python:

>>> num = ne = no = 0
>>> d = 0.001
>>> while num < 1.0:
...     digit = int(round(num, 1) * 10)
...     if digit & 1:
...         no += 1
...     else:
...         ne += 1
...     num += d
>>> ne, no
(500, 500)

However, a somewhat less naive way does show a discrepancy, but less so than 
what arange() apparently does:

>>> ne = no = 0
>>> for i in range(1000):
...     digit = int(round(i * d, 1) * 10)
...     if digit & 1:
...         no += 1
...     else:
...         ne += 1
>>> ne, no
(501, 499)

I assume that's because of the specific nearest/even behavior I already showed 
for multipliers i=250 and i=750.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue41198>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to