-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Closed as not planned
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
I am encountering some strange results in Python 3.12.3 when summing up numbers using the sum function.
It seems that there are some precision issues, which I wouldn't expect with these numbers:
>>> 2.5392 + 0.4608 - 3.0
0.0
>>> sum([2.5392,0.4608,-3.0], 0.0)
1.1102230246251565e-16
>>> import numpy
>>> sum([2.5392,0.4608,-3.0], numpy.float64(0.0))
0.0I tested on the official docker images of Python 3.11 - 3.13 and version 3.13 also seem affected (3.11 works as expected).
$ docker run -it python:3.11 python -c "print(sum([2.5392,0.4608,-3.0], 0.0))"
0.0
$ docker run -it python:3.12 python -c "print(sum([2.5392,0.4608,-3.0], 0.0))"
1.1102230246251565e-16
$ docker run -it python:3.13 python -c "print(sum([2.5392,0.4608,-3.0], 0.0))"
1.1102230246251565e-16CPython versions tested on:
3.12, 3.13
Operating systems tested on:
Linux, macOS
Metadata
Metadata
Assignees
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error