From ee2f5960f428f314acb76fea3dd8f25a7d0c54aa Mon Sep 17 00:00:00 2001 From: lisyarus Date: Fri, 12 Mar 2021 14:42:31 +0300 Subject: [PATCH] Add idiv & imod functions --- libs/geom/include/psemek/geom/math.hpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libs/geom/include/psemek/geom/math.hpp b/libs/geom/include/psemek/geom/math.hpp index 9a10d075..ea820d1c 100644 --- a/libs/geom/include/psemek/geom/math.hpp +++ b/libs/geom/include/psemek/geom/math.hpp @@ -118,4 +118,16 @@ namespace psemek::geom return std::atan2(y, x); } + template + T idiv(T x, T m) + { + return (x >= 0) ? (x / m) : -((- x + m - 1) / m); + } + + template + T imod(T x, T m) + { + return x - m * idiv(x, m); + } + }