Commit 497f891f authored by Brian Kessler's avatar Brian Kessler Committed by Robert Griesemer

math/big: recognize squaring for Floats

Updates #13745

Recognize z.Mul(x, x) as squaring for Floats and use
the internal z.sqr(x) method for nat on the mantissa.

Change-Id: I0f792157bad93a13cae1aecc4c10bd20c6397693
Reviewed-on: https://go-review.googlesource.com/56774Reviewed-by: default avatarRobert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent fe08ebae
...@@ -1311,8 +1311,11 @@ func (z *Float) umul(x, y *Float) { ...@@ -1311,8 +1311,11 @@ func (z *Float) umul(x, y *Float) {
// TODO(gri) Optimize this for the common case. // TODO(gri) Optimize this for the common case.
e := int64(x.exp) + int64(y.exp) e := int64(x.exp) + int64(y.exp)
if x == y {
z.mant = z.mant.sqr(x.mant)
} else {
z.mant = z.mant.mul(x.mant, y.mant) z.mant = z.mant.mul(x.mant, y.mant)
}
z.setExpAndRound(e-fnorm(z.mant), 0) z.setExpAndRound(e-fnorm(z.mant), 0)
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment