code: public static float clamp (float v, float lower, float upper) {
          if (v < lower) return lower;
          else if (v > upper) return upper;
          else return v;
      }
docs: Clamps a value to the range [lower, upper].