1 // The Computer Language Shootout
2 // http://shootout.alioth.debian.org/
3 // contributed by Isaac Gouy
6 var a1 = a2 = a3 = a4 = a5 = a6 = a7 = a8 = a9 = 0.0;
7 var twothirds = 2.0/3.0;
9 var k2 = k3 = sk = ck = 0.0;
11 for (var k = 1; k <= n; k++){
18 a1 += Math.pow(twothirds,k-1);
19 a2 += Math.pow(k,-0.5);
20 a3 += 1.0/(k*(k+1.0));
21 a4 += 1.0/(k3 * sk*sk);
22 a5 += 1.0/(k3 * ck*ck);
29 // NOTE: We don't try to validate anything from pow(), sin() or cos() because those aren't
30 // well-specified in ECMAScript.
31 return a6 + a7 + a8 + a9;
36 for (var i = 1024; i <= 2097152; i *= 2) {
40 var expected = 173.3312765300306;
42 if (total != expected) {
43 throw "ERROR: bad result: expected " + expected + " but got " + total;