DIV and MOD ( was: Something IBM did right )

Prescott K. Turner turner at sdti.UUCP
Thu Nov 10 03:36:18 AEST 1988


In article <643 at quintus.UUCP> ok at quintus.UUCP (Richard A. O'Keefe) writes:
>As Every Schoolboy Knows, there are at least three sensible definitions of
>integer division/remainder, all of which agree which divisor and dividend
>are positive.
To call all three definitions "sensible" is inviting a war.  To me the
arguments Dave Jones presented make sense and the counterarguments do not.
Actually, I do accept as a counterargument that most programming languages
require the definition in which the quotient is truncated towards 0.
But it's a shame that they went down that path.

>Note that the Pascal standard does not define integer division and
>remainder for non-positive divisors.
The Pascal standard defines integer division for all divisors except 0.
Standard Pascal's "mod" operator does not give the remainder from "div",
even for positive divisors.  The committee decided that while "div" had to
be like all of the other languages, "mod" should be sensible.
--
Prescott K. Turner, Jr.
Software Development Technologies, Inc.
375 Dutton Rd., Sudbury, MA 01776 USA        (508) 443-5779
UUCP:...genrad!mrst!sdti!turner



More information about the Comp.lang.c mailing list