aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2011-12-13 17:08:56 -0500
committerRuss Cox <rsc@golang.org>2011-12-13 17:08:56 -0500
commit2572803899485e6d07490ae04b1eb5aa5c758699 (patch)
tree90cb75351a5aaddc820c93984cbb3b0f56e6a7a2
parent2c6d3eaf78c9314fe49a550e765def95463179e8 (diff)
downloadgo-2572803899485e6d07490ae04b1eb5aa5c758699.tar.gz
go-2572803899485e6d07490ae04b1eb5aa5c758699.zip
math: delete non-Sqrt-based Hypot
I was confused by the existence of two portable Hypot routines in the tree when I cleaned things up, and I made ARM use the wrong (imprecise) one. Use the right one, and delete the wrong one. Fixes arm build. R=golang-dev, r CC=golang-dev https://golang.org/cl/5485065
-rw-r--r--src/pkg/math/all_test.go34
-rw-r--r--src/pkg/math/export_test.go3
-rw-r--r--src/pkg/math/hypot.go45
-rw-r--r--src/pkg/math/hypot_arm.s2
4 files changed, 10 insertions, 74 deletions
diff --git a/src/pkg/math/all_test.go b/src/pkg/math/all_test.go
index 7091c035ab..0a3cb0315d 100644
--- a/src/pkg/math/all_test.go
+++ b/src/pkg/math/all_test.go
@@ -2062,30 +2062,16 @@ func TestHypot(t *testing.T) {
}
}
-func TestHypotSqrtGo(t *testing.T) {
+func TestHypotGo(t *testing.T) {
for i := 0; i < len(vf); i++ {
a := Abs(1e200 * tanh[i] * Sqrt(2))
- if f := HypotSqrtGo(1e200*tanh[i], 1e200*tanh[i]); !veryclose(a, f) {
- t.Errorf("HypotSqrtGo(%g, %g) = %g, want %g", 1e200*tanh[i], 1e200*tanh[i], f, a)
+ if f := HypotGo(1e200*tanh[i], 1e200*tanh[i]); !veryclose(a, f) {
+ t.Errorf("HypotGo(%g, %g) = %g, want %g", 1e200*tanh[i], 1e200*tanh[i], f, a)
}
}
for i := 0; i < len(vfhypotSC); i++ {
- if f := HypotSqrtGo(vfhypotSC[i][0], vfhypotSC[i][1]); !alike(hypotSC[i], f) {
- t.Errorf("HypotSqrtGo(%g, %g) = %g, want %g", vfhypotSC[i][0], vfhypotSC[i][1], f, hypotSC[i])
- }
- }
-}
-
-func TestHypotNoSqrtGo(t *testing.T) {
- for i := 0; i < len(vf); i++ {
- a := Abs(1e200 * tanh[i] * Sqrt(2))
- if f := HypotNoSqrtGo(1e200*tanh[i], 1e200*tanh[i]); !veryclose(a, f) {
- t.Errorf("HypotNoSqrtGo(%g, %g) = %g, want %g", 1e200*tanh[i], 1e200*tanh[i], f, a)
- }
- }
- for i := 0; i < len(vfhypotSC); i++ {
- if f := HypotNoSqrtGo(vfhypotSC[i][0], vfhypotSC[i][1]); !alike(hypotSC[i], f) {
- t.Errorf("HypotNoSqrtGo(%g, %g) = %g, want %g", vfhypotSC[i][0], vfhypotSC[i][1], f, hypotSC[i])
+ if f := HypotGo(vfhypotSC[i][0], vfhypotSC[i][1]); !alike(hypotSC[i], f) {
+ t.Errorf("HypotGo(%g, %g) = %g, want %g", vfhypotSC[i][0], vfhypotSC[i][1], f, hypotSC[i])
}
}
}
@@ -2741,15 +2727,9 @@ func BenchmarkHypot(b *testing.B) {
}
}
-func BenchmarkHypotNoSqrtGo(b *testing.B) {
- for i := 0; i < b.N; i++ {
- HypotNoSqrtGo(3, 4)
- }
-}
-
-func BenchmarkHypotSqrtGo(b *testing.B) {
+func BenchmarkHypotGo(b *testing.B) {
for i := 0; i < b.N; i++ {
- HypotSqrtGo(3, 4)
+ HypotGo(3, 4)
}
}
diff --git a/src/pkg/math/export_test.go b/src/pkg/math/export_test.go
index c32a5dbd1d..02992d70e8 100644
--- a/src/pkg/math/export_test.go
+++ b/src/pkg/math/export_test.go
@@ -7,6 +7,5 @@ package math
// Export internal functions for testing.
var ExpGo = exp
var Exp2Go = exp2
-var HypotSqrtGo = hypotSqrt
-var HypotNoSqrtGo = hypotNoSqrt
+var HypotGo = hypot
var SqrtGo = sqrt
diff --git a/src/pkg/math/hypot.go b/src/pkg/math/hypot.go
index ee9759ad7a..233257b522 100644
--- a/src/pkg/math/hypot.go
+++ b/src/pkg/math/hypot.go
@@ -16,7 +16,7 @@ package math
// Hypot(p, q) = NaN if p or q is NaN
func Hypot(p, q float64) float64
-func hypotSqrt(p, q float64) float64 {
+func hypot(p, q float64) float64 {
// TODO(rsc): Remove manual inlining of IsNaN, IsInf
// when compiler does it for us
// special cases
@@ -41,46 +41,3 @@ func hypotSqrt(p, q float64) float64 {
q = q / p
return p * Sqrt(1+q*q)
}
-
-func hypotNoSqrt(p, q float64) float64 {
- // TODO(rsc): Remove manual inlining of IsNaN, IsInf
- // when compiler does it for us
- // special cases
- switch {
- case p < -MaxFloat64 || p > MaxFloat64 || q < -MaxFloat64 || q > MaxFloat64: // IsInf(p, 0) || IsInf(q, 0):
- return Inf(1)
- case p != p || q != q: // IsNaN(p) || IsNaN(q):
- return NaN()
- }
- if p < 0 {
- p = -p
- }
- if q < 0 {
- q = -q
- }
-
- if p < q {
- p, q = q, p
- }
-
- if p == 0 {
- return 0
- }
-
- pfac := p
- q = q / p
- r := q
- p = 1
- for {
- r = r * r
- s := r + 4
- if s == 4 {
- return p * pfac
- }
- r = r / s
- p = p + 2*r*p
- q = q * r
- r = q / p
- }
- panic("unreachable")
-}
diff --git a/src/pkg/math/hypot_arm.s b/src/pkg/math/hypot_arm.s
index f3f492719e..2c599fd551 100644
--- a/src/pkg/math/hypot_arm.s
+++ b/src/pkg/math/hypot_arm.s
@@ -3,4 +3,4 @@
// license that can be found in the LICENSE file.
TEXT ·Hypot(SB),7,$0
- B ·hypotNoSqrt(SB)
+ B ·hypot(SB)