summary refs log tree commit diff
path: root/src/Math/Mod.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Math/Mod.hpp')
-rw-r--r--src/Math/Mod.hpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/Math/Mod.hpp b/src/Math/Mod.hpp
new file mode 100644
index 0000000..d686ad9
--- /dev/null
+++ b/src/Math/Mod.hpp
@@ -0,0 +1,12 @@
+#pragma once
+
+namespace Math {
+
+// Returns the least nonnegative remainder of a % b.
+// Euclidian definition of modulo.
+template <typename A, typename B>
+auto mod(A a, B b) -> decltype(a % b) {
+    return (a % b + b) % b;
+}
+
+}
\ No newline at end of file