MIN, MAX and CLAMP in FastMath

It would be nice to have the functions min, max and clamp in the FastMath class. These are fairly common functions and FastMath is the most convenient place to put them.



   public static float min(float a, float b) {
      if (a < b) return a;
      return b;
   }
   
   public static float max(float a, float b) {
      if (a > b) return a;
      return b;
   }
   
   public static float clamp(float val, float min, float max) {
      if (val > max) return max;
      if (val < min) return min;
      return val;
   }

At least min and max are in java.lang.Math already (and you can do a clamp with those requiring only a couple of characters more ;))

FastMath already contains a 1-line-clamp:

    public static float clamp(float input, float min, float max) {
        return (input < min) ? min : (input > max) ? max : input;
    }

At least min and max are in java.lang.Math already

Yes, but those do a couple of extra checks: one for NAN and another for positive and negative zero. It is debatable if those checks are really necessary in the game.

FastMath already contains a 1-line-clam

I've missed that one... mainly because i was looking for min and max. Notice that this function does not perform any extra checks.

That's because its in FastMath :smiley: extra checks are for little girls and boys.

It is about a magnitude faster than nesting Math.min() and Math.max().