public static double computeTauAndDivide ( final int j , final int numRows , final double [ ] u , final double max ) { double tau = 0 ; // double div_max = 1.0/max; // if( Double.isInfinite(div_max)) { for ( int i = j ; i < numRows ; i ++ ) { double d = u [ i ] /= max ; tau += d * d ; } // } else { // for( int i = j; i < numRows; i++ ) { // double d = u[i] *= div_max; // tau += d*d; // } // } tau = Math . sqrt ( tau ) ; if ( u [ j ] < 0 ) tau = - tau ; return tau ; }
Normalizes elements in u by dividing by max and computes the norm2 of the normalized array u . Adjust the sign of the returned value depending on the size of the first element in u . Normalization is done to avoid overflow .