1 // Copyright 2018 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
12 // Inputs to test trig_reduce
13 var trigHuge = []float64{
21 1234567891234567 << 180,
22 1234567891234567 << 300,
26 // Results for trigHuge[i] calculated with https://github.com/robpike/ivy
27 // using 4096 bits of working precision. Values requiring less than
28 // 102 decimal digits (1 << 120, 1 << 240, 1 << 480, 1234567891234567 << 180)
29 // were confirmed via https://keisan.casio.com/
30 var cosHuge = []float64{
43 var sinHuge = []float64{
56 var tanHuge = []float64{
69 // Check that trig values of huge angles return accurate results.
70 // This confirms that argument reduction works for very large values
72 func TestHugeCos(t *testing.T) {
73 for i := 0; i < len(trigHuge); i++ {
75 f2 := Cos(trigHuge[i])
77 t.Errorf("Cos(%g) = %g, want %g", trigHuge[i], f2, f1)
79 f3 := Cos(-trigHuge[i])
81 t.Errorf("Cos(%g) = %g, want %g", -trigHuge[i], f3, f1)
86 func TestHugeSin(t *testing.T) {
87 for i := 0; i < len(trigHuge); i++ {
89 f2 := Sin(trigHuge[i])
91 t.Errorf("Sin(%g) = %g, want %g", trigHuge[i], f2, f1)
93 f3 := Sin(-trigHuge[i])
95 t.Errorf("Sin(%g) = %g, want %g", -trigHuge[i], f3, -f1)
100 func TestHugeSinCos(t *testing.T) {
101 for i := 0; i < len(trigHuge); i++ {
102 f1, g1 := sinHuge[i], cosHuge[i]
103 f2, g2 := Sincos(trigHuge[i])
104 if !close(f1, f2) || !close(g1, g2) {
105 t.Errorf("Sincos(%g) = %g, %g, want %g, %g", trigHuge[i], f2, g2, f1, g1)
107 f3, g3 := Sincos(-trigHuge[i])
108 if !close(-f1, f3) || !close(g1, g3) {
109 t.Errorf("Sincos(%g) = %g, %g, want %g, %g", -trigHuge[i], f3, g3, -f1, g1)
114 func TestHugeTan(t *testing.T) {
115 for i := 0; i < len(trigHuge); i++ {
117 f2 := Tan(trigHuge[i])
119 t.Errorf("Tan(%g) = %g, want %g", trigHuge[i], f2, f1)
121 f3 := Tan(-trigHuge[i])
123 t.Errorf("Tan(%g) = %g, want %g", -trigHuge[i], f3, -f1)