Quote:

Guenter Dotzel writes:

> The semantics of Oberon-2's DIV and MOD is specified by the

> function procedures ODIV and OMOD written in Oberon-2 and listed

> below. The implementation of ODIV and OMOD checks for negative

> dividends and uses DIV and MOD only with positive dividends and

> hence doesn't depend on the semantical differences described above,

> but doesn't check for overflow:

> (**

> y > 0

> x = ODIV(x,y)*y + OMOD(x,y)

> 0 <= OMOD(x,y) < y

> **)

There are many natural applications that require DIV and MOD to be

implemented correctly, i.e. according to the definition extant in

mathematics for well over 100 years. The above quoted definition,

where (x Mod y) is always non-negative, is that correct definition.

I can pull my number theory books and give an exact citation if

required. Off the top of my head, Neal McCoy is one such reference.

The two natural applications available to physical scientists and

engineers are the strip-chart recorder with wraparound and the

clock. Not suprisingly, the introduction to the equivalence groups

in mathematics sometimes calls them the clock numbers.

In a clock simulation or a wrap-around strip chart with 12 levels,

it is natural to desire 12+1 becomes 1. This is equivalent to 0+1

becomes 1. We would also have 12+1-2 (hours) becomes 11 hours.

There is not legal answer of -1 hours, either in the clock or the

stripchart.

Professor Wirth offers us a correct definition and example in the

distribution file Oberon2.Report.Text (Sparc.2.6). I quote without

permission:

Quote:

> 8.2.2 Arithmetic operators

> + sum

> - difference

> * product

> / real quotient

> DIV integer quotient

> MOD modulus

> The operators +, -, *, and / apply to operands of numeric types. The

> type of the result is the type of that operand which includes the

> type of the other operand, except for division (/), where the result

> is the smallest real type which includes both operand types. When

> used as monadic operators, - denotes sign inversion and + denotes

> the identity operation. The operators DIV and MOD apply to integer

> operands only. They are related by the following formulas defined

> for any x and positive divisors y:

> x = (x DIV y) * y + (x MOD y)

> 0 <= (x MOD y) < y

> Examples:

> x y x DIV y x MOD y

> 5 3 1 2

> -5 3 -2 1

Almost all hardware designers make this symmetrical around zero,

that is, they implement (-x) MOD y as -(x MOD y). This is contrary

to well established definitions, i.e. wrong. Please tell your EE

undergraduates this. I cannot believe that it is advantageous to

make a program wrong to make it faster. We don't re-define

multiplication when we work with a 6502. Although in principle

I cannot see any problem with extensions that allow a correct program

to function correctly, as yours would, I also cannot see any reason to

add changes specifically to allow an incorrect program to be written.

To change Wirth's Einstein quote: "Make it as fast as possible, but not

faster." (Relatively speaking... :-)

If there is any (natural) application to use a negative definition of

Mod, I'd be more inclined to stay silent about this. If anyone knows

of one, I'd appreciate knowing of it.

--

Aubrey McIntosh / Chemistry / University of Texas / Austin, TX 78712

..another Gaelic learner...