   }
            B[i+1] -= B[j]*r;
        }

    // calculate xs
    X[n-1] = B[n-1] / underflow_padded(A[n-1][n-1]);
    for (var i = n-2; i >= 0; --i){
        var s = 0.0;
        for (var j = i; j < n; ++j){
            s = s + A[i][j]*X[j];
        }
        X[i] = (B[i] - s) / underflow_padded(A[i][i]);
    }
    return X;
}

// solver than returns 0, 0 if there is no solution
function solved_linear2_or_zero(A, B) {
    var d = (A[0][0]*A[1][1] - A[0][1]*A[1][0])
    if(d == 0.0)
        return [0.0,