[Oberon] real math

Chris Burrows chris at cfbsoftware.com
Wed Nov 12 12:37:39 CET 2014

In Oberon the numbers 480 and 100 are both INTEGERs. You need to include a
decimal point to indicate that a number is a REAL e.g. 480.0 and 100.0.
However, in this example it is fairly inconsequential as in Oberon (1990)
and later Oberon-2 (1992), numeric types form a hierarchy where the larger
type includes (the values of) the smaller type:


Again, quoting from 'Programming in Oberon':

"The range of the larger type includes the ranges of the smaller types. For
example, REAL includes LONGINT.. .SHORTINT. The smaller type is said to be
compatible with the larger one in the sense that it can, without danger of
loss of leading digits, be converted. In most cases, such a conversion is
also exact. In assignments and in expressions, the conversion of internal
representations is automatic."

Because "/" is a REAL operator 480 / 100 is automatically converted to 480.0
/ 100.0. As the result is REAL, when it is multiplied by 100, that is also
automatically convertd to 100.0. 

On the other hand, Oberon systems (e.g. Project Oberon 2013 and Astrobe)
which conform to more recent versions of the Oberon Language report
(2007-2014) behave more like Modula-2. i.e explicit numeric conversion
functions (FLT and FLOOR) are required to convert INTEGER to REAL and
vice-versa. There is no automatic conversion performed and the following
results in a runtime error:

  r := 480 / 100 * 100;

You can either write this as:

  r := 480.0 / 100.0 * 100.0;

Or if you prefer:

  r := FLT(480) / FLT(100) * FLT(100);


Chris Burrows
Astrobe: Oberon for ARM Cortex M3 and M4

From: rob solomon [mailto:drrob106 at verizon.net] 
Sent: Wednesday, 12 November 2014 11:48 AM
To: ETH Oberon and related systems
Subject: Re: [Oberon] real math

Not knowing much about oberon, but I have use modula-2 for many years.  I
have one observation.

r := 480 / 100 * 100;

In modula-2, this line would not be allowed, as it is doing integer
arithmetic, getting an integer result, and they trying to assign this
integer result to a real number.

Is oberon less type-strict?  Is oberon more like C and Fortran in this way?

More information about the Oberon mailing list