You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The text was updated successfully, but these errors were encountered:
mikioh
changed the title
math/big Exp function returns puzzling results when exponent = 1
math/big: Exp function returns puzzling results when exponent = 1
Feb 10, 2015
In nat.go expNN (here), when y is 1, v is set to 1 (here) and shift on the next line to 64. Then on the line
w := _W - int(shift)
w is set to 0(64 - 64), so the code inside the loop on line 921 is never ran. Since z (the result) was set to x (on line 895) and never changed the function returns x (5 in the example) instead of x mod m.
I'm using Go 1.4 on 64 bit Debian.
I run the following:
import "math/big"
a := new(big.Int).Exp(big.NewInt(5), big.NewInt(1), big.NewInt(3))
I expect 'a' to be 2, because 5**1 % 3 = 5 % 3 = 2. Instead, Go gives a = 5.
Code can be found here: http://play.golang.org/p/TCWWiXXZhf
The text was updated successfully, but these errors were encountered: