On Tue, Feb 10, 2009 at 8:55 PM, Timothy Pratley
<[email protected]> wrote:
>
> In the code I posted the let evaluated rem before checking the
> arguments.
Thanks for doing all the hard work. :-)
How about:
(defn mod42
"Modulus of num and div. Truncates toward negative infinity."
[num div]
(if-not (and (integer? num) (integer? div))
(throw (IllegalArgumentException. "mod requires two integers"))
(let [m (rem num div)]
(if (or (zero? m) (> (* num div) 0))
m
(+ m div)))))
--Chouser
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---