JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
55d3e30b23b3cf98e6c9cf791a9073fa50e713cc
[vor.git] / float.h
1 #ifndef VOR_FLOAT_H
2 #define VOR_FLOAT_H
3
4 #include <math.h>
5
6 #define SMIDGE 0.0001
7
8 // return true if f is OUTSIDE the range [SMIDGE..(max-SMIDGE)]
9 static inline int
10 fclip(float f, float max)
11 {
12         return f < SMIDGE || f >= (max - SMIDGE);
13 }
14
15 // wrap f so it's within the range [SMIDGE..(max-SMIDGE)]
16 // assumes f is not outside this range by more than (max - (2 * SMIDGE))
17 static inline float
18 fwrap(float f, float max)
19 {
20         float upper = max - SMIDGE;
21         float range = upper - SMIDGE;
22
23         if(f > upper) {
24                 f -= range;
25         }
26         if(f < SMIDGE) {
27                 f += range;
28         }
29
30         return f;
31 }
32
33
34 #endif // VOR_FLOAT_H