From 497f891fce8c6657ab28dfcd2e7195014f3a967f Mon Sep 17 00:00:00 2001 From: Brian Kessler Date: Thu, 17 Aug 2017 23:26:31 -0700 Subject: [PATCH] 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/56774 Reviewed-by: Robert Griesemer Run-TryBot: Robert Griesemer TryBot-Result: Gobot Gobot --- src/math/big/float.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/math/big/float.go b/src/math/big/float.go index afbed306f3..c042854eba 100644 --- a/src/math/big/float.go +++ b/src/math/big/float.go @@ -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) } -- 2.50.0