code: private static boolean nearlyEqual(double a, double b, double epsilon)
      {
          final double absA = Math.abs(a);
          final double absB = Math.abs(b);
          final double diff = Math.abs(a - b);
  
          if (a == b)
          { // shortcut, handles infinities
              return true;
          }
          else if (a == 0 || b == 0 || diff < Double.MIN_NORMAL)
          {
              // a or b is zero or both are extremely close to it
              // relative error is less meaningful here
              return diff < (epsilon * Double.MIN_NORMAL);
          }
          else
          { // use relative error
              return diff / (absA + absB) < epsilon;
          }
      }
docs: Correctly handles floating point comparisions. <br>
  source: http://floating-point-gui.de/errors/comparison/
  
  @param a       first number
  @param b       second number
  @param epsilon double tolerance value
  @return true if a and b are close enough