[Oberon] A C++ version of the Lola-2 compiler and an Oberon to C++ compiler

JR joerg.straube at iaeth.ch
Fri Apr 19 08:57:14 CEST 2019


Hi all

The last one of my three variants is only correct if b is a power of two. This is very often the case in Oberon programs.
But Chris is right, I missed the MOD = 0 case as shown in his example. Hopefully this one does it:

   int _MOD(int a, b) { int m = a%b; if (a < 0 && m != 0) m += b; return m; } 

br
Jörg

> Am 19.04.2019 um 01:05 schrieb Chris Burrows <chris at cfbsoftware.com>:
> 
>> -----Original Message-----
>> From: Oberon [mailto:oberon-bounces at lists.inf.ethz.ch] On Behalf Of
>> rochus.keller at bluewin.ch
>> Sent: Thursday, 18 April 2019 9:43 PM
>> To: oberon at lists.inf.ethz.ch
>> Subject: Re: [Oberon] A C++ version of the Lola-2 compiler and an
>> Oberon to C++ compiler
>> 
>> @ Chris Burrows
>> 
>> Thank you very much for the implementation; it's obviously much more
>> elegant than my quick approach. There is also this proposal by J rg
>> Straube:
>> 
>> int _MOD(int a, b) { int m = a%b; if (a<0) m += b; return m; } 
>> int _MOD(int a, b) { return a<0 ? a%b+b : a%b ; } 
>> int _MOD(int a, b) { return a & (b-1); }
>> 
> 
> None of those gives the same results as either your quick approach or my implementation, e.g. 
> 
> a := -21
> b := 7 
> 
> The result of a MOD b should be 0. Unless I'm mistaken the first two return 7 and the last returns 2.
> 
> Regards,
> Chris
> 
> Chris Burrows
> CFB Software
> http://www.astrobe.com
> 
> 
> --
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
> https://lists.inf.ethz.ch/mailman/listinfo/oberon



More information about the Oberon mailing list