-
Notifications
You must be signed in to change notification settings - Fork 49
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
Integer::extended_gcd should not permit unsigned value. #40
Comments
May be we can require |
Yeah, we do require |
Alternatively, it's possible to support Edit: because assert_eq!(
gcd,
(x * a + y * b) % (a * b),
); |
@aj-r interesting, thanks! I'm open to "fixing" unsigned with that kind of implementation, as long as we're careful to document the difference -- and ideally how to reconstruct what the signed result would have been. |
Maybe we could then drop |
Fwiw I was recently bitten by this. But I was running in release mode so the program didn't crash. But half the time my algorithm was spitting out weird incorrect values because the coefficient I used was the under-flowed value. Switching to a signed type was easy enough for me in this particular case but I lost a few hours. My expectations as a consumer would have been either the unsigned types did not have this method, or only produced results in the domain of that unsigned type as @aj-r mentioned. (I consider underflow outside of the domain). As for backwards compatibly, as a consumer and I saw my build break because I used an unsigned type with this method and had silent bugs in my program because of it I think I would be thankful. |
This code fails to get the y value, with the error 'attempt to subtract with overflow'.
The text was updated successfully, but these errors were encountered: