clamp method

double clamp(
  1. double min,
  2. double max
)

Implementation

double clamp(double min, double max) {
  if (this < min) {
    return min;
  } else if (this > max) {
    return max;
  } else {
    return this;
  }
}