]> Cypherpunks repositories - gostls13.git/commitdiff
math/big: recognize squaring for Floats
authorBrian Kessler <brian.m.kessler@gmail.com>
Fri, 18 Aug 2017 06:26:31 +0000 (23:26 -0700)
committerRobert Griesemer <gri@golang.org>
Fri, 18 Aug 2017 12:48:10 +0000 (12:48 +0000)
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/56774
Reviewed-by: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/math/big/float.go

index afbed306f3d67f795c10b18419ec3846340e8208..c042854ebaafcf3d7444f3c042099fd2bfc35036 100644 (file)
@@ -1311,8 +1311,11 @@ func (z *Float) umul(x, y *Float) {
        // TODO(gri) Optimize this for the common case.
 
        e := int64(x.exp) + int64(y.exp)
-       z.mant = z.mant.mul(x.mant, y.mant)
-
+       if x == y {
+               z.mant = z.mant.sqr(x.mant)
+       } else {
+               z.mant = z.mant.mul(x.mant, y.mant)
+       }
        z.setExpAndRound(e-fnorm(z.mant), 0)
 }