Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!samsung!uakari.primate.wisc.edu!unmvax!bbx!bbxsda!scott From: scott@bbxsda.UUCP (Scott Amspoker) Newsgroups: comp.lang.c Subject: Re: % operator with negatives Message-ID: <1529@bbxsda.UUCP> Date: 14 Dec 90 22:57:42 GMT References: <1990Dec12.185714.7169@mp.cs.niu.edu> <1990Dec12.205416.26622@zoo.toronto.edu> <7461:Dec1310:04:0990@kramden.acf.nyu.edu> Reply-To: scott@bbxsda.UUCP (Scott Amspoker) Organization: Basis International, Albuquerque, NM Lines: 20 In article <7461:Dec1310:04:0990@kramden.acf.nyu.edu> brnstnd@kramden.acf.nyu.edu (Dan Bernstein) writes: >And if you're asking ``Where is the information on it?'', the answer is >that a % b is defined so that (a / b) * b + (a % b) equals a. It's the >ambiguous definition of / that makes % so useless with negatives. Well I can really stir up the muck by pointing out that, by definition, a mod 0 == a Therefore, the method of dividing (a/b) does not always work since b could legally equal 0. To be fair, C compilers disregard this "feature" of a modulo and give an error on expressions such as 'a % 0'. If you wish a guaranteed proper modulo you might have to implement your own and not rely on the '%' operater. -- Scott Amspoker | Basis International, Albuquerque, NM | "I'm going out for a sandwich" (505) 345-5232 | - Ben unmvax.cs.unm.edu!bbx!bbxsda!scott |