# [Oberon] Assumed issue in the Lola-2 compiler

rochus.keller at bluewin.ch rochus.keller at bluewin.ch
Tue Apr 16 11:40:17 CEST 2019

```Here for the sake of completeness the definitions from the ISO 14882:2011 C++ standard:

5.6 Multiplicative operators
1. The multiplicative operators *, /, and % group left-to-right.
2. The operands of * and / shall have arithmetic or unscoped enumeration type; the operands of % shall have
integral or unscoped enumeration type. The usual arithmetic conversions are performed on the operands
and determine the type of the result.
3. The binary * operator indicates multiplication.
4. The binary / operator yields the quotient, and the binary % operator yields the remainder from the division
of the first expression by the second. If the second operand of / or % is zero the behavior is undefined. For
integral operands the / operator yields the algebraic quotient with any fractional part discarded*; if the
quotient a/b is representable in the type of the result, (a/b)*b + a%b is equal to a.
* This is often called truncation towards zero.

And here from the ISO 9899:1999 C standard:

6.5.5 Multiplicative operators
2 Each of the operands shall have arithmetic type. The operands of the % operator shall
have integer type.
3 The usual arithmetic conversions are performed on the operands.
4 The result of the binary * operator is the product of the operands.
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 is undefined.
6 When integers are divided, the result of the / operator is the algebraic quotient with any
fractional part discarded*. If the quotient a/b is representable, the expression
(a/b)*b + a%b shall equal a.
* This is often called "truncation toward zero"

And here the last paragraph of section 8.2.2. Arithmetic operators of The Programming Language Oberon Revision 3.5.2016

The operators DIV and MOD apply to integer operands only. Let q = x DIV y, and r = x MOD y.
Then quotient q and remainder r are defined by the equation
x = q*y + r      0 <= r < y

So it's essentially the same, but the C/C++ standard in contrast to Oberon declares y=0 in DIV and MOD undefined and also explicitly requires "algebraic quotient" and "truncation toward zero".
Oberon in contrast to C/C++ requires y and r to be >= 0 (y=0 is not forbidden) and the truncation direction is not (explicitly) specified. From my point of view it is undecidable from the Oberon report whether "-1 DIV 16" is zero or -1. There are valid arguments for both interpretations.
```