    r = A[i+1][j] / underflow_padded(A[j][j]);
            A[i+1][j] = 0.;
            for (var b_j = j+1; b_j < n; ++b_j){
                A[i+1][b_j] -= A[j][b_j]*r;
            }
            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;
}

