Message372888
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. |
|
Date |
User |
Action |
Args |
2020-07-02 21:56:36 | tim.peters | set | recipients:
+ tim.peters, lemburg, rhettinger, mark.dickinson, stutzbach, steven.daprano, Carlos Neves |
2020-07-02 21:56:36 | tim.peters | set | messageid: <1593726996.51.0.209433996335.issue41198@roundup.psfhosted.org> |
2020-07-02 21:56:36 | tim.peters | link | issue41198 messages |
2020-07-02 21:56:36 | tim.peters | create | |
|