modulus fn with negatives

jrv at mitre-bedford.ARPA jrv at mitre-bedford.ARPA
Mon Sep 10 10:29:00 AEST 1984


>Should ((-2) % 3) equal -2 or 1?  Our machine returns -2, but the posted
>corewars game seems to assume a%b always returns 0..b-1; is modulus for
>negative lefthand args well defined?  What about Pascal mod function?
>Modula Modulus?  Accepted mathematical definition of modulus?
>                                                Merlyn % Leroy

K&R apparently allow for either kind, but every time I've USED a
modulus function, I needed one that returned a nonnegative
number, whether the dividend was positive or negative. Has
anyone ever needed the other kind?  Has anyone ever needed a
modulus with a negative divisor?
                                        - Jim Van Zandt



More information about the Comp.lang.c mailing list