[Oberon] real math

Chris Burrows chris at cfbsoftware.com
Sun Nov 9 22:34:17 CET 2014


> -----Original Message-----
> From: oberon at moravcik.info [mailto:oberon at moravcik.info]
> Sent: Monday, 10 November 2014 6:06 AM
> To: oberon at lists.inf.ethz.ch
> Subject: [Oberon] real math
> 
> Hi,
> 
> following code returns imprecise real number:
> 
>  r : REAL;
> 
>  r := 480 / 100 * 100;
>  out.Int( ENTIER(r * 1000000) , 0 );
> 
> outputs 48000019 instead of 48000000
> 
> How to check that 480/100*100 is 480 again ?
> 

It isn't so you can't. Refer to Section 3.2.2 The types REAL and LONGREAL in
"Programming in Oberon - Steps Beyond Pascal and Modula" by Martin Reiser
and Niklause Wirth. You can download a copy from:

http://www.inf.ethz.ch/personal/wirth/

"Floating-point numbers are only an approximation to the real numbers of
mathematics. As a consequence, computations involving floating-point values
are inexact because each operation may be subject to truncation. The
resulting problems have been investigated in detail, and are treated in
every text on numerical mathematics."

Regards,
Chris

Chris Burrows
CFB Software
http://www.cfbsoftware.com






More information about the Oberon mailing list