Sha256: fbf35a551f5b7d84de15f91353696aefd9472ca73fd1ba2261c762e42028488f

Contents?: true

Size: 697 Bytes

Versions: 5

Compression:

Stored size: 697 Bytes

Contents

function partial(n){
    var a1 = a2 = a3 = a4 = a5 = a6 = a7 = a8 = a9 = 0.0;
    var twothirds = 2.0/3.0;
    var alt = -1.0;
    var k2 = k3 = sk = ck = 0.0;
    
    for (var k = 1; k <= n; k++){
        k2 = k*k;
        k3 = k2*k;
        sk = Math.sin(k);
        ck = Math.cos(k);
        alt = -alt;
        
        a1 += Math.pow(twothirds,k-1);
        a2 += Math.pow(k,-0.5);
        a3 += 1.0/(k*(k+1.0));
        a4 += 1.0/(k3 * sk*sk);
        a5 += 1.0/(k3 * ck*ck);
        a6 += 1.0/k;
        a7 += 1.0/k2;
        a8 += alt/k;
        a9 += alt/(2*k -1);
    }
}

var start = Date.now();
for (var i = 1024; i <= 16384; i *= 2) {
    partial(i);
}
print(Date.now() - start);


Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
johnson-2.0.0.pre0 vendor/tracemonkey/math-partial-sums.js
smparkes-johnson-1.1.2.6 vendor/tracemonkey/math-partial-sums.js
smparkes-johnson-1.1.2.5 vendor/tracemonkey/math-partial-sums.js
smparkes-johnson-1.1.2.4 vendor/tracemonkey/math-partial-sums.js
smparkes-johnson-1.1.2.3 vendor/tracemonkey/math-partial-sums.js