Skip to content

Fix is_multiple_of(&MIN, &-1) - #83

Open
Marsman1996 wants to merge 1 commit into
rust-num:mainfrom
Marsman1996:fix-is_multiple_of
Open

Marsman1996 wants to merge 1 commit into
rust-num:mainfrom
Marsman1996:fix-is_multiple_of

Conversation

@Marsman1996

Copy link
Copy Markdown

For self == i64::MIN, other == -1, the % hits the remainder-overflow case (MIN / -1 overflows).

num-integer/src/lib.rs

Lines 570 to 575 in 765fd9b

fn is_multiple_of(&self, other: &Self) -> bool {
if other.is_zero() {
return self.is_zero();
}
*self % *other == 0
}

Mathematically MIN % -1 is 0, so is_multiple_of(&MIN, &-1) should return true, consistent with the existing -1 guards in next_multiple_of and prev_multiple_of that were added in #45

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant