clampDouble function Null safety

double clampDouble(
  1. double x,
  2. double min,
  3. double max
)

Same as num.clamp but optimized for non-null double.

This is faster because it avoids polymorphism, boxing, and special cases for floating point numbers.

Implementation

//
// See also: //dev/benchmarks/microbenchmarks/lib/foundation/clamp.dart
double clampDouble(double x, double min, double max) {
  assert(min <= max && !max.isNaN && !min.isNaN);
  if (x < min) {
    return min;
  }
  if (x > max) {
    return max;
  }
  if (x.isNaN) {
    return max;
  }
  return x;
}