MCPcopy Create free account
hub / github.com/asm-js/validator / GeometricMean

Function GeometricMean

test/valid/GeometricMean-common.js:1–30  ·  view source on GitHub ↗
(stdlib, foreign, buffer)

Source from the content-addressed store, hash-verified

1function GeometricMean(stdlib, foreign, buffer) {
2 "use asm";
3
4 var exp = stdlib.Math.exp;
5 var log = stdlib.Math.log;
6 var values = new stdlib.Float64Array(buffer);
7
8 function logSum(start, end) {
9 start = start|0;
10 end = end|0;
11
12 var sum = 0.0, p = 0, q = 0;
13
14 // asm.js forces byte addressing of the heap by requiring shifting by 3
15 for (p = start << 3, q = end << 3; (p|0) < (q|0); p = (p + 8)|0) {
16 sum = sum + +log(values[p>>3]);
17 }
18
19 return +sum;
20 }
21
22 function geometricMean(start, end) {
23 start = start|0;
24 end = end|0;
25
26 return +exp(+logSum(start, end) / +((end - start)|0));
27 }
28
29 return { geometricMean: geometricMean };
30}
31
32module.exports = GeometricMean;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected