# spectral-norm Node js #3 program

## source code

```// The Computer Language Benchmarks Game
// https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
//
// contributed by Ian Osgood
// Optimized by Roy Williams
// modified for Node.js by Isaac Gouy

function A(i,j) {
return 1/(((i+j)*(i+j+1)>>>1)+i+1);
}

function Au(u,v) {
var n = u.length;
for (var i=0; i<n; ++i) {
var t = 0;
for (var j=0; j<n; ++j)
t += A(i,j) * u[j];
v[i] = t;
}
}

function Atu(u,v) {
var n = u.length;
for (var i=0; i<n; ++i) {
var t = 0;
for (var j=0; j<n; ++j)
t += A(j,i) * u[j];
v[i] = t;
}
}

function AtAu(u,v,w) {
Au(u,w);
Atu(w,v);
}

function spectralnorm(n) {
var storage_ = new ArrayBuffer(n * 24);
var u = new Float64Array(storage_, 0, n),
v = new Float64Array(storage_, 8*n, n),
w = new Float64Array(storage_, 16*n, n);
var i, vv=0, vBv=0;
for (i=0; i<n; ++i) {
u[i] = 1; v[i] = w[i] = 0;
}
for (i=0; i<10; ++i) {
AtAu(u,v,w);
AtAu(v,u,w);
}
for (i=0; i<n; ++i) {
vBv += u[i]*v[i];
vv  += v[i]*v[i];
}
return Math.sqrt(vBv/vv);
}

console.log(spectralnorm(+process.argv[2]).toFixed(9));
```

## notes, command-line, and program output

```NOTES:
v12.7.0

Mon, 05 Aug 2019 18:01:14 GMT

MAKE:
cp -L spectralnorm.node-3.node spectralnorm.node-3.js

0.11s to complete and log all make actions

COMMAND LINE:
/opt/src/node-v12.7.0-linux-x64/bin/node spectralnorm.node-3.js 5500

PROGRAM OUTPUT:
1.274224153
```