diff options
author | Rich Hickey <richhickey@gmail.com> | 2009-01-23 02:07:16 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2009-01-23 02:07:16 +0000 |
commit | 1f47f47f1e84f5c9bda36a2b22feba73df553faf (patch) | |
tree | 9e064dd48c1f095039ac0dbf602f8617836d053f | |
parent | dfbb8529a8df73d6844c2554c95307d35646b7e6 (diff) |
added mod, patch from Mark Engelberg
-rw-r--r-- | src/clj/clojure/core.clj | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj index 830c0192..848ee2d7 100644 --- a/src/clj/clojure/core.clj +++ b/src/clj/clojure/core.clj @@ -1845,6 +1845,16 @@ (instance? Short n) (instance? Byte n))) +(defn mod + "modulus of num and div." + [num div] + (cond + (or (not (integer? num)) (not (integer? div))) + (throw (IllegalArgumentException. + "mod requires two integers")) + (or (< num 0 div) (< div 0 num)) (+ (rem num div) div) + :else (rem num div))) + (defn ratio? "Returns true if n is a Ratio" [n] (instance? clojure.lang.Ratio n)) |