clamp method

Rational clamp(
  1. Rational lowerLimit,
  2. Rational upperLimit
)

Clamps the rational to be in the range lowerLimit-upperLimit. The comparison is done using compareTo and therefore takes -0.0 into account.

Implementation

Rational clamp(Rational lowerLimit, Rational upperLimit) =>
    this < lowerLimit ? lowerLimit : this > upperLimit ? upperLimit : this;