private static double euclideanNorm(double vector[]){
  int n=vector.length;
  if (n < 1) {
    return 0;
  }
  if (n == 1) {
    return Math.abs(vector[0]);
  }
  double scale=0;
  double sum=1;
  for (int i=0; i < n; i++) {
    if (vector[i] != 0) {
      double abs=Math.abs(vector[i]);
      if (scale < abs) {
        double t=scale / abs;
        sum=1 + sum * (t * t);
        scale=abs;
      }
 else {
        double t=abs / scale;
        sum+=t * t;
      }
    }
  }
  return scale * Math.sqrt(sum);
}

private static double euclideanNorm ( double vector [ ] ) { int n = vector . length ; if ( n < 1 ) { return 0 ; } if ( n == 1 ) { return Math . abs ( vector [ 0 ] ) ; } double scale = 0 ; double sum = 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( vector [ i ] != 0 ) { double abs = Math . abs ( vector [ i ] ) ; if ( scale < abs ) { double t = scale / abs ; sum = 1 + sum * ( t * t ) ; scale = abs ; } else { double t = abs / scale ; sum += t * t ; } } } return scale * Math . sqrt ( sum ) ; }
returns the euclidean norm of a vector
