aboutsummaryrefslogtreecommitdiff
path: root/src/lib/math.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/math.js')
-rw-r--r--src/lib/math.js8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/lib/math.js b/src/lib/math.js
new file mode 100644
index 0000000..c745cdc
--- /dev/null
+++ b/src/lib/math.js
@@ -0,0 +1,8 @@
+/**
+ * Modulo that acts well with negative numbers.
+ * @param {number} dividend the number to divide
+ * @param {number} divisor the divisor to calculate the remainder
+ */
+export const modulo = function modulo (dividend, divisor) {
+ return ((dividend % divisor) + divisor) % divisor
+};