Skip to content

Conversation

andrewwhitehead
Copy link
Contributor

Fixes #847

The result of taking a signed integer modulo an unsigned one should be unsigned. Python agrees at least:

>>> hex(-0x112709385A4E59AFCE14364856CB6D1760D7D2B618A2DA9F85A96C4C2751D179 % 0xde157f812521c55eccf9a903b31e4a34)
'0x44bfe3176459710d0d0848f99b37e47b'
>>> hex(0x112709385A4E59AFCE14364856CB6D1760D7D2B618A2DA9F85A96C4C2751D179 % 0xde157f812521c55eccf9a903b31e4a34)
'0x99559c69c0c85451bff1600a17e665b9'

This also removes the RemAssign implementations, Int %= Uint. If somebody needs to do this, I think they can do a checked conversion to an Int for the modulus first.

Signed-off-by: Andrew Whitehead <[email protected]>
@fjarri
Copy link
Contributor

fjarri commented Jul 28, 2025

I think in Rust's terms that makes it rem_euclid rather than rem.

@andrewwhitehead
Copy link
Contributor Author

I think in Rust's terms that makes it rem_euclid rather than rem.

Yes, it's also possible to rename these methods to rem_euclid and add a separate RemEuclid trait. A checked_rem method that returned a CtOption<Int<LIMBS>> would also be possible (checking if the modulus fits in an Int).

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.

Bug in Int::div_rem_uint
2 participants