public static boolean same(double d1,double d2){
  if (Double.isNaN(d1)) {
    return Double.isNaN(d2);
  }
  if (d1 == d2)   return true;
  if (Double.isInfinite(d1)) {
    return false;
  }
  return value(d1 - d2) == 0;
}

public static boolean same ( double d1 , double d2 ) { if ( Double . isNaN ( d1 ) ) { return Double . isNaN ( d2 ) ; } if ( d1 == d2 ) return true ; if ( Double . isInfinite ( d1 ) ) { return false ; } return value ( d1 - d2 ) == 0 ; }
when value won ' t work , because numbers are potentially infinite , then use this one . < p > standard means for comparing double when dealing with the special quantities , nan and infinite numbers . also properly ensures that numbers " close to zero " ( within an epsilon ) are to be treated as zero for this computation .
