[fpc-pascal] round(2.5)=2
Klaus Hartnegg
hartnegg at gmx.de
Tue Jun 12 23:11:54 CEST 2018
Am 12.06.2018 um 09:01 schrieb Mattias Gaertner:
>> IMHO this is not really relevant, as relying on the exact value of a
>> real number is erroneous, anyway. So a real number never can be
>> considered to *exactly* *be* 1.5, but just somewhere nearby, and hence
>> it's not legal to predict hat it is rounded to.
>
> Floats can represent 1.5 exactly.
Yes. And such numbers do pop up all the time.
That mathematical theory is only valid for measured values. If measured
with unlimited precision.
Then you could arbitrarily define round(1.5)=9, and nobody would ever
notice. Because the chance would be zero that a variable ever has that
exact value.
But we do not only store measured values in variables. And we often
measure with low precision. That's why this is relevant.
When I got different results from the FreePascal port of my source, it
took me quite a while until I found the cause in the compiler. Because
that is typically not the first place to look at.
Klaus
More information about the fpc-pascal
mailing list