Author tim.peters
Recipients Carlos Neves, lemburg, mark.dickinson, rhettinger, steven.daprano, stutzbach, tim.peters
Date 2020-07-02.21:56:36
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1593726996.51.0.209433996335.issue41198@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2020-07-02 21:56:36tim.peterssetrecipients: + tim.peters, lemburg, rhettinger, mark.dickinson, stutzbach, steven.daprano, Carlos Neves
2020-07-02 21:56:36tim.peterssetmessageid: <1593726996.51.0.209433996335.issue41198@roundup.psfhosted.org>
2020-07-02 21:56:36tim.peterslinkissue41198 messages
2020-07-02 21:56:36tim.peterscreate