math-fdlibm-sincostan.js (3875B)
1 let g = newGlobal({alwaysUseFdlibm: true}); 2 3 // Adapted from https://github.com/arkenfox/TZP/blob/master/tests/math.html 4 // Tests all values that differed from libm for me on Linux and Windows. 5 6 function test() { 7 for (var i = 0; i < 100; i++) { 8 assertEq(g.Math.cos(1e130 ), -0.767224894221913); 9 assertEq(g.Math.cos(1e272 ), -0.7415825695514536); 10 assertEq(g.Math.cos(1e284 ), 0.7086865671674247); 11 assertEq(g.Math.cos(1e75 ), -0.7482651726250321); 12 assertEq(g.Math.cos(57*Math.E ), -0.536911695749024); 13 assertEq(g.Math.cos(21*Math.LN2 ), -0.4067775970251724); 14 assertEq(g.Math.cos(51*Math.LN2 ), -0.7017203400855446); 15 assertEq(g.Math.cos(21*Math.SQRT1_2), -0.6534063185820198); 16 assertEq(g.Math.cos(17*Math.LOG10E ), 0.4537557425982784); 17 assertEq(g.Math.cos(2*Math.LOG10E ), 0.6459044007438142); 18 19 assertEq(g.Math.sin(35*Math.LN2 ), -0.765996413898051); 20 assertEq(g.Math.sin(110*Math.LOG2E ), 0.9989410140273757); 21 assertEq(g.Math.sin(7*Math.LOG10E ), 0.10135692924965616); 22 23 assertEq(g.Math.tan(1e140 ), 0.7879079967710036); 24 assertEq(g.Math.tan(6*Math.E ), 0.6866761546452431); 25 assertEq(g.Math.tan(6*Math.LN2 ), 1.6182817135715877); 26 assertEq(g.Math.tan(10*Math.LOG2E ), -3.3537128705376014); 27 assertEq(g.Math.tan(17*Math.SQRT2 ), -1.9222955461799982); 28 assertEq(g.Math.tan(34*Math.SQRT1_2), -1.9222955461799982); 29 assertEq(g.Math.tan(10*Math.LOG10E ), 2.5824856130712432); 30 } 31 } 32 33 /* 34 cos 35 3: 1e130 : -0.767224894221913 , 36 4: 1e272 : -0.7415825695514536, 37 6: 1e284 : 0.7086865671674247, 38 7: 1e75 : -0.7482651726250321, 39 13: 57*Math.E : -0.536911695749024, 40 14: 21*Math.LN2 : -0.4067775970251724, 41 15: 51*Math.LN2 : -0.7017203400855446, 42 19: 21*Math.SQRT1_2 : -0.6534063185820198, 43 20: 17*Math.LOG10E : 0.4537557425982784, 44 21: 2*Math.LOG10E : 0.6459044007438142, 45 46 47 sin 48 11: : -0.765996413898051, 49 12: : 0.9989410140273757, 50 13: : 0.10135692924965616, 51 52 tan 53 1: 1e140 : 0.7879079967710036, 54 10: 6*Math.E : 0.6866761546452431, 55 11: 6*Math.LN2 : 1.6182817135715877, 56 12: 10*Math.LOG2E : -3.3537128705376014, 57 13: 17*Math.SQRT2 : -1.9222955461799982, 58 14: 34*Math.SQRT1_2 : -1.9222955461799982, 59 15: 10*Math.LOG10E : 2.5824856130712432, 60 */ 61 62 test(); 63 64 // Test if the test is still useful, or if all results match without 65 // fingerprinting resistance as well. 66 if (!getBuildConfiguration("android") && 67 Math.cos(1e130 ) == -0.767224894221913 && 68 Math.cos(1e272 ) == -0.7415825695514536 && 69 Math.cos(1e284 ) == 0.7086865671674247 && 70 Math.cos(1e75 ) == -0.7482651726250321 && 71 Math.cos(57*Math.E ) == -0.536911695749024 && 72 Math.cos(21*Math.LN2 ) == -0.4067775970251724 && 73 Math.cos(51*Math.LN2 ) == -0.7017203400855446 && 74 Math.cos(21*Math.SQRT1_2) == -0.6534063185820198 && 75 Math.cos(17*Math.LOG10E ) == 0.4537557425982784 && 76 Math.cos(2*Math.LOG10E ) == 0.6459044007438142 && 77 Math.sin(35*Math.LN2 ) == -0.765996413898051 && 78 Math.sin(110*Math.LOG2E ) == 0.9989410140273757 && 79 Math.sin(7*Math.LOG10E ) == 0.10135692924965616 && 80 Math.tan(1e140 ) == 0.7879079967710036 && 81 Math.tan(6*Math.E ) == 0.6866761546452431 && 82 Math.tan(6*Math.LN2 ) == 1.6182817135715877 && 83 Math.tan(10*Math.LOG2E ) == -3.3537128705376014 && 84 Math.tan(17*Math.SQRT2 ) == -1.9222955461799982 && 85 Math.tan(34*Math.SQRT1_2) == -1.9222955461799982 && 86 Math.tan(10*Math.LOG10E ) == 2.5824856130712432) { 87 assertEq(false, true); 88 }