[fpc-pascal] Floating point question
Ern Aldo
pasfrelst at dyadic.org
Sat Feb 17 02:12:21 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:
>>> 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?
> Bernd: I don't know exactly, what you mean by constant propagation.
I believe this question is a red herring. In case "constant propagation" is an
optimization aimed primarily at run-time program code (this is mainly why
compilers exist) then it doesn't exactly apply to compile-time math, aka
compile-time execution of non-program code. In other words, compile-time
execution for the purpose of solving compiler math (not program math) could be
done entirely without any optimizations at all. If this would preserve
compiler-math correctness and/or make it match run-time program-math
correctness then it would yes be worth doing.
> James Richters: The result of math when using constants MUST be the same as
> the result of identical math using variables.
Agree.
> if the developer explicitly wants reduced precision, then [that's fine].
Agree.
> But reduced precision should not come unexpectedly
Agree.
It is possible math is being done differently by the compiler than by programs?
For math-related source code, the compiler compiles the instructions and writes
them to the program file for execution at runtime. For compile-time constant
calculations that produce run-time constant values, one would expect the
compiler to compile the instructions, execute them during compilation, and
write the resulting value to the program file for use at runtime. Such
instructions are discarded, because the program does not need them. If math is
being compiled differently for program-executed calculations versus
compiler-executed calculations, then that would be a problem.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20240216/8e3bdd2c/attachment.htm>
More information about the fpc-pascal
mailing list