[New-bugs-announce] [issue43887] it seems that sorted built-in always return floats before int if they appear to be equal

John Mish report at bugs.python.org
Mon Apr 19 07:48:23 EDT 2021


New submission from John Mish <johnmish.iam at gmail.com>:

A1
>>> sorted([12.000000000000001, 2, 1.999, 2.1, 4, 12])
[1.999, 2, 2.1, 4, 12, 12.000000000000002]
A2
>>> sorted([12.0000000000000001, 2, 1.999, 2.1, 4, 12])
[1.999, 2, 2.1, 4, 12.0, 12]
B1
>>> sorted([11.999999999999999, 2, 1.999, 2.1, 4, 12])
[1.999, 2, 2.1, 4, 11.999999999999998, 12]
B2
>>> sorted([11.9999999999999999, 2, 1.999, 2.1, 4, 12])
[1.999, 2, 2.1, 4, 12.0, 12]

Hello,

In A2 and in B2 we see the same output for 2 not equal expected values.

It seems to be that floats are always first in list.

So, what about trying to "store" if some float is 12 "in limit" of 12 but from "left/-"? So then it is < than 12.

12.000000000000000000000000000001 would be then 12 but in upper limit, right/+ so > 12

What do You think?

Best regards.

PS ofc I could use decimal, but if it shouldn't work, why it does not raise exception and ask for forgiveness... ?

----------
components: Interpreter Core
messages: 391372
nosy: johnmish.iam
priority: normal
severity: normal
status: open
title: it seems that sorted built-in always return floats before int if they appear to be equal
type: behavior
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43887>
_______________________________________


More information about the New-bugs-announce mailing list