Skip to content

Should INT_MIN % -1 return 0 instead of panicking? #1276

Open
@glaebhoerl

Description

@glaebhoerl

As @bill-myers originally pointed out here INT_MIN % -1 is mathematically well-defined to be 0, but Rust currently unconditionally panics instead, as like INT_MIN / -1 it is technically an overflow according to the two's complement representation. If we're incurring a branch to test for this case anyways, then we might as well return the correct result.

("Forked" from #1237.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-libs-apiRelevant to the library API team, which will review and decide on the RFC.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions