diff --git a/code/__DEFINES/maths.dm b/code/__DEFINES/maths.dm index 29f26e4500..f37efd694c 100644 --- a/code/__DEFINES/maths.dm +++ b/code/__DEFINES/maths.dm @@ -30,7 +30,7 @@ #define FLOOR(x, y) ( round((x) / (y)) * (y) ) // Similar to clamp but the bottom rolls around to the top and vice versa. min is inclusive, max is exclusive -#define WRAP(val, min, max) ( min == max ? min : (val) - (round(((val) - (min))/((max) - (min))) * ((max) - (min))) ) +#define WRAP(val, min, max) CLAMP(( min == max ? min : (val) - (round(((val) - (min))/((max) - (min))) * ((max) - (min))) ),min,max-1) // Real modulus that handles decimals #define MODULUS(x, y) ( (x) - (y) * round((x) / (y)) )