[Oberon] real math
drrob106 at verizon.net
Mon Nov 10 13:50:22 CET 2014
AFAIK, my hp calculators use 13 digits internally, but only display 10.
I always assumed that the display is rounded.
I have gotten the behaviour you seek by rounding
On 11/10/2014 06:30 AM, oberon at moravcik.info wrote:
> "...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!
> 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
>>> 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:
>> "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."
>> Chris Burrows
>> CFB Software
>> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
More information about the Oberon