question: public static double vectorDistance ( double [ ] vec1 , double [ ] vec2 , double power , double oneOverPower ) { double result = 0 ; if ( power == 0 ) { for ( int i = 0 ; i < vec1 . length ; i ++ ) { result += vec1 [ i ] - vec2 [ i ] == 0 ? 0 : 1 ; } } else if ( power == 1.0 ) { for ( int i = 0 ; i < vec1 . length ; i ++ ) { result += Math . abs ( vec1 [ i ] - vec2 [ i ] ) ; } } else if ( power == 2.0 ) { result = Math . sqrt ( distSquaredCartesian ( vec1 , vec2 ) ) ; } else if ( power == Integer . MAX_VALUE || Double . isInfinite ( power ) ) { for ( int i = 0 ; i < vec1 . length ; i ++ ) { result = Math . max ( result , Math . max ( vec1 [ i ] , vec2 [ i ] ) ) ; } } else { for ( int i = 0 ; i < vec1 . length ; i ++ ) { result += Math . pow ( vec1 [ i ] - vec2 [ i ] , power ) ; } result = Math . pow ( result , oneOverPower ) ; } return result ; }
target:  Calculate the p-norm (i.e. length) between two vectors.