From: Plekhanov Maxim Date: Fri, 22 Dec 2017 23:25:35 +0000 (+0300) Subject: math: use Abs in Pow rather than if x < 0 { x = -x } X-Git-Tag: go1.12beta1~891 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=47e71f3b6917113660a65a180e66c91fc6318458;p=gostls13.git math: use Abs in Pow rather than if x < 0 { x = -x } name old time/op new time/op delta PowInt 55.7ns ± 1% 53.4ns ± 2% -4.15% (p=0.000 n=9+9) PowFrac 133ns ± 1% 133ns ± 2% ~ (p=0.587 n=8+9) Change-Id: Ica0f4c2cbd554f2195c6d1762ed26742ff8e3924 Reviewed-on: https://go-review.googlesource.com/c/85375 Reviewed-by: Brad Fitzpatrick --- diff --git a/src/math/pow.go b/src/math/pow.go index 336193bce1..2219a906b8 100644 --- a/src/math/pow.go +++ b/src/math/pow.go @@ -83,13 +83,7 @@ func pow(x, y float64) float64 { return 1 / Sqrt(x) } - absy := y - flip := false - if absy < 0 { - absy = -absy - flip = true - } - yi, yf := Modf(absy) + yi, yf := Modf(Abs(y)) if yf != 0 && x < 0 { return NaN() } @@ -147,9 +141,9 @@ func pow(x, y float64) float64 { } // ans = a1*2**ae - // if flip { ans = 1 / ans } + // if y < 0 { ans = 1 / ans } // but in the opposite order - if flip { + if y < 0 { a1 = 1 / a1 ae = -ae }