Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83 SMI; site sun.uucp Path: utzoo!linus!decvax!decwrl!sun!gnu From: gnu@sun.uucp (John Gilmore) Newsgroups: net.lang.c Subject: Anybody got a "Hacker's Integer Modulo"? Message-ID: <418@sun.uucp> Date: Thu, 12-Jan-84 05:52:10 EST Article-I.D.: sun.418 Posted: Thu Jan 12 05:52:10 1984 Date-Received: Fri, 13-Jan-84 05:48:53 EST References: <2208@fortune.UUCP> <3459@utzoo.UUCP> Organization: Sun Microsystems, Inc. Lines: 11 With all this talk about division, I'd like to see modulo addressed. I looked at compiling "hacker division" last month and came up with the code already described, but could not come up with reasonable code for doing "hacker modulo" (given the "Fortran" definition of modulo). For those who joined late, we're talking about dividing by powers of two, by shifting -- you have to correct it if the argument is negative. For modulo by powers of two, of course, you just want to AND to keep the low order bits, but again a correction is required for negatives -- one which was not obvious to me except to brute force it, which generates lousy code.