[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Gm2] GCC / GM2 Optimizer
From: |
Waldek Hebisch |
Subject: |
Re: [Gm2] GCC / GM2 Optimizer |
Date: |
Tue, 1 Dec 2015 03:13:00 +0100 (CET) |
Michael Riedl wrote:
>
> Hallo Gaius,
>
> another curious result.
>
> MODULE TestMachEps;
>
> FROM STextIO IMPORT WriteLn;
> FROM SLongIO IMPORT WriteFloat;
>
> PROCEDURE MachEps() : LONGREAL;
>
> VAR eps,EinsPlusEps : LONGREAL;
> BEGIN
> eps:=3D0.5; EinsPlusEps:=3D1.5;
> WHILE (EinsPlusEps # 1.0) DO
> eps:=3D0.5*eps;
> EinsPlusEps:=3D1.0+eps;
> END;
> RETURN 2.0*eps;
> END MachEps;
>
> VAR eps : LONGREAL;
>
> BEGIN
> eps :=3D MachEps();
>
> WriteLn; WriteLn;
> WriteString(" MachEps =3D "); WriteFloat(eps,20,10);
> WriteLn; WriteLn;
> END TestMachEps.
>
> Compile attached with -O0 and with -O2. In the latter the machine=20
> precision equals to zero ...
> By the way - same behavior with REAL.
This is classic example of nonportable program which may work
or not depending on optimization settings/machine. In short:
in the loop compiler may use higher precision (normal on
32-bit Intel processors). At return higher precision results
gets rounded to lower precision. Due to underflow this gives
0. You should get result you expect using SSE math, maybe
Gfortran uses this by default...
--
Waldek Hebisch