github.com/twelsh-aw/go/src@v0.0.0-20230516233729-a56fe86a7c81/math/huge_test.go (about) 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. 4 5 // Disabled for s390x because it uses assembly routines that are not 6 // accurate for huge arguments. 7 8 //go:build !s390x 9 10 package math_test 11 12 import ( 13 . "math" 14 "testing" 15 ) 16 17 // Inputs to test trig_reduce 18 var trigHuge = []float64{ 19 1 << 28, 20 1 << 29, 21 1 << 30, 22 1 << 35, 23 1 << 120, 24 1 << 240, 25 1 << 480, 26 1234567891234567 << 180, 27 1234567891234567 << 300, 28 MaxFloat64, 29 } 30 31 // Results for trigHuge[i] calculated with https://github.com/robpike/ivy 32 // using 4096 bits of working precision. Values requiring less than 33 // 102 decimal digits (1 << 120, 1 << 240, 1 << 480, 1234567891234567 << 180) 34 // were confirmed via https://keisan.casio.com/ 35 var cosHuge = []float64{ 36 -0.16556897949057876, 37 -0.94517382606089662, 38 0.78670712294118812, 39 -0.76466301249635305, 40 -0.92587902285483787, 41 0.93601042593353793, 42 -0.28282777640193788, 43 -0.14616431394103619, 44 -0.79456058210671406, 45 -0.99998768942655994, 46 } 47 48 var sinHuge = []float64{ 49 -0.98619821183697566, 50 0.32656766301856334, 51 -0.61732641504604217, 52 -0.64443035102329113, 53 0.37782010936075202, 54 -0.35197227524865778, 55 0.95917070894368716, 56 0.98926032637023618, 57 -0.60718488235646949, 58 0.00496195478918406, 59 } 60 61 var tanHuge = []float64{ 62 5.95641897939639421, 63 -0.34551069233430392, 64 -0.78469661331920043, 65 0.84276385870875983, 66 -0.40806638884180424, 67 -0.37603456702698076, 68 -3.39135965054779932, 69 -6.76813854009065030, 70 0.76417695016604922, 71 -0.00496201587444489, 72 } 73 74 // Check that trig values of huge angles return accurate results. 75 // This confirms that argument reduction works for very large values 76 // up to MaxFloat64. 77 func TestHugeCos(t *testing.T) { 78 for i := 0; i < len(trigHuge); i++ { 79 f1 := cosHuge[i] 80 f2 := Cos(trigHuge[i]) 81 if !close(f1, f2) { 82 t.Errorf("Cos(%g) = %g, want %g", trigHuge[i], f2, f1) 83 } 84 } 85 } 86 87 func TestHugeSin(t *testing.T) { 88 for i := 0; i < len(trigHuge); i++ { 89 f1 := sinHuge[i] 90 f2 := Sin(trigHuge[i]) 91 if !close(f1, f2) { 92 t.Errorf("Sin(%g) = %g, want %g", trigHuge[i], f2, f1) 93 } 94 } 95 } 96 97 func TestHugeSinCos(t *testing.T) { 98 for i := 0; i < len(trigHuge); i++ { 99 f1, g1 := sinHuge[i], cosHuge[i] 100 f2, g2 := Sincos(trigHuge[i]) 101 if !close(f1, f2) || !close(g1, g2) { 102 t.Errorf("Sincos(%g) = %g, %g, want %g, %g", trigHuge[i], f2, g2, f1, g1) 103 } 104 } 105 } 106 107 func TestHugeTan(t *testing.T) { 108 for i := 0; i < len(trigHuge); i++ { 109 f1 := tanHuge[i] 110 f2 := Tan(trigHuge[i]) 111 if !close(f1, f2) { 112 t.Errorf("Tan(%g) = %g, want %g", trigHuge[i], f2, f1) 113 } 114 } 115 }