Skip to content

% and REM fail to handle -1, -9223372036854775808 #2

@Sejsel

Description

@Sejsel

Currently, both % and REM instructions will fail with IntegerOverflow when used with -1, -9223372036854775808 as the parameters, even though the result should clearly be zero.

This happens because the rust checked_rem_euclid and checked_rem both "overflow" on this case. It is documented (with no explanation given, and to be honest, when I looked up the design of these functions, it doesn't exactly look like it was given much thought). It is clearly wrong from the viewpoint of the result.

-9223372036854775804         mod -1 = 0
-9223372036854775804 checked mod -1 = Some(0)
-9223372036854775805         mod -1 = 0
-9223372036854775805 checked mod -1 = Some(0)
-9223372036854775806         mod -1 = 0
-9223372036854775806 checked mod -1 = Some(0)
-9223372036854775807         mod -1 = 0
-9223372036854775807 checked mod -1 = Some(0)
-9223372036854775808         mod -1 = 0
-9223372036854775808 checked mod -1 = None

We do have tests checking this case (they expect fail), but we should change them to expect 0 as the result.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions