Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Accuracy issues of sum() specialization for floats/complexes #122234

Closed
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error
@skirpichev

Description

@skirpichev

Bug report

Bug description:

Unfortunately,#121176 was merged with a bug:

if (PyFloat_Check(item)) {
doublevalue=PyFloat_AS_DOUBLE(item);
re_sum.hi+=value;
im_sum.hi+=0.0;
_Py_DECREF_SPECIALIZED(item,_PyFloat_ExactDealloc);
continue;
}

L2751 lacks cs_add(). Sorry for that. Reproducer:sum([2j, 1., 10E100, 1., -10E100]) (should be2+2j). I'll provide a patch.

But maybe cases for integer arguments also should use compensated summation? E.g.:

if (PyLong_Check(item)) {
longvalue;
intoverflow;
value=PyLong_AsLongAndOverflow(item,&overflow);
if (!overflow) {
re_sum.hi+= (double)value;
Py_DECREF(item);
continue;
}
}

on L2694 (and usePyLong_AsDouble()). An example:

>>>sum([1.0,10E100,1.0,-10E100])2.0>>>sum([1.0,10**100,1.0,-10**100])# huh?0.0

I 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 chooses2.0:

>>> math.fsum([1.0,10**100,1.0,-10**100])2.0

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2026 Movatter.jp