[fpc-pascal] Loss of precision when using math.Max()

gtt at wolfgang-ehrhardt.de gtt at wolfgang-ehrhardt.de
Mon Jul 9 19:55:13 CEST 2018


Zitat von Martok <listbox at martoks-place.de>:
> To make sure this works, one has to manually make the const  
> expression be of the
> type required:
> const
>   e: Extended = Extended(1.0) / 3.0;
>
> I seem to remember that this was once documented somewhere for Delphi. Can't
> seem to find it though, so maybe it was a 3rd-party book? There is  
> no hint of it
> in the FPC documentation, anyway.

As already noted, it is not necessary in Delphi

D:\Work\TMP>D:\DMX\M18\DCC32 -b exttest.dpr
Embarcadero Delphi for Win32 compiler version 25.0
Copyright (c) 1983,2013 Embarcadero Technologies, Inc.
exttest.dpr(14)
15 lines, 0.00 seconds, 20816 bytes code, 13864 bytes data.
D:\Work\TMP>exttest
                   0.3333333433                  0.3333333433
             0.3333333333333333            0.3333333333333333
             0.3333333333333333            0.3333333333333333

And with Delphi Tokio 10.2.3 Starter

G:\TMP>bds -b exttest.dpr
G:\TMP>exttest.exe
                   0.3333333433                  0.3333333433
             0.3333333333333333            0.3333333333333333
             0.3333333333333333            0.3333333333333333

And I also wrote that the explicit type cast can only be used with
very new Delphi, e.g. compiler version 25 gives for

{$apptype console}
const
   x1: extended = extended(1.0)/3.0;
begin
   writeln(x1:30:16);
end.

D:\Work\TMP>b18 exttest2.dpr
D:\Work\TMP>D:\DMX\M18\DCC32 -b exttest2.dpr
Embarcadero Delphi for Win32 compiler version 25.0
Copyright (c) 1983,2013 Embarcadero Technologies, Inc.
exttest2.dpr(3) Error: E2089 Invalid typecast
exttest2.dpr(7)

Tokyo compiles without error, I do know now which was the
first version which allows the type cast.




More information about the fpc-pascal mailing list