js-mod

function/macrosince v0.0-1552Edit
(js-mod n d)

Details:

Returns the modulus of dividing numerator n by denominator d, with JavaScript's original behavior for negative numbers.

Returns NaN when d is 0 (divide by 0 error).

Equivalent to x % y in JavaScript.


Examples:

(js-mod -5 3)
;;=> -2

(js-mod 5 3)
;;=> 2

(js-mod 5 0)
;;=> NaN

See Also:


Source docstring:
Modulus of num and div with original javascript behavior. i.e. bug for negative numbers
Function code @ clojurescript:src/main/cljs/cljs/core.cljs
(defn js-mod
  [n d]
  (cljs.core/js-mod n d))

Macro code @ clojurescript:src/main/clojure/cljs/core.cljc
(core/defmacro ^::ana/numeric js-mod [num div]
  (core/list 'js* "(~{} % ~{})" num div))