Restrict x to the range low, high.
low, high
static double clamp(double x, double low, double high) => x < low ? low : (x > high ? high : x);