X-Git-Url: https://jasonwoof.com/gitweb/?p=vor.git;a=blobdiff_plain;f=float.h;fp=float.h;h=58f6616a8ec555d31da966fb44d2f2b5bd2e8eab;hp=0000000000000000000000000000000000000000;hb=fe549d406b589b1c3db83aeea28c911292a5968e;hpb=1796973cc22433f9b875b8b6d945fc914a78e14d diff --git a/float.h b/float.h new file mode 100644 index 0000000..58f6616 --- /dev/null +++ b/float.h @@ -0,0 +1,23 @@ +#ifndef VOR_FLOAT_H +#define VOR_FLOAT_H + +#include + +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