[fpc-pascal] Floating point question

Bernd Oppolzer bernd.oppolzer at t-online.de
Sat Feb 17 16:53:39 CET 2024


Am 17.02.2024 um 16:38 schrieb Bernd Oppolzer:
>
> IMO, a compiler switch that gives all FP constants the best available 
> precision would solve the problem -
> BTW: WITHOUT forcing expressions where they appear to use this 
> precision, if the other parts of the expression
> have lower precision.
>
> In fact, when parsing and compiling the expressions, you always can 
> break the problem down to TWO operands
> that you have to consider, and if one of them is a literal constant, 
> it should not force the type of the operation to
> a higher precision ... that's what I would do.
>
>
Commenting on my own post (this time):

const xs : single = 1440.5;
       xd : double = 1440.5;
       xu = 1440.5;              /* double or single, depending on new 
option */
       z : single = 33.0;

y1 := xs / z;   { single precision }
y2 := xd / z;   { double precision }
y3 := xu / z;   { different result, depending on new option }
y4 := 1440.5 / z;   { single, because z dictates it, independent of 
option }
y5 := 1440.1 / z;   { IMO: single, because z dictates it, independent of 
option }
y6 := 1440.5 / 33.0;   { depending on new option }


This may be in contrast to what's today done in FPC,
but that's how I (personally) would like to have it done.
Maybe the behaviour without the new option set is the same as now.

Not sure about y5.

Kind regards

Bernd







More information about the fpc-pascal mailing list