withinRounding method

bool withinRounding(
  1. FloatingPointValue other
)

Return true if the other FloatingPointValue is within a rounding error of this value.

Implementation

bool withinRounding(FloatingPointValue other) {
  if (isNaN || other.isNaN) {
    return false;
  }
  if (isAnInfinity || other.isAnInfinity) {
    return this == other;
  }
  if (this != other) {
    final diff = (abs() - other.abs()).abs();
    if (diff.compareTo(ulp()) == 1) {
      return false;
    }
  }
  return true;
}