[Oberon] real math

oberon at moravcik.info oberon at moravcik.info
Thu Nov 13 14:26:19 CET 2014


> This expression is evaluated in double precision
> before being assigned to the single precision variable. This has the
> effect of rounding off the errors.

That's it! After changing the source code to:
 float f = 480.0;
 f = f / 100.0;
 f = f * 100.0;
 printf("result1: %3.15f\n", f);

produces on my machine result1: 480.000030517578125


So the hand calculators are using similar approach? (rounding on hidden digits?)

What if the compilers would compute every real number operation with longreal and then rounding back to real number?

Like for example do real division with REAL(float) number in LONGREAL(double) space, 
with LONGREAL number in even bigger space (HUGEREAL?)....



Zdenek

On Thu, Nov 13, 2014 at 11:48:20PM +1100, Sean Case wrote:
> On 13 Nov 2014, at 23:28, oberon at moravcik.info wrote:
> 
> >   float number;
> 
> ‘number’ is a single precision variable.
> 
> >   number = 480.0 / 100.0 * 100.0;
> 
> I believe that this expression is evaluated in double precision
> before being assigned to the single precision variable. This has the
> effect of rounding off the errors.
> 
> The errors arise in the first place because the computer represents
> floating point numbers as binary fractions, as opposed to the decimal
> fractions used by most calculators. 4.8 as a binary fraction is a
> recurring sequence, like, say, 1/3 considered as a decimal fraction.
> 
> Sean Case
> 
> 
> 
> --
> 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