[Oberon] Assumed issue in the Lola-2 compiler
Chris Burrows
chris at cfbsoftware.com
Mon Apr 15 13:29:28 CEST 2019
> -----Original Message-----
> From: Oberon [mailto:oberon-bounces at lists.inf.ethz.ch] On Behalf Of
> rochus.keller at bluewin.ch
> Sent: Monday, 15 April 2019 8:02 PM
> To: oberon at lists.inf.ethz.ch
> Subject: Re: [Oberon] Assumed issue in the Lola-2 compiler
>
> @ Paul Reed:
>
> >> The result of x [= -1] DIV 10H is -1, because it is implemented as
> an
> >> arithmetic shift right, in turn because the divisor is a constant
> power of two.
>
> Thank you for the clarification. Is there a formal specification
> somewhere of how the DIV operator exactly works? I read quite a lot
> of stuff about Oberon but didn't find an indication so far that "-1
> DIV 16 = -1". Can you give me a hint please where I can find a
> complete specification, a value table or at least a reference
> implementation?
>
In the Oberon-07 Language Report DIV and MOD are defined as follows:
------------------------------------------------------------------
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
a) x = q*y + r
b) 0 <= r < y
------------------------------------------------------------------
Hence, in the case of -1 DIV 16, x = -1 and y = 16.
Therefore, substituting for x and y in a):
-1 = q * 16 + r
Rearranging:
q = -(r + 1) / 16
therefore to satisfy the constraint b) on r, for integer r and q, r must
equal 15 and therefore q = -16 / 16 = -1.
There was a lengthy discussion somewhat related to this in this mailing list
a couple of years ago:
http://lists.inf.ethz.ch/pipermail/oberon/2017/010355.html
Regards,
Chris Burrows
CFB Software
http://www.astrobe.com
More information about the Oberon
mailing list