Closed Easyoakland closed 1 year ago
I'm surprised you managed to figure out the inner workings, as basically nothing is documented right now.
Wrapping, checked, and overflowing arithmetic is something that I wanted to implement for a while, and was thinking about recently.
I will take a look into this soon! I imagine it'll take some thinking on my end.
The implementation panics if the number is signed and the range is too large. Ideally this could be fixed with methods like checked_add_unsigned but the if_signed
macro doesn't seem to work inside the method body and the unsigned
methods are not implemented for unsigned types.
Although there isn't an equivalent rem_euclid for unsigned arguments so maybe that technique won't work anyway.
checked_add_unsigned
should work. It'll require the MSRV be bumped, but that's not an issue.
As to rem_euclid
, I imagine it's possible to implement it manually. I would provide a function definition, but I don't have sufficient time at the moment.
@jhpratt I think I finished the no_panic implementation with a valid explanation why the algorithm works. Feel free to check that it's actually valid.
Thanks, I'll check it out! Now you know why I was putting off implementing it myself 😅
Quick status update: Apologies for the delay! Between RustConf and some other things, I've been quite busy. I intend to look at this in the next day or two.
Thanks for the changes! Everything LGTM. Merging.
Adding methods for wrapping.
I don't know if there is a better way to implement these.
Currently only
wrapping_add
is implemented but I can work on the others if this is the correct way to go about it.