@@ -58,3 +58,35 @@ internal actual fun safeMultiply(a: Int, b: Int): Int {
58
58
if (result > Int .MAX_VALUE || result < Int .MIN_VALUE ) throw ArithmeticException (" Multiplication overflows Int range: $a * $b ." )
59
59
return result.toInt()
60
60
}
61
+
62
+ /* *
63
+ * Returns the floor division.
64
+ * <p>
65
+ * This returns {@code 0} for {@code floorDiv(0, 4)}.<br />
66
+ * This returns {@code -1} for {@code floorDiv(-1, 4)}.<br />
67
+ * This returns {@code -1} for {@code floorDiv(-2, 4)}.<br />
68
+ * This returns {@code -1} for {@code floorDiv(-3, 4)}.<br />
69
+ * This returns {@code -1} for {@code floorDiv(-4, 4)}.<br />
70
+ * This returns {@code -2} for {@code floorDiv(-5, 4)}.<br />
71
+ *
72
+ * @param a the dividend
73
+ * @param b the divisor
74
+ * @return the floor division
75
+ */
76
+ internal fun floorDiv (a : Long , b : Long ): Long = if (a >= 0 ) a / b else (a + 1 ) / b - 1
77
+
78
+ /* *
79
+ * Returns the floor modulus.
80
+ *
81
+ *
82
+ * This returns `0` for `floorMod(0, 4)`.<br></br>
83
+ * This returns `1` for `floorMod(-1, 4)`.<br></br>
84
+ * This returns `2` for `floorMod(-2, 4)`.<br></br>
85
+ * This returns `3` for `floorMod(-3, 4)`.<br></br>
86
+ * This returns `0` for `floorMod(-4, 4)`.<br></br>
87
+ *
88
+ * @param a the dividend
89
+ * @param b the divisor
90
+ * @return the floor modulus (positive)
91
+ */
92
+ internal fun floorMod (a : Long , b : Long ): Long = (a % b + b) % b
0 commit comments