blob: ef144a85dbaf9bc7a8657794fbc72bfbf676afb5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
var x = 0;
function test() {
function sincos1(a, b) {
var sa = Math.sin(a);
var sb = Math.sin(b);
var ca = Math.cos(a);
var cb = Math.cos(b);
var ra = sa * sa + ca * ca;
var rb = sb * sb + cb * cb;
var dec = 100000;
assertEq(Math.round(ra * dec) / dec, Math.round(rb * dec) / dec);
ca = Math.cos(a);
cb = Math.cos(b);
sa = Math.sin(a);
sb = Math.sin(b);
var ra = sa * sa + ca * ca;
var rb = sb * sb + cb * cb;
assertEq(Math.round(ra * dec) / dec, Math.round(rb * dec) / dec);
return ra;
}
function sincos2(x) {
var s1 = Math.sin(x);
var c1 = Math.cos(x);
var c2 = Math.cos(x);
var s2 = Math.sin(x);
return (s1 * s1 + c1 * c1) - (s2 * s2 + c2 * c2);
}
function bailoutHere() { bailout(); }
function sincos3(x) {
var s = Math.sin(x);
bailoutHere();
var c = Math.cos(x);
assertEq(Math.round(s * s + c * c), 1);
return s;
}
function sincos4(x) {
if (x < 2500)
x = Math.sin(x);
else
x = Math.cos(x);
return x;
}
for (var i=0; i<5000; i++) {
x += sincos1(x, x + 1);
x += sincos2(x);
x += sincos3(x);
x += sincos4(i);
}
}
x += 1;
test();
|