summaryrefslogtreecommitdiff
path: root/src/pkg/math
diff options
context:
space:
mode:
authorKen Thompson <ken@golang.org>2009-11-24 15:42:46 -0800
committerKen Thompson <ken@golang.org>2009-11-24 15:42:46 -0800
commit19a66dc4c7887adb80a0ca37ae8f80cd705a3c91 (patch)
treee4eb221ba7bb4e8699353cb0d494c9d678187a4e /src/pkg/math
parentdf004024b2e8c65415390f784886ae732d730ad9 (diff)
downloadgolang-19a66dc4c7887adb80a0ca37ae8f80cd705a3c91.tar.gz
test case for large angles in trig functions
R=rsc http://codereview.appspot.com/157160
Diffstat (limited to 'src/pkg/math')
-rw-r--r--src/pkg/math/all_test.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/pkg/math/all_test.go b/src/pkg/math/all_test.go
index 099922837..60ce6de24 100644
--- a/src/pkg/math/all_test.go
+++ b/src/pkg/math/all_test.go
@@ -169,6 +169,7 @@ func tolerance(a, b, e float64) bool {
}
return d < e;
}
+func kindaclose(a, b float64) bool { return tolerance(a, b, 1e-8) }
func close(a, b float64) bool { return tolerance(a, b, 1e-14) }
func veryclose(a, b float64) bool { return tolerance(a, b, 4e-16) }
@@ -274,6 +275,42 @@ func TestHypot(t *testing.T) {
}
}
+// Check that math functions of high angle values
+// return similar results to low angle values
+func TestLargeSin(t *testing.T) {
+ large := float64(100000 * Pi);
+ for i := 0; i < len(vf); i++ {
+ f1 := Sin(vf[i]);
+ f2 := Sin(vf[i] + large);
+ if !kindaclose(f1, f2) {
+ t.Errorf("Sin(%g) = %g, want %g\n", vf[i]+large, f1, f2)
+ }
+ }
+}
+
+func TestLargeCos(t *testing.T) {
+ large := float64(100000 * Pi);
+ for i := 0; i < len(vf); i++ {
+ f1 := Cos(vf[i]);
+ f2 := Cos(vf[i] + large);
+ if !kindaclose(f1, f2) {
+ t.Errorf("Cos(%g) = %g, want %g\n", vf[i]+large, f1, f2)
+ }
+ }
+}
+
+
+func TestLargeTan(t *testing.T) {
+ large := float64(100000 * Pi);
+ for i := 0; i < len(vf); i++ {
+ f1 := Tan(vf[i]);
+ f2 := Tan(vf[i] + large);
+ if !kindaclose(f1, f2) {
+ t.Errorf("Tan(%g) = %g, want %g\n", vf[i]+large, f1, f2)
+ }
+ }
+}
+
// Check that math constants are accepted by compiler
// and have right value (assumes strconv.Atof works).
// http://code.google.com/p/go/issues/detail?id=201