almostEqualNormD function

bool almostEqualNormD (double a, double b, double diff, double maximumAbsoluteError)

Compares two doubles and determines if they are equal within the specified maximum absolute error.

Implementation

bool almostEqualNormD(
    double a, double b, double diff, double maximumAbsoluteError) {
  // If A or B are infinity (positive or negative) then
  // only return true if they are exactly equal to each other -
  // that is, if they are both infinities of the same sign.
  if (a.isInfinite || b.isInfinite) {
    return a == b;
  }

  // If A or B are a NAN, return false. NANs are equal to nothing,
  // not even themselves.
  if (a.isNaN || b.isNaN) {
    return false;
  }

  return diff.abs() < maximumAbsoluteError;
}