/**
   A class for useful numeric methods.
*/

public class Numeric
{  /**
      Tests whether two floating-point numbers are
      equal, except for a roundoff error
      @param x a floating-point number
      @param y a floating-point number
      @return true if x and y are approximately equal
   */
   public static boolean approxEqual(double x, double y)
   {  
      final double EPSILON = 1E-14;
      if (x == 0) return Math.abs(y) <= EPSILON;
      if (y == 0) return Math.abs(x) <= EPSILON;
      return Math.abs(x - y) / Math.max(Math.abs(x), Math.abs(y))
         <= EPSILON;
   }
   // more numeric methods can be added here
}
