I suppose then that we would also need div.  Using GHCi here:

Prelude> (-3) `div` 2
-2
Prelude> (-3) `quot` 2
-1


On Dec 22, 7:04 am, "Mark Engelberg" <mark.engelb...@gmail.com> wrote:
> Anyone know why there is no modulo or mod function in Clojure's core?
> I know there is a rem function, but that's not the same thing.  mod
> and rem behave differently when the first number is negative.
>
> (mod -2 5) -> 3
> (rem -2 5) -> -2
>
> modulo n is important for making things stay in the range from 0 to
> n-1, for example, if you're working with vectors of length n.  You
> need to ensure that negative numbers wrap around to the positive
> range.  rem does not do this.
>
> I'm more familiar with Scheme than CL, and I know PLT Scheme provides
> both modulo and remainder.  But according to the Wikipedia
> (http://en.wikipedia.org/wiki/Modulo_operation), Common Lisp also
> provides both mod and rem functions.  So why not Clojure?  Is it a
> Java defeciency?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to