[fpc-pascal] FORTRAN from FreePascal

Santiago A. svaa at ciberpiula.net
Tue Nov 21 12:20:20 CET 2017

El 19/11/2017 a las 11:06, Adriaan van Os escribió:
> Mark Morgan Lloyd wrote:
>> That obviously applies to all languages, I've never come across
>> something which can represent 1/3 or pi exactly.
> If you do read what is written in the link - that is not the issue.
> The issue is how to interpret floating-point constants and how to
> convert single-precision floating-point to decimal. In BCD, that
> conversion is exact.

No. It is not.

n := 1 - (1/3) - (1/3) - (1/3);

n:=1.000000 - 0.333333 - 0.333333 - 0.333333;

n is never zero, no matter what representation you pick, unless you
have  infinite digits.

The problem is that periodic numbers can't be stored without infinite
digits. And the second problem is that depending upon the base, binary,
decimal, hex, have different periodic numbers and, unfortunately, 1/10,
in base 10, is periodic number in binary.

So you are right 0.10 can't be represented with an exact value in
floating-point, but it can be represented with exact value in BCD
(nevertheless,  you can represent 1/10 with an exact constant but not
1/3) . But internal operations won't be executed in BCD but using the
floating-point processor representation, so, the aftermath is the same.

Once I played with fraction representation, just for fun


Except for irrational numbers pi, e, etc, it had full precision.
Obviously  it was too slow. And, by the way, BCD is also too slow for
numeric operations.


Santiago A.

More information about the fpc-pascal mailing list