X-Git-Url: https://jasonwoof.com/gitweb/?p=vor.git;a=blobdiff_plain;f=float.h;h=1f07d6c2b8b2df541ee2f26727d76f4d53fecf5f;hp=55d3e30b23b3cf98e6c9cf791a9073fa50e713cc;hb=10a2a28fa10959beda62e518887bc34466f02148;hpb=a072e528186c4c8c8ff6ead5b1d852178a1419fc diff --git a/float.h b/float.h index 55d3e30..1f07d6c 100644 --- a/float.h +++ b/float.h @@ -12,6 +12,37 @@ fclip(float f, float max) return f < SMIDGE || f >= (max - SMIDGE); } +static inline float +fconstrain(float f, float max) +{ + max -= SMIDGE; + + if(f > max) { + return max; + } + if(f < SMIDGE) { + return SMIDGE; + } + + return f; +} + +static inline float +fconstrain2(float f, float min, float max) +{ + min += SMIDGE; + max -= SMIDGE; + + if(f > max) { + return max; + } + if(f < min) { + return min; + } + + return f; +} + // wrap f so it's within the range [SMIDGE..(max-SMIDGE)] // assumes f is not outside this range by more than (max - (2 * SMIDGE)) static inline float @@ -30,5 +61,4 @@ fwrap(float f, float max) return f; } - #endif // VOR_FLOAT_H