JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
* float.h (fwrap, fclip): new file.
[vor.git] / float.h
diff --git a/float.h b/float.h
new file mode 100644 (file)
index 0000000..58f6616
--- /dev/null
+++ b/float.h
@@ -0,0 +1,23 @@
+#ifndef VOR_FLOAT_H
+#define VOR_FLOAT_H
+
+#include <math.h>
+
+static inline int
+fclip(float f, float max)
+{
+       return f < 0 || (float)f >= (float)max;
+}
+
+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);
+       }
+       return f;
+}
+
+#endif // VOR_FLOAT_H