diff --git a/libs/geom/include/psemek/geom/math.hpp b/libs/geom/include/psemek/geom/math.hpp index b74dc013..8e3d832d 100644 --- a/libs/geom/include/psemek/geom/math.hpp +++ b/libs/geom/include/psemek/geom/math.hpp @@ -155,15 +155,17 @@ namespace psemek::geom } template - T idiv(T x, T m) + T imod(T x, T m) { - return (x >= 0) ? (x / m) : -((- x + m - 1) / m); + static_assert(std::is_integral_v); + return ((x % m) + m) % m; } template - T imod(T x, T m) + T idiv(T x, T m) { - return x - m * idiv(x, m); + static_assert(std::is_integral_v); + return (x - imod(x, m)) / m; } template