R=gri
CC=golang-dev, golang-dev
https://golang.org/cl/
1244044
// See Knuth, volume 2, section 4.6.3.
func (z *Int) Exp(x, y, m *Int) *Int {
if y.neg || len(y.abs) == 0 {
+ neg := x.neg
z.SetInt64(1)
- z.neg = x.neg
+ z.neg = neg
return z
}
continue
}
- z := new(Int).Exp(x, y, m)
+ z := y.Exp(x, y, m)
if !isNormalized(z) {
t.Errorf("#%d: %v is not normalized", i, *z)
}
// If m != nil, expNN calculates x**y mod m. Otherwise it calculates x**y. It
// reuses the storage of z if possible.
func (z nat) expNN(x, y, m nat) nat {
+ if alias(z, x) || alias(z, y) {
+ // We cannot allow in place modification of x or y.
+ z = nil
+ }
+
if len(y) == 0 {
z = z.make(1)
z[0] = 1