<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div class="moz-cite-prefix">Am 17.02.2024 um 02:12 schrieb Ern Aldo
via fpc-pascal:<br>
</div>
<blockquote type="cite"
cite="mid:4770101a-61fd-bc43-5e1e-0e4a1680365d@dyadic.org">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<br>
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.<br>
<br>
</blockquote>
<p>I'll try to comment on this using some source code which
hopefully does conform to FPC, <br>
but I am not sure, because I am not familiar with FPC standards.
Please look: <br>
</p>
<pre class="moz-quote-pre" wrap="">Const
A_const = Integer(8427);
B_const = Byte(33);
C_const = Single(1440.5);
y1 := A_const + C_const / B_const;
y2 := 8427 + 1440.5 / 33;
</pre>
In my understanding, in the first assignment the constants have
types, which are given to themĀ <br>
by the const declarations. And that's why the computation is done
using single precision. <br>
This would be OK for me, because the developers decided to do the
definitions this way,<br>
and so he or she takes responsibility. <br>
If the computation is done at run time or at compile time, DOESN'T
MATTER. <br>
<p>In the second case, using literal constants, the compiler should
do the math using the maximum <br>
precision available (IMO), because one constant (1440.5) has a FP
representation. It does and should <br>
not matter, that this constant can be stored exactly in a single
FP field. Here again: <br>
If the computation is done at run time or at compile time, DOESN'T
MATTER. <br>
</p>
<p>Maybe this is not how FPC works today, but IMO this is how it
should be done, because we want <br>
(IMO) Pascal to be a clear language which is simple to explain,
easy to use and easy to implement. <br>
<br>
The case would be different, of course, if you do the same casting
in the y2 case as in the const <br>
declarations. <br>
</p>
<p>Kind regards</p>
<p>Bernd <br>
</p>
<p></p>
<p><br>
</p>
<blockquote type="cite"
cite="mid:4770101a-61fd-bc43-5e1e-0e4a1680365d@dyadic.org"><span
style="white-space: pre-wrap">
</span></blockquote>
</body>
</html>