-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
fix: Base.GMP.MPZ.invert yielding return code instead of return value #56894
fix: Base.GMP.MPZ.invert yielding return code instead of return value #56894
Conversation
It'd be good to add a regression test |
base/gmp.jl
Outdated
invert!(x::BigInt, b::BigInt) = invert!(x, x, b) | ||
function invert(a::BigInt, b::BigInt) | ||
ret = deepcopy(a) |
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.
ret = deepcopy(a) | |
ret = BigInt() |
A deepcopy
is a bit excessive.
P.S.: Alternatively you can fix the invert!(x::BigInt, a::BigInt, b::BigInt)
function to return x
.
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.
I dont think I can without also refactoring invmod(x::BigInt, y::BigInt)
at line 519
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.
However I modified the original commit in shorter notation without the deepcopy
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.
Alternatively you can fix the
invert!(x::BigInt, a::BigInt, b::BigInt)
function to returnx
.
Initially I agreed, but looking at invmod
, I see that there still needs to be a way to get the return code and the return value is the cleanest way I can think of.
e4c2c59
to
00cda38
Compare
9eb202f
to
bb79ec4
Compare
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.
Thanks for finding and fixing this! A lovely first pull request.
Hey,
I hope I followed all guidelines for contributing, this is my first contribution.
There is a bug in
Base.GMP.MPZ.invert
it returns GMP return code, instead of the actual value. This PR fixes it. I am not sure if it could be implemented better, but from my testing you cannot get away without a deepcopy.Before:
After: