Skip to content
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

math/big: handle negative moduli in ModInverse #24949

Closed
bmkessler opened this issue Apr 19, 2018 · 3 comments
Closed

math/big: handle negative moduli in ModInverse #24949

bmkessler opened this issue Apr 19, 2018 · 3 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@bmkessler
Copy link
Contributor

What version of Go are you using (go version)?

go version go1.10 linux/amd64

Does this issue reproduce with the latest release?

yes

What did you do?

Calculate ModInverse with positive and negative moduli.

https://play.golang.org/p/oCjaCyBdbp7

What did you expect to see?

Both should give the same result for ModInverse.

What did you see instead?

Negative moduli returns 0.

@gopherbot
Copy link

Change https://golang.org/cl/108115 mentions this issue: math/big: handle negative moduli in ModInverse

@FiloSottile
Copy link
Contributor

When the modulus is negative, shouldn't the result be negative as well?

@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 19, 2018
@ianlancetaylor ianlancetaylor added this to the Go1.11 milestone Apr 19, 2018
@bmkessler
Copy link
Contributor Author

I think the result should always be non-negative per the definition of Euclidean modulus from the go docs

DivMod implements Euclidean division and modulus (unlike Go):
q = x div y such that
m = x - y*q with 0 <= m < |y|

So, I would expect the result of ModInverse to always be non-negative as well, such that taking the Mod of the ModInverse would be the identity. If the ModInverse result was negative, taking the Mod of the result would return the positive value.

@golang golang locked and limited conversation to collaborators May 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants