public static int compareCanonicalFPNumbers(String float1,String float2){
  if (float1.equals(NaN) || float2.equals(NaN)) {
    if (float1.equals(float2)) {
      return 0;
    }
 else {
      throwIAE("NaN cannot be compared to other floats");
    }
  }
  if (float1.equals(POSITIVE_INFINITY)) {
    return (float2.equals(POSITIVE_INFINITY)) ? 0 : 1;
  }
 else   if (float2.equals(POSITIVE_INFINITY)) {
    return -1;
  }
  if (float1.equals(NEGATIVE_INFINITY)) {
    return (float2.equals(NEGATIVE_INFINITY)) ? 0 : -1;
  }
 else   if (float2.equals(NEGATIVE_INFINITY)) {
    return 1;
  }
  if (float1.charAt(0) == '-' && float2.charAt(0) != '-') {
    return -1;
  }
  if (float2.charAt(0) == '-' && float1.charAt(0) != '-') {
    return 1;
  }
  int eIdx1=float1.indexOf('E');
  String mantissa1=float1.substring(0,eIdx1);
  String exponent1=float1.substring(eIdx1 + 1);
  int eIdx2=float2.indexOf('E');
  String mantissa2=float2.substring(0,eIdx2);
  String exponent2=float2.substring(eIdx2 + 1);
  int result=compareCanonicalIntegers(exponent1,exponent2);
  if (result != 0 && float1.charAt(0) == '-') {
    result=-result;
  }
  if (result == 0) {
    result=compareCanonicalDecimals(mantissa1,mantissa2);
  }
  return result;
}

public static int compareCanonicalFPNumbers ( String float1 , String float2 ) { if ( float1 . equals ( NaN ) || float2 . equals ( NaN ) ) { if ( float1 . equals ( float2 ) ) { return 0 ; } else { throwIAE ( "NaN cannot be compared to other floats" ) ; } } if ( float1 . equals ( POSITIVE_INFINITY ) ) { return ( float2 . equals ( POSITIVE_INFINITY ) ) ? 0 : 1 ; } else if ( float2 . equals ( POSITIVE_INFINITY ) ) { return - 1 ; } if ( float1 . equals ( NEGATIVE_INFINITY ) ) { return ( float2 . equals ( NEGATIVE_INFINITY ) ) ? 0 : - 1 ; } else if ( float2 . equals ( NEGATIVE_INFINITY ) ) { return 1 ; } if ( float1 . charAt ( 0 ) == '-' && float2 . charAt ( 0 ) != '-' ) { return - 1 ; } if ( float2 . charAt ( 0 ) == '-' && float1 . charAt ( 0 ) != '-' ) { return 1 ; } int eIdx1 = float1 . indexOf ( 'E' ) ; String mantissa1 = float1 . substring ( 0 , eIdx1 ) ; String exponent1 = float1 . substring ( eIdx1 + 1 ) ; int eIdx2 = float2 . indexOf ( 'E' ) ; String mantissa2 = float2 . substring ( 0 , eIdx2 ) ; String exponent2 = float2 . substring ( eIdx2 + 1 ) ; int result = compareCanonicalIntegers ( exponent1 , exponent2 ) ; if ( result != 0 && float1 . charAt ( 0 ) == '-' ) { result = - result ; } if ( result == 0 ) { result = compareCanonicalDecimals ( mantissa1 , mantissa2 ) ; } return result ; }
compares two canonical floating point numbers to eachother .
