[Oberon] real math
oberon at moravcik.info
oberon at moravcik.info
Mon Nov 10 12:30:02 CET 2014
"...As a consequence, computations involving floating-point values are inexact because each operation may be subject to truncation."
Yes I know that, but why is it that my scientific hand calculator does the same operation correctly?
480 / 100 * 100 = 480 (integer!) This calculator has 10 digits.
Are calculators using other algorithms?
Maybe there are digits after decimal point that are always exact and after it the numbers are inexact.
I would need to know how many digits are exact for REAL and for LONGREAL?
That would probably solve my problem because I really need to check that 480 / 100 * 100 is integer number 480 again!
Thanks
Zdenek
On Mon, Nov 10, 2014 at 08:04:17AM +1030, Chris Burrows wrote:
>
> > -----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
>
>
>
>
> --
> 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