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