contains method

bool contains(
  1. Q quantity, [
  2. bool inclusive = true,
  3. double epsilon = 1.0e-10
])

True if this range contains quantity, with a tolerance, epsilon, of rounding errors of 1.0e-10 and inclusive of the endpoints by default.

Implementation

bool contains(Q quantity, [bool inclusive = true, double epsilon = 1.0e-10]) {
  if (inclusive && (quantity == q1 || quantity == q2)) return true;
  if (epsilon == 0.0) {
    if (q1 < quantity && q2 > quantity) return true;
    if (q1 > quantity && q2 < quantity) return true;
  } else {
    if (inclusive) {
      if (q1.mks - epsilon < quantity.mks && q2.mks + epsilon > quantity.mks) return true;
      if (q1.mks + epsilon > quantity.mks && q2.mks - epsilon < quantity.mks) return true;
    } else {
      if (q1.mks - epsilon <= quantity.mks && q2.mks + epsilon >= quantity.mks) return true;
      if (q1.mks + epsilon >= quantity.mks && q2.mks - epsilon <= quantity.mks) return true;
    }
  }
  return false;
}