Skip to content

extra::stats suffers from catastrophic cancellation #10851

Closed
@huonw

Description

@huonw

It is using the naive algorithm which is numerically unstable; it should be using something like Kahan summation.

extern mod extra;
use extra::stats::Stats;

fn main() {
    // prints 0, but should be 1
    println!("{}", [1e20, 1.0, -1e20].sum());
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions