Skip to content

Commit 1f47f47

Browse files
committed
added mod, patch from Mark Engelberg
1 parent dfbb852 commit 1f47f47

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/clj/clojure/core.clj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,6 +1845,16 @@
18451845
(instance? Short n)
18461846
(instance? Byte n)))
18471847

1848+
(defn mod
1849+
"modulus of num and div."
1850+
[num div]
1851+
(cond
1852+
(or (not (integer? num)) (not (integer? div)))
1853+
(throw (IllegalArgumentException.
1854+
"mod requires two integers"))
1855+
(or (< num 0 div) (< div 0 num)) (+ (rem num div) div)
1856+
:else (rem num div)))
1857+
18481858
(defn ratio?
18491859
"Returns true if n is a Ratio"
18501860
[n] (instance? clojure.lang.Ratio n))

0 commit comments

Comments
 (0)