comp.lang.ada
 help / color / mirror / Atom feed
* Modulus and Remainder operations (Was Re: Help with a bit of C code)
@ 1994-09-27 14:40 David A. Cobb
  1994-09-28 13:56 ` Robert Dewar
  0 siblings, 1 reply; 21+ messages in thread
From: David A. Cobb @ 1994-09-27 14:40 UTC (permalink / raw)


X-In-Reply-To: Mon, 26 Sep 1994 14:35:11 EDT <bruce@AIS.COM>

<quote>
    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:
</quote>

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:

<quote>
    A = (A/B)*B + (A rem B) where (A rem B) <e>has the sign of A</e>
and an absolute value less than B. ....

    A = B*N + (A mod B), for some signed integer N, where (A mod B)
<e>has the sign of B</e> and an absolute value less than the
absolute value of B.
</quote>

Thus:
<pre>
    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
</pre>



^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~1994-10-16  1:25 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1994-09-27 14:40 Modulus and Remainder operations (Was Re: Help with a bit of C code) David A. Cobb
1994-09-28 13:56 ` Robert Dewar
1994-09-29  9:04   ` Christopher Costello
1994-09-29 14:34   ` Norman H. Cohen
     [not found]   ` <1994Oct7.225248.6208@nosc.mil>
     [not found]     ` <1994Oct10.084630.19894@sei.cmu.edu>
     [not found]       ` <37bof4$ljl@gnat.cs.nyu.edu>
     [not found]         ` <37cigq$6e0@felix.seas.gwu.edu>
1994-10-11 14:42           ` Norman H. Cohen
     [not found]     ` <hbakerCxFK2p.4wp@netcom.com>
     [not found]       ` <1994Oct11.161048.1058@nosc.mil>
1994-10-11 20:06         ` Norman H. Cohen
1994-10-13  1:51           ` Henry G. Baker
1994-10-13  8:27             ` Magnus Kempe
1994-10-13 12:30               ` Robert Dewar
1994-10-14 15:45               ` Henry G. Baker
1994-10-14 22:11                 ` Robert Dewar
1994-10-15 17:35                 ` Tucker Taft
1994-10-13 10:38             ` Tucker Taft
1994-10-13 21:34             ` Norman H. Cohen
1994-10-14 15:39               ` Henry G. Baker
1994-10-14 22:56                 ` David Weller
1994-10-16  1:25                   ` Henry G. Baker
1994-10-13 18:13           ` Charles H. Sampson
1994-10-13 16:56             ` Robert I. Eachus
1994-10-13 20:59             ` Robert Dewar
1994-10-13 23:44             ` Bob Duff

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox