From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,18069d15345a10c8,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1994-09-27 13:25:26 PST Path: bga.com!news.sprintlink.net!howland.reston.ans.net!europa.eng.gtefsd.com!paladin.american.edu!auvm!V22BZ.NPT.NUWC.NAVY.MIL!COBB Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU Newsgroups: comp.lang.ada Message-ID: <940927104030.20400d35@v22bz.npt.nuwc.navy.mil> Date: Tue, 27 Sep 1994 10:40:30 -0400 Sender: Ada programming language From: "David A. Cobb" Subject: Modulus and Remainder operations (Was Re: Help with a bit of C code) Comments: To: INFO-ADA@VM1.NODAK.EDU Date: 1994-09-27T10:40:30-04:00 List-Id: X-In-Reply-To: Mon, 26 Sep 1994 14:35:11 EDT Strictly speaking, the % operator in C is a REMAINDER operator, not a MODULUS operator. This often seems to be a confusing point for a lot of people, but the results are different for negative numbers (Try it with, eg, PL/I, which uses the modulus function rather than the remainder function). For example, these 3 languages give the following results: Ada, the language everyone loves to hate, has both but has the decency to give both clear definitions. I assume the designers talked to a mathamagician: A = (A/B)*B + (A rem B) where (A rem B) has the sign of A and an absolute value less than B. .... A = B*N + (A mod B), for some signed integer N, where (A mod B) has the sign of B and an absolute value less than the absolute value of B. Thus:
    A        B        A/B      A rem B   A mod B
    12        5         2         2         2
   -12        5        -2        -2         3
    12       -5        -2         2        -3
   -12       -5        -2        -2        -2