% operator with negatives

Scott Amspoker scott at bbxsda.UUCP
Sat Dec 15 09:57:42 AEST 1990


In article <7461:Dec1310:04:0990 at kramden.acf.nyu.edu> brnstnd at 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   |



More information about the Comp.lang.c mailing list