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
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.