dEq static method

bool dEq(
  1. double a,
  2. double b,
  3. double epsilon
)

Returns true if two doubles are considered equal based on a tolerance of {@value #D_TOLERANCE}.

Note that two {@link Double#NaN} are seen as equal and return true.

@param a double to compare. @param b double to compare. @return true if two doubles are considered equal.

Implementation

static bool dEq(double a, double b, double epsilon) {
  if (a.isNaN && b.isNaN) {
    return true;
  }
  var diffAbs = (a - b).abs();
  return a == b
      ? true
      : diffAbs < epsilon
          ? true
          : diffAbs / math.max(a.abs(), b.abs()) < epsilon;
}