-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wrapping add #9
wrapping add #9
Conversation
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. |
Panics if range_size greater than inner::MAX. This only applies on signed integers. There might be a way to read bytes as unsigned, wrap add, then read bytes as signed. Using something like to_le_bytes and from_le_bytes.
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 Although there isn't an equivalent rem_euclid for unsigned arguments so maybe that technique won't work anyway. |
As to |
Still clarifying/checking wrapping add method works. It seems to work for all input I can come up with but since I haven't finished verifying it might be wrong.
a4b689a
to
fba6c18
Compare
- It was actually much simpler than previously realized. - The tests might be overkill
@jhpratt I think I finished the no_panic implementation with a valid explanation why the algorithm works. |
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation looks correct. I only have one question and two nits.
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.