1.3 alpha 7: Bug in modulo

24 views
Skip to first unread message

Mark Engelberg

unread,
May 21, 2011, 6:09:37 AM5/21/11
to clojure-dev
In 1.3, (mod 3216478362187432 432143214) gives an arithmetic overflow error.

The code for mod currently determines whether num and div are the same
sign with the test: (pos? (* num div))), and the multiplication is
overflowing.
The test needs to be replaced by something like (= (pos? num) (pos? div))

Stuart Sierra

unread,
May 21, 2011, 4:56:51 PM5/21/11
to cloju...@googlegroups.com
This looks like a real bug to me. Please create a ticket on http://dev.clojure.org/jira

-Stuart Sierra
clojure.com

ataggart

unread,
May 22, 2011, 1:54:19 AM5/22/11
to Clojure Dev

Mark Engelberg

unread,
May 23, 2011, 2:15:11 AM5/23/11
to cloju...@googlegroups.com
Upon further thought, can't the
(pos? (* num div))
just be replaced by
(pos? m)

ataggart

unread,
May 23, 2011, 1:11:10 PM5/23/11
to Clojure Dev
No, the sign of the rem result is insufficient to determine the mod
result. It has to look at the sign of the args:

user=> (for [x [12 -12] y [5 -5]] ((juxt mod rem) x y))
([2 2] [-3 2] [3 -2] [-2 -2])

Mark Engelberg

unread,
May 23, 2011, 1:49:48 PM5/23/11
to cloju...@googlegroups.com
Right. Thanks.
Reply all
Reply to author
Forward
0 new messages