From 9f3624ba3e43ebe4dd0b29a7fd181a5209d76fd3 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Wed, 14 Sep 2016 17:37:49 +1000 Subject: [PATCH] maths: add mod wrappers --- maths.hpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/maths.hpp b/maths.hpp index 543ceed1..712cf7ab 100644 --- a/maths.hpp +++ b/maths.hpp @@ -385,6 +385,32 @@ namespace util { } + /////////////////////////////////////////////////////////////////////////// + // Modulus/etc + + // namespaced wrapper for `man 3 fmod` + template + constexpr + std::enable_if_t< + std::is_floating_point::value, T + > + mod (T x, T y) + { + return std::fmod (x, y); + } + + + template + constexpr + std::enable_if_t< + std::is_integral::value, T + > + mod (T x, T y) + { + return x % y; + } + + /////////////////////////////////////////////////////////////////////////////// // angles, trig template