Title: Accuracy issues of sum() specialization for floats/complexes · Issue #122234 · python/cpython · GitHub
Open Graph Title: Accuracy issues of sum() specialization for floats/complexes · Issue #122234 · python/cpython
X Title: Accuracy issues of sum() specialization for floats/complexes · Issue #122234 · python/cpython
Description: Bug report Bug description: Unfortunately, #121176 was merged with a bug: cpython/Python/bltinmodule.c Lines 2749 to 2755 in e968121 if (PyFloat_Check(item)) { double value = PyFloat_AS_DOUBLE(item); re_sum.hi += value; im_sum.hi += 0.0;...
Open Graph Description: Bug report Bug description: Unfortunately, #121176 was merged with a bug: cpython/Python/bltinmodule.c Lines 2749 to 2755 in e968121 if (PyFloat_Check(item)) { double value = PyFloat_AS_DOUBLE(item...
X Description: Bug report Bug description: Unfortunately, #121176 was merged with a bug: cpython/Python/bltinmodule.c Lines 2749 to 2755 in e968121 if (PyFloat_Check(item)) { double value = PyFloat_AS_DOUBLE(item...
Opengraph URL: https://github.com/python/cpython/issues/122234
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Accuracy issues of sum() specialization for floats/complexes","articleBody":"# Bug report\r\n\r\n### Bug description:\r\n\r\nUnfortunately, #121176 was merged with a bug:\r\nhttps://github.com/python/cpython/blob/e9681211b9ad11d1c1f471c43bc57cac46814779/Python/bltinmodule.c#L2749-L2755\r\nL2751 lacks cs_add(). Sorry for that. Reproducer: ``sum([2j, 1., 10E100, 1., -10E100])`` (should be ``2+2j``). I'll provide a patch.\r\n\r\nBut maybe cases for integer arguments also should use compensated summation? E.g.:\r\nhttps://github.com/python/cpython/blob/e9681211b9ad11d1c1f471c43bc57cac46814779/Python/bltinmodule.c#L2689-L2698\r\non L2694 (and use ``PyLong_AsDouble()``). An example:\r\n```pycon\r\n\u003e\u003e\u003e sum([1.0, 10E100, 1.0, -10E100])\r\n2.0\r\n\u003e\u003e\u003e sum([1.0, 10**100, 1.0, -10**100]) # huh?\r\n0.0\r\n```\r\nI would guess, that integer values in this case are treated as exact and they are allowed to smash floating-point result to garbage. But... This looks as a bug for me. ``fsum()`` also chooses ``2.0``:\r\n```pycon\r\n\u003e\u003e\u003e math.fsum([1.0, 10**100, 1.0, -10**100])\r\n2.0\r\n```\r\n\r\n\r\n### CPython versions tested on:\r\n\r\nCPython main branch\r\n\r\n### Operating systems tested on:\r\n\r\n_No response_\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-122236\n* gh-122406\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/skirpichev","@type":"Person","name":"skirpichev"},"datePublished":"2024-07-24T14:07:07.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":9},"url":"https://github.com/122234/cpython/issues/122234"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:2de4423c-a381-f23a-1881-9f2516ee5d6f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DCCE:1025CE:295850:378C9F:6969AA11 |
| html-safe-nonce | ca9ea63dc9a20601099522f00b93e7291304d5c5a0fdf23ccdbdb6fa7b8ff142 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQ0NFOjEwMjVDRToyOTU4NTA6Mzc4QzlGOjY5NjlBQTExIiwidmlzaXRvcl9pZCI6IjQzNTAzMzQ5NzEwMTY3NTE2MzMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | cb02744398a119c50ec75ac63fdac29da46c268feaa9a7ced66a5689436f2be8 |
| hovercard-subject-tag | issue:2427697244 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/122234/issue_layout |
| twitter:image | https://opengraph.githubassets.com/dbd83e6929760c09991d5b1874a8dc7c3b4f1c004f8ec4ddd09e6ae0a53352b4/python/cpython/issues/122234 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/dbd83e6929760c09991d5b1874a8dc7c3b4f1c004f8ec4ddd09e6ae0a53352b4/python/cpython/issues/122234 |
| og:image:alt | Bug report Bug description: Unfortunately, #121176 was merged with a bug: cpython/Python/bltinmodule.c Lines 2749 to 2755 in e968121 if (PyFloat_Check(item)) { double value = PyFloat_AS_DOUBLE(item... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | skirpichev |
| hostname | github.com |
| expected-hostname | github.com |
| None | 24c4c97a2d520cb286b35e1a4c22d7a4df3c26a2fa28dd7cdf0e65db327b4de7 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 124667f43168afb6c9c03b7c02eb5b1d2e1be3d9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width