In this example below, the performance argument does not count IMO,
because the complete computation can be done at compile time.
That's why IMO in all 3 cases the values on the right side should be
computed with
maximum precision (of course independent of the left side), and in an
ideal world
it should be done at compile time. But if not: anyway with max precision.
Tagging the FP constants with FP attributes like single, double and
extended and
then doing arithmetic on them which leads to MATHEMATICAL results which
are unexpected
is IMO wrong and would not be accepted in most other programming
languages or compilers.
This is NOT about variables ... they have attributes and there you can
explain all sort of
strange behaviour. It's about CONSTANT EXPRESSIONS (which can and should
be evaluated
at compile time, and the result should be the same, no matter if the
evaluation is done at
compile time or not).
That said:
if you have arithmetic involving a single variable and a FP constant, say
x + 1440.0
you don't need to handle this as an extended arithmetic IMO, if you
accept my statement above.
You can treat the 1440.0 as a single constant in this case, if you wish.
It's all about context ...
Kind regards
Bernd
Am 12.02.2024 um 10:44 schrieb Thomas Kurz via fpc-pascal:
I wouldn't say so. Or at least, not generally. Why can't the compiler do what
the programer intends to do:
var
s: single;
d: double;
e: extended;
begin
s := 8427.0 + 33.0 / 1440.0; // treat all constants all "single"
d := 8427.0 + 33.0 / 1440.0; // treat all constants all "double"
e := 8427.0 + 33.0 / 1440.0; // treat all constants all "extended"
end.
Shouldn't this satisfy all the needs? Those caring for precision will work with
double precision and don't have to take care for a loss in precision. Those
caring for speed can use the single precision type and be sure that no costly
conversion to double or extended will take place.
----- Original Message -----
From: Jonas Maebe via fpc-pascal <fpc-pascal@lists.freepascal.org>
To: fpc-pascal@lists.freepascal.org <fpc-pascal@lists.freepascal.org>
Sent: Sunday, February 11, 2024, 23:29:42
Subject: [fpc-pascal] Floating point question
On 11/02/2024 23:21, Bernd Oppolzer via fpc-pascal wrote:
and this would IMHO be the solution which is the easiest to document and
maybe to implement
and which would satisfy the users.
And generate the slowest code possible on most platforms.
Jonas
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal