cljs.math/floor-mod
function | since v1.11.50 | Edit |
(floor-mod x y)
Source docstring:
Integer modulus x - (floorDiv(x, y) * y). Sign matches y and is in the
range -|y| < r < |y|.
See: https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#floorMod-long-long-
(defn ^number floor-mod
{:added "1.11.10"}
[x y]
(if-not (and ^boolean (js/Number.isSafeInteger x) ^boolean (js/Number.isSafeInteger y))
(throw (ex-info "floor-mod called with non-safe-integer arguments"
{:x-int? (js/Number.isSafeInteger x) :y-int? (js/Number.isSafeInteger y)}))
(let [r (long (/ x y))]
(if (and (xor (< x 0) (< y 0)) (not (== (* r y) x)))
(- x (* y r) (- y))
(- x (* y r))))))