mirror of
https://github.com/golang/go
synced 2024-11-25 16:57:58 -07:00
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
This commit is contained in:
parent
a4514c42dd
commit
6e6fc67425
@ -7,6 +7,7 @@ package math_test
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
. "math"
|
. "math"
|
||||||
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -2100,6 +2101,16 @@ func TestTan(t *testing.T) {
|
|||||||
t.Errorf("Tan(%g) = %g, want %g\n", vfsinSC[i], f, sinSC[i])
|
t.Errorf("Tan(%g) = %g, want %g\n", vfsinSC[i], f, sinSC[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make sure portable Tan(Pi/2) doesn't panic (it used to).
|
||||||
|
// The portable implementation returns NaN.
|
||||||
|
// Assembly implementations might not,
|
||||||
|
// because Pi/2 is not exactly representable.
|
||||||
|
if runtime.GOARCH != "386" {
|
||||||
|
if f := Tan(Pi / 2); !alike(f, NaN()) {
|
||||||
|
t.Errorf("Tan(%g) = %g, want %g\n", Pi/2, f, NaN())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTanh(t *testing.T) {
|
func TestTanh(t *testing.T) {
|
||||||
|
@ -54,7 +54,7 @@ func Tan(x float64) float64 {
|
|||||||
|
|
||||||
if flag {
|
if flag {
|
||||||
if temp == 0 {
|
if temp == 0 {
|
||||||
panic(NaN())
|
return NaN()
|
||||||
}
|
}
|
||||||
temp = 1 / temp
|
temp = 1 / temp
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user