Skip to content

Commit 6e6fc67

Browse files
committed
math: make portable Tan(Pi/2) return NaN
The panic NaN was a translation error. The earliest version said panic "return sys.NaN()", and when sys.NaN came along, it changed to "panic sys.NaN()" instead of "return sys.NaN()". R=r CC=golang-dev https://golang.org/cl/2106049
1 parent a4514c4 commit 6e6fc67

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/pkg/math/all_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package math_test
77
import (
88
"fmt"
99
. "math"
10+
"runtime"
1011
"testing"
1112
)
1213

@@ -2100,6 +2101,16 @@ func TestTan(t *testing.T) {
21002101
t.Errorf("Tan(%g) = %g, want %g\n", vfsinSC[i], f, sinSC[i])
21012102
}
21022103
}
2104+
2105+
// Make sure portable Tan(Pi/2) doesn't panic (it used to).
2106+
// The portable implementation returns NaN.
2107+
// Assembly implementations might not,
2108+
// because Pi/2 is not exactly representable.
2109+
if runtime.GOARCH != "386" {
2110+
if f := Tan(Pi / 2); !alike(f, NaN()) {
2111+
t.Errorf("Tan(%g) = %g, want %g\n", Pi/2, f, NaN())
2112+
}
2113+
}
21032114
}
21042115

21052116
func TestTanh(t *testing.T) {

src/pkg/math/tan.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func Tan(x float64) float64 {
5454

5555
if flag {
5656
if temp == 0 {
57-
panic(NaN())
57+
return NaN()
5858
}
5959
temp = 1 / temp
6060
}

0 commit comments

Comments
 (0)