From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <3e1162e60512170324jaf33d6cgf5938e68e92256d2@mail.gmail.com> Date: Sat, 17 Dec 2005 03:24:10 -0800 From: David Leimbach To: Fans of the OS Plan 9 from Bell Labs <9fans@cse.psu.edu> Subject: Re: [9fans] More Microsoft bashing In-Reply-To: <3e1162e60512170309kba53cefm6959ed5b62135f0d@mail.gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_1422_13737197.1134818650328" References: <6e35c0620512152004n37c06ff5wd250424db50d874d@mail.gmail.com> <3e1162e60512170309kba53cefm6959ed5b62135f0d@mail.gmail.com> Topicbox-Message-UUID: c98052b2-ead0-11e9-9d60-3106f5b1d025 ------=_Part_1422_13737197.1134818650328 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline If you have the C99 standard handy anyway, this is clearly stated on page 8= 2 :) 6.5.5.5: --- The result of the / operator is the quotient from the division of the first operand by the second; the result of the % operator is the remainder. In both operations, if the value of the second operand is zero, the behavior i= s undefined. --- So negatives are allowed in the C99 standard. I don't have a copy of the C89 standard so I can't quote that one. Plan 9 = C isn't C99 so I'm not sure any of this is even relevant ot the list. In The C Programming Language ["draft ANSI Version" that I got from a college professor who was retiring] it says that the expression x % y produces the remainder when x is divided by y. Dave On 12/17/05, David Leimbach wrote: > > C's 'mod' isn't really mod. It's actually remainder. It's always been > this way to my knowledge. > > If you want a real "mod" use Python or Ada :) > > Dave > > On 12/15/05, Jack Johnson wrote: > > > > Not really, but all the talk about Singularity got me poking around > > and I came across this: > > > > ------ > > > > How are the functions DIV and MOD defined? > > > > The following answers are given by the Internal Working Document on > > the Common Language Infrastructure (CLI). > > > > result =3D value1 DIV value2 satisfies the following conditions: > > |result| =3D |value1| / |value2|, and > > sign(result) =3D +, if sign(value1) =3D sign(value2) > > sign(result) =3D - , if sign(value1) # sign(value2) > > > > result =3D value1 MOD value2 satisfies the following conditions: > > result =3D value1 - value2 * (value1 DIV value2), and > > 0 <=3D |result| < |value2|, and > > sign(result) =3D sign(value1) > > > > Please note that this definition of DIV and MOD differs from the > > definition given in [M. Reiser, N. Wirth. Programming in Oberon. p. > > 36]: > > x =3D (x DIV y) * y + (x MOD y), and > > 0 <=3D (x MOD y) < y > > > > ( from http://www.bluebottle.ethz.ch/oberon.net/faq.html#ad_DivMod ) > > > > ------ > > > > I kind of collect random, older computer science texts, so I cracked > > open The Nature of Computation by Pohl and Shaw, which yields: > > > > "x MOD y =3D x - (x =F7 y) * y, where =F7 indicates integer division = (i.e. > > fractions are disregarded; equivalently, the result of the division is > > truncated)." > > > > So, what *is* -5 MOD 3? > > > > -Jack > > > > ------=_Part_1422_13737197.1134818650328 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline If you have the C99 standard handy anyway, this is clearly stated on page 8= 2 :)

6.5.5.5:
---
The result of= the / operator is the quotient from the division of the first operand by t= he second; the result of the % operator is the remainder.  In both ope= rations, if the value of the second operand is zero, the behavior is undefi= ned.
---

So negatives are allowed in the C99 standard.

I don't= have a copy of the C89 standard so I can't quote that one.  Plan 9 C = isn't C99 so I'm not sure any of this is even relevant ot the list.

= In The C Programming Language ["draft ANSI Version" that I got fr= om a college professor who was retiring] it says that  the expression

x % y

produces the remainder when x is divided by y.

=
Dave

On 12/17/05, David Leimbach < leimy2k@gmail.com> wrote:
C's 'mod' isn't really mod.  It's actually remai= nder.  It's always been this way to my knowledge.

If you want a real "mod" use Python or Ada :)

Dave=


On 12/15/05,=20 Jack Johnson <knapjack@gmail.com> wrote:
Not really, but all the talk about Singularity got me poking around
and = I came across this:

------

How are the functions DIV and MOD = defined?

The following answers are given by the Internal Working Doc= ument on
the Common Language Infrastructure (CLI).

result =3D value1 DIV = value2 satisfies the following conditions:
|result| =3D |value1| / |valu= e2|, and
sign(result) =3D +, if sign(value1) =3D sign(value2)
sign(re= sult) =3D - , if sign(value1) # sign(value2)

result  =3D value1 MOD value2 satisfies the following con= ditions:
result =3D value1 - value2 * (value1 DIV value2), and
0 <= =3D |result| < |value2|, and
sign(result) =3D sign(value1)

Ple= ase note that this definition of DIV and MOD differs from the
definition given in [M. Reiser, N. Wirth. Programming in Oberon. p.
= 36]:
x  =3D (x DIV y) * y + (x MOD y), and
0 <=3D (x MOD= y) < y

( from http://www.bluebottle.ethz.ch/oberon.net/faq.html#ad_DivMod )

--= ----

I kind of collect random, older computer science texts, so I cr= acked
open The Nature of Computation by Pohl and Shaw, which yields:

  "x MOD y =3D x - (x =F7 y) * y, where =F7 indicate= s integer division (i.e.
fractions are disregarded; equivalently, the re= sult of the division is
truncated)."

So, what *is* -5 MOD 3?=

-Jack


------=_Part_1422_13737197.1134818650328--