From b01c594cba74c8a2ec0d876a4bc64c0ef456e17e Mon Sep 17 00:00:00 2001 From: lisyarus Date: Thu, 30 Jan 2025 12:37:48 +0300 Subject: [PATCH] Add math::fmod that works for negative inputs --- libs/math/include/psemek/math/math.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libs/math/include/psemek/math/math.hpp b/libs/math/include/psemek/math/math.hpp index d6c0c633..40d3d3e8 100644 --- a/libs/math/include/psemek/math/math.hpp +++ b/libs/math/include/psemek/math/math.hpp @@ -174,6 +174,12 @@ namespace psemek::math return (x / y) + ((x % y) == 0 ? 0 : 1); } + template + T fmod(T x, T m) + { + return (x >= 0) ? std::fmod(x, m) : (m - std::fmod(-x, m)); + } + template bool make_min(T & target, T const & source) {