[gnu.emacs] Bug in cl.el division

mad@math.keio.JUNET (MAEDA Atusi) (09/17/89)

In article <124799@sun.Eng.Sun.COM> rock%warp@Sun.COM (Bill Petro) writes:
   >Sometimes when I start getris, I get:
   >Args out of range: [[2 (6 .2) (4 . 2) (2 . 2) (0 . 2)) (3 (2 . 3) (2 .  2)  (2 . 
   >Any ideas?
   >
   >(Sun 3/160 SunOS 4.0.3)

In article <124801@sun.Eng.Sun.COM> anantha%ravi@Sun.COM (Anantha Srirama) writes:
   >I am having problem running this game after I made the changes concerning the
   >kanji-flag.  I chose the "boundp 'kanji-flag" approach as suggested by somebody
   >on the net.  When the games starts up with the sign-on message and I hit
   >cariage return to start the game I get the following message in the mini-buffer
   >
   >Args out of range: [[(2 (6 . 2) (4 . 2) (2 . 2) (0 . 2)) (3 (2 . 3) (2 . 2) (2.
   >......
   >
   >I haven't changed any of the user customizable variables, leaving them in
   >their default states.  Anybody have any clue as to why this is happening??

I suppose the people having this kind of problem use cl.el, the Common
Lisp compatibility package.  The `mod' function redefined in cl.el has a
bug.  (Actually, other division functions such as `floor', `truncate',
`ceiling', `round', and `rem' also suffer from that bug.)

The problem is that an internal routine commonly used in division fucntions,
named `safe-idiv', is not safe.  The routine calculate the sign of
the remainder by (signum (* a b)), and this sometimes overflows.  (It
should be (* (signum a) (signum b)), I think.)

For example, on our Emacs
 (GNU Emacs 18.52.18 of Wed Jun 21 1989 on cabbage (berkeley-unix), Sun4/260)
(mod -1579501 7) returns -3159002 after loading cl.el.  The correct value is 0.

Built-in `mod' function seems to return correct value.

I don't know whether this bug has already reported.  I cross-post this
message to gnu.emacs and gnu.emacs.bug.  Please follow up only in gnu.emacs.

Thanks.

;;;  Keio University
;;;    Faculty of Science and Technology
;;;      Department of Math
;;;		MAEDA Atusi (In Japan we write our family names first.)
;;;		mad@nakanishi.math.keio.ac.jp