]> Cypherpunks repositories - gostls13.git/commitdiff
math: make portable Tan(Pi/2) return NaN
authorRuss Cox <rsc@golang.org>
Sun, 12 Sep 2010 03:41:25 +0000 (23:41 -0400)
committerRuss Cox <rsc@golang.org>
Sun, 12 Sep 2010 03:41:25 +0000 (23:41 -0400)
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

src/pkg/math/all_test.go
src/pkg/math/tan.go

index 10f1e2435f298d93cd24469d00a21bf3bd3f589a..54c0cfa9258163f3a9080901e77360106667db4f 100644 (file)
@@ -7,6 +7,7 @@ package math_test
 import (
        "fmt"
        . "math"
+       "runtime"
        "testing"
 )
 
@@ -2100,6 +2101,16 @@ func TestTan(t *testing.T) {
                        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) {
index 842ac643861643c0fb1a9209470343f8b89c39ee..a36ebbf449c76ae0303dd06de359d5689054cc93 100644 (file)
@@ -54,7 +54,7 @@ func Tan(x float64) float64 {
 
        if flag {
                if temp == 0 {
-                       panic(NaN())
+                       return NaN()
                }
                temp = 1 / temp
        }