From a072e528186c4c8c8ff6ead5b1d852178a1419fc Mon Sep 17 00:00:00 2001 From: Jason Woofenden Date: Tue, 27 Mar 2007 17:07:51 -0400 Subject: [PATCH] fclip() and fwrap() now shrink range by SMIDGE --- float.h | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/float.h b/float.h index 58f6616..55d3e30 100644 --- a/float.h +++ b/float.h @@ -3,21 +3,32 @@ #include +#define SMIDGE 0.0001 + +// return true if f is OUTSIDE the range [SMIDGE..(max-SMIDGE)] static inline int fclip(float f, float max) { - return f < 0 || (float)f >= (float)max; + return f < SMIDGE || f >= (max - SMIDGE); } +// 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 fwrap(float f, float max) { - if((float)f >= (float)max) f = (float)f - (float)max; - else if(f < 0) { - f += max; - if((float)f >= (float)max) f = nextafterf(f, 0); + float upper = max - SMIDGE; + float range = upper - SMIDGE; + + if(f > upper) { + f -= range; + } + if(f < SMIDGE) { + f += range; } + return f; } + #endif // VOR_FLOAT_H -- 1.7.10.4