From 9b335433396088d2701e8a058ae107689404ec6a Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Fri, 14 Jul 2023 08:34:39 -0700 Subject: [PATCH] math: test large negative values as args for trig functions Sin/Tan are odd, Cos is even, so it is easy to compute the correct result from the positive argument case. Change-Id: If851d00fc7f515ece8199cf56d21186ced51e94f Reviewed-on: https://go-review.googlesource.com/c/go/+/509815 Run-TryBot: Keith Randall TryBot-Result: Gopher Robot Reviewed-by: Srinivas Pokala Reviewed-by: Robert Griesemer Reviewed-by: Keith Randall --- src/math/huge_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/math/huge_test.go b/src/math/huge_test.go index bc28c6ff69..568b0c85eb 100644 --- a/src/math/huge_test.go +++ b/src/math/huge_test.go @@ -81,6 +81,10 @@ func TestHugeCos(t *testing.T) { if !close(f1, f2) { t.Errorf("Cos(%g) = %g, want %g", trigHuge[i], f2, f1) } + f3 := Cos(-trigHuge[i]) + if !close(f1, f3) { + t.Errorf("Cos(%g) = %g, want %g", -trigHuge[i], f3, f1) + } } } @@ -91,6 +95,10 @@ func TestHugeSin(t *testing.T) { if !close(f1, f2) { t.Errorf("Sin(%g) = %g, want %g", trigHuge[i], f2, f1) } + f3 := Sin(-trigHuge[i]) + if !close(-f1, f3) { + t.Errorf("Sin(%g) = %g, want %g", -trigHuge[i], f3, -f1) + } } } @@ -101,6 +109,10 @@ func TestHugeSinCos(t *testing.T) { if !close(f1, f2) || !close(g1, g2) { t.Errorf("Sincos(%g) = %g, %g, want %g, %g", trigHuge[i], f2, g2, f1, g1) } + f3, g3 := Sincos(-trigHuge[i]) + if !close(-f1, f3) || !close(g1, g3) { + t.Errorf("Sincos(%g) = %g, %g, want %g, %g", -trigHuge[i], f3, g3, -f1, g1) + } } } @@ -111,5 +123,9 @@ func TestHugeTan(t *testing.T) { if !close(f1, f2) { t.Errorf("Tan(%g) = %g, want %g", trigHuge[i], f2, f1) } + f3 := Tan(-trigHuge[i]) + if !close(-f1, f3) { + t.Errorf("Tan(%g) = %g, want %g", -trigHuge[i], f3, -f1) + } } }