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: Exp does not handle negative exponents correctly #25865

Closed
zzh1823 opened this issue Jun 13, 2018 · 2 comments
Closed

math/big: Exp does not handle negative exponents correctly #25865

zzh1823 opened this issue Jun 13, 2018 · 2 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@zzh1823
Copy link

zzh1823 commented Jun 13, 2018

Please answer these questions before submitting your issue. Thanks!

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

Go 1.10

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

linux_amd64

What did you do?

When using package math/big, specifically big.Int.Exp(), I found that it cannot handle negative exponents correctly but simply returns 1.

What did you expect to see?

Compared to ModPow() in Java, Exp(x, y, z) should return mod inverse of (x ^ Abs(y)) mod N when y is negative.

What did you see instead?

Exp(x, y, z) simply returns 1 when y is negative.

@ianlancetaylor ianlancetaylor changed the title math/big Exp() does not handle negative exponents correctly math/big: Exp does not handle negative exponents correctly Jun 13, 2018
@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 13, 2018
@ianlancetaylor ianlancetaylor added this to the Go1.12 milestone Jun 13, 2018
@gopherbot
Copy link

Change https://golang.org/cl/118562 mentions this issue: math/big: handle negative exponents in Exp

@zzh1823
Copy link
Author

zzh1823 commented Jun 14, 2018

Thanks for the fix!
I checked the revision: Exp(x, y, m) = Exp(ModInv(x, m), y.abs, m). I wonder if ModInv(Exp(x, y.abs, m), m) is simpler.

@golang golang locked and limited conversation to collaborators Jun 14, 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