// add x0*y1*b
x0 := x0.norm()
- y1 := y[k:] // y1 is normalized because y is
- addAt(z, t.mul(x0, y1), k)
+ y1 := y[k:] // y1 is normalized because y is
+ t = t.mul(x0, y1) // update t so we don't lose t's underlying array
+ addAt(z, t, k)
// add xi*y0<<i, xi*y1*b<<(i+k)
y0 := y0.norm()
xi = xi[:k]
}
xi = xi.norm()
- addAt(z, t.mul(xi, y0), i)
- addAt(z, t.mul(xi, y1), i+k)
+ t = t.mul(xi, y0)
+ addAt(z, t, i)
+ t = t.mul(xi, y1)
+ addAt(z, t, i+k)
}
}
// 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.
+ // We cannot allow in-place modification of x or y.
z = nil
}
// TestMulUnbalanced tests that multiplying numbers of different lengths
// does not cause deep recursion and in turn allocate too much memory.
-// test case for issue 3807
+// Test case for issue 3807.
func TestMulUnbalanced(t *testing.T) {
x := rndNat(50000)
y := rndNat(40)
for i := 0; i < n; i++ {
x[i] = Word(rnd.Int63()<<1 + rnd.Int63n(2))
}
- return x
+ return x.norm()
}
func BenchmarkMul(b *testing.B) {