ClojureDocs

Nav

Namespaces

quot

clojure.core

Available since 1.0 (source)
  • (quot num div)
quot[ient] of dividing numerator by denominator.
2 Examples
;; (quot m n) is the value of m/n, rounded towards 0 to the nearest integer.
;; m, n need not be integers.

user=> (quot 10 3)
3

user=> (quot 11 3)
3

user=> (quot 12 3)
4

user=> (quot -5.9 3)
-1.0

user=> (quot 10 -3)
-3

user=> (quot 15 0)
ArithmeticException / by zero  clojure.lang.Numbers.quotient (Numbers.java:1764)


;; For ClojureScript (at least v1.10.597), `num`, `div` should be integer.
;; Otherwise, it does not work correctly due to its implementation:
http://cljs.github.io/api/cljs.core/quot

;; in clojure,
user=> (quot 286.3 21.2)
13.0

;; in clojurescript
cljs.user=> (quot 286.3 21.2)
12
;; note that the "/" function and the quot function are not equivalent

user=> (= (/ 4 2) (quot 4 2))
true

user=> (= (/ 3 2) (quot 3 2))
false
See Also

remainder of dividing numerator by denominator.

Added by Kototama

Modulus of num and div. Truncates toward negative infinity.

Added by Kototama

Returns the division of x by y, both int. Note - uses a primitive operator subject to truncation.

Added by timgilbert

If no denominators are supplied, returns 1/numerator, else returns numerator divided by all of the...

Added by chrismurrph

Integer division that rounds to negative infinity (as opposed to zero). The special case (floorDiv...

Added by tomdl89
0 Notes
No notes for quot