diff --git a/src/periodic.h b/src/periodic.h index 05cb2fe454feadf8fe75942294443a726fc94d89..e3656efc614b983ecfd300d30984b51bf8f01054 100644 --- a/src/periodic.h +++ b/src/periodic.h @@ -28,15 +28,15 @@ /** * @brief Limits the value of x to be between a and b * - * Only wraps once. If x > 2b, the returned value will be larger than b. - * Similarly for x < -b. + * Only wraps once. If x > a + 2(b - a), the returned value will be larger than + * b. Similarly for x < a - (b - a), the value will be smaller than a. */ -#define box_wrap(x, a, b) \ - ({ \ - const __typeof__(x) _x = (x); \ - const __typeof__(a) _a = (a); \ - const __typeof__(b) _b = (b); \ - _x < _a ? (_x + _b) : ((_x >= _b) ? (_x - _b) : _x); \ +#define box_wrap(x, a, b) \ + ({ \ + const __typeof__(x) _x = (x); \ + const __typeof__(a) _a = (a); \ + const __typeof__(b) _b = (b); \ + _x < _a ? (_x + (_b - _a)) : ((_x >= _b) ? (_x - (_b - _a)) : _x); \ }) /**