isWithinTolerance method

bool isWithinTolerance(
  1. BigInt target,
  2. BigInt tolerance
)

Checks if this BigInt is within a fixed tolerance of the target value.

Formula: (this - target).abs() <= tolerance. Assumes tolerance is a non-negative BigInt.

Implementation

bool isWithinTolerance(BigInt target, BigInt tolerance) {
  assert(!tolerance.isNegative, 'Tolerance cannot be negative');
  return (this - target).abs() <= tolerance;
}