Skip to content

[Feature Request]: consider using more accurate algorithm for sum() of floating-point values #1281

Open

Description

@skirpichev

Describe the feature

See python/cpython#100425 (available since v3.12). N.B.: this was extended to complex input in python/cpython#121176 (available since v3.14).

An example:

Python 3.16.0a0 (heads/main:ee68f5f46a1, Aug 12 2026, 11:19:39) [GCC 14.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> xs = [1.0,1e200,1.0,-1e200]
>>> sum(xs)
2.0
>>> res = xs[0]
... for t in xs[1:]:
...     res += t
... res  # naive result
... 
0.0

vs

Python 3.13.14 (Thu Sep 17 18:51:21 UTC 2026)
[Graal, Oracle GraalVM, Java 25.0.4.1.1 (amd64)] on 'linux'
Type "help", "copyright", "credits" or "license" for more information.
>>> sum([1.0,1e200,1.0,-1e200])
0.0

Expected behavior

Close to CPython (or NumPy).

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions