summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/pkg/math/all_test.go11
-rw-r--r--src/pkg/math/sqrt.go1
-rw-r--r--src/pkg/math/sqrt_port.go6
3 files changed, 12 insertions, 6 deletions
diff --git a/src/pkg/math/all_test.go b/src/pkg/math/all_test.go
index a653555a2..af4d88635 100644
--- a/src/pkg/math/all_test.go
+++ b/src/pkg/math/all_test.go
@@ -1335,12 +1335,16 @@ var sinhSC = []float64{
var vfsqrtSC = []float64{
Inf(-1),
-Pi,
+ -1 / Inf(1), // -0
+ 0,
Inf(1),
NaN(),
}
var sqrtSC = []float64{
NaN(),
NaN(),
+ -1 / Inf(1), // -0
+ 0,
Inf(1),
NaN(),
}
@@ -2018,7 +2022,7 @@ func TestSqrt(t *testing.T) {
for i := 0; i < len(vf); i++ {
a := Fabs(vf[i])
if f := SqrtGo(a); sqrt[i] != f {
- t.Errorf("sqrtGo(%g) = %g, want %g\n", a, f, sqrt[i])
+ t.Errorf("SqrtGo(%g) = %g, want %g\n", a, f, sqrt[i])
}
a = Fabs(vf[i])
if f := Sqrt(a); sqrt[i] != f {
@@ -2026,7 +2030,10 @@ func TestSqrt(t *testing.T) {
}
}
for i := 0; i < len(vfsqrtSC); i++ {
- if f := Log10(vfsqrtSC[i]); !alike(sqrtSC[i], f) {
+ if f := SqrtGo(vfsqrtSC[i]); !alike(sqrtSC[i], f) {
+ t.Errorf("SqrtGo(%g) = %g, want %g\n", vfsqrtSC[i], f, sqrtSC[i])
+ }
+ if f := Sqrt(vfsqrtSC[i]); !alike(sqrtSC[i], f) {
t.Errorf("Sqrt(%g) = %g, want %g\n", vfsqrtSC[i], f, sqrtSC[i])
}
}
diff --git a/src/pkg/math/sqrt.go b/src/pkg/math/sqrt.go
index e6bc4680b..ff5cc91e0 100644
--- a/src/pkg/math/sqrt.go
+++ b/src/pkg/math/sqrt.go
@@ -8,6 +8,7 @@ package math
//
// Special cases are:
// Sqrt(+Inf) = +Inf
+// Sqrt(±0) = ±0
// Sqrt(x < 0) = NaN
// Sqrt(NaN) = NaN
func Sqrt(x float64) float64 { return sqrtGo(x) }
diff --git a/src/pkg/math/sqrt_port.go b/src/pkg/math/sqrt_port.go
index c818834e7..8d821b559 100644
--- a/src/pkg/math/sqrt_port.go
+++ b/src/pkg/math/sqrt_port.go
@@ -90,7 +90,7 @@ package math
//
// Special cases are:
// Sqrt(+Inf) = +Inf
-// Sqrt(0) = 0
+// Sqrt(±0) = ±0
// Sqrt(x < 0) = NaN
// Sqrt(NaN) = NaN
func sqrtGo(x float64) float64 {
@@ -98,10 +98,8 @@ func sqrtGo(x float64) float64 {
// TODO(rsc): Remove manual inlining of IsNaN, IsInf
// when compiler does it for us
switch {
- case x != x || x > MaxFloat64: // IsNaN(x) || IsInf(x, 1):
+ case x == 0 || x != x || x > MaxFloat64: // x == 0 || IsNaN(x) || IsInf(x, 1):
return x
- case x == 0:
- return 0
case x < 0:
return NaN()
}