Am 17.02.2024 um 14:38 schrieb Michael Van Canneyt via fpc-pascal:
There can be discussion about the rules that the compiler uses when it
chooses a type, but any given set of rules will always have
consequences that may or may not be desirable.
Possibly some compiler switches can be invented that modify the
compiler's
rules for the constant type to use.
If the rules at the moment make this a single:
const xs = 64.015625; { 64 + 1 / 64 }
because it can be represented correctly (without rounding error) in a
binary single FP IEEE representation,
and this a double or extended type:
const xd = 64.1; { no finite representation in binary or hex }
with all the observed effects on computations that the other posters
here have pointed out
my personal opinion would be:
- never use such (implicitly typed) definitions ... but that's standard
Pascal, after all
- try to convince the compiler builders that we need a better solution here
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.
That's why I write all those mails (although I am not an active FPC
user), because I want all Pascal versions around
to implement a clear and UNDERSTANDABLE language without strange effects.
Kind regards
Bernd
(incidentally, this is one of the reasons the FPC team does not want
to make
inline variables as Delphi does, since there the type will again be
determined by
the compiler - just as for constants, leading to ambiguity...)
Michael.
_______________________________________________
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