According to the implementation of trait method modulo
let result = self % rhs.clone();
if result < Self::Output::default() {
result + rhs
}
The modulo result will be wrong if result and rhs both are negative numbers. (-1).modulo(-2) gives the wrong result -3, it should be 1 anyway.
The fix may be result + | rhs |? Namely, result + rhs.abs()