From d2a20d78829e067dce34caedb6a809eb4fbf829f Mon Sep 17 00:00:00 2001 From: lisyarus Date: Fri, 11 Feb 2022 14:26:11 +0300 Subject: [PATCH] Add safe round-up integer division --- libs/geom/include/psemek/geom/math.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libs/geom/include/psemek/geom/math.hpp b/libs/geom/include/psemek/geom/math.hpp index 71b559b1..56aab707 100644 --- a/libs/geom/include/psemek/geom/math.hpp +++ b/libs/geom/include/psemek/geom/math.hpp @@ -165,4 +165,10 @@ namespace psemek::geom return x - m * idiv(x, m); } + template + T div_ceil(T x, T y) + { + return (x / y) + ((x % y) == 0 ? 0 : 1); + } + }