[fpc-pascal] Floating point question

Bernd Oppolzer bernd.oppolzer at t-online.de
Fri Feb 16 15:34:05 CET 2024


Am 16.02.2024 um 08:32 schrieb Florian Klämpfl via fpc-pascal:
> Am 16.02.2024 um 08:23 schrieb Ern Aldo via fpc-pascal 
> <fpc-pascal at lists.freepascal.org>:
>>  Compile-time math needs to be as correct as possible. RUN-time math can worry about performance.
> So you are saying when constant propagation is on, an expression should have a different result than with constant propagation off?

I don't know exactly, what you mean by constant propagation.

But IMO, given this (sort of fictive) Pascal code snippet:


const Xconst : single = 1440.0;

var y1, y2 : real;

y1 := 33.0 / 1440.0;

y2 :=  33.0 / Xconst;


the division in the first assignment (to y1) should be done at maximum 
precision, that is,
both constants should be converted by the compiler to the maximum 
available precision and
the division should be done (best at compile time) using this precision.

in the second case, if the compiler supports constants of the reduced 
type (which I believe it does,
no matter how the syntax is), I find it acceptable if the computation is 
done using single precision,
because that's what the developer calls for.

So probably the answer to your question is: yes.

Kind regards

Bernd




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20240216/9e4c7d68/attachment.htm>


More information about the fpc-pascal mailing list