[Oberon] real math
oberon at moravcik.info
oberon at moravcik.info
Thu Nov 13 12:47:38 CET 2014
Hi Jörg,
just tested your code below and it outputs again 480....32 as in my other email I sent today.
Basically I need to test that 480/100*100 is 480 without some decimal digits at the end
because I am comparing two computed real numbers if they are less, greater or equal.
Comparing 480.0 with 480.0...32 does not make those two equal.
I rounded the computed real numbers to 2 decimal digits which is enough precision in my case.
This way the problem was solved but I do not think this is the general solution.
Note that linux gcc compiler returns 480
printf("result: %3.15f", 480.0/100.0*100.0);
Zdenek
On Mon, Nov 10, 2014 at 06:50:02PM +0100, Jörg wrote:
>
> 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
> --
> 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