aboutsummaryrefslogtreecommitdiff
path: root/src/math
diff options
context:
space:
mode:
authorPlekhanov Maxim <kishtatix@gmail.com>2017-12-21 02:14:55 +0300
committerBrad Fitzpatrick <bradfitz@golang.org>2018-10-04 17:32:44 +0000
commit497d24178fdc321a037150656d51bec40f93e6d6 (patch)
treef3cf16e720acd7ac0a084e6048f267cd6b139de2 /src/math
parentf22c357a34521404c445dc2e848657ecbfa4ad5e (diff)
downloadgo-497d24178fdc321a037150656d51bec40f93e6d6.tar.xz
math: use Abs in Mod rather than if x < 0 { x = -x}
goos: linux goarch: amd64 pkg: math name old time/op new time/op delta Mod 64.7ns ± 2% 63.7ns ± 2% -1.52% (p=0.003 n=8+10) Change-Id: I851bec0fd6c223dab73e4a680b7393d49e81a0e8 Reviewed-on: https://go-review.googlesource.com/c/85095 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/math')
-rw-r--r--src/math/mod.go8
1 files changed, 2 insertions, 6 deletions
diff --git a/src/math/mod.go b/src/math/mod.go
index e1a414e5f9..7efc018a5d 100644
--- a/src/math/mod.go
+++ b/src/math/mod.go
@@ -24,16 +24,12 @@ func mod(x, y float64) float64 {
if y == 0 || IsInf(x, 0) || IsNaN(x) || IsNaN(y) {
return NaN()
}
- if y < 0 {
- y = -y
- }
+ y = Abs(y)
yfr, yexp := Frexp(y)
- sign := false
r := x
if x < 0 {
r = -x
- sign = true
}
for r >= y {
@@ -43,7 +39,7 @@ func mod(x, y float64) float64 {
}
r = r - Ldexp(y, rexp-yexp)
}
- if sign {
+ if x < 0 {
r = -r
}
return r