[Oberon] real math
Jörg
joerg.straube at iaeth.ch
Mon Nov 10 18:50:02 CET 2014
Hi Zdenek
I just compiled your code with AOS on Windows.
- - - -
MODULE RealTest;
IMPORT Commands;
PROCEDURE Do*(ctx: Commands.Context);
VAR
r: REAL;
BEGIN
r := 480 / 100 * 100;
ctx.out.Int( ENTIER(r*1000000), 0);
END Do;
BEGIN
END RealTest.Do ~
- - - - -
On my PC the output is 480000000. So, I don't have the same effect as you
have.
Generally, checking REALs on equality is a little dangerous. You should
rather subtract two REALs and check for an epsilon>0.
I wonder what the use case of your code is? What do you want to find out by
dividing 480 by 100 and multiplying it by 100 again. Do you want to round a
number to two digits?
br
Jörg
-----Original Message-----
From: oberon at moravcik.info [mailto:oberon at moravcik.info]
Sent: Sonntag, 9. November 2014 20:36
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 ?
Thanks
Zdenek
--
Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
https://lists.inf.ethz.ch/mailman/listinfo/oberon
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 6097 bytes
Desc: not available
Url : https://lists.inf.ethz.ch/pipermail/oberon/attachments/20141110/2ffd0b06/attachment.bin
More information about the Oberon
mailing list