nearEqual function Null safety

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

Whether two doubles are within a given distance of each other.

The epsilon argument must be positive and not null. The a and b arguments may be null. A null value is only considered near-equal to another null value.

Implementation

bool nearEqual(double? a, double? b, double epsilon) {
  assert(epsilon != null);
  assert(epsilon >= 0.0);
  if (a == null || b == null) {
    return a == b;
  }
  return (a > (b - epsilon)) && (a < (b + epsilon)) || a == b;
}