[fpc-pascal] Why this evaluates on "if" wrong ?
Daniël Mantione
daniel.mantione at freepascal.org
Sun Oct 28 19:38:38 CET 2007
Op Sun, 28 Oct 2007, schreef Joao Morais:
> Daniël Mantione wrote:
> > There is a similar issue here. The value "0.4" cannot be stored exactly
> > in a computer, therefore it is rounded.
> >
> > This behaviour normal and while annoying, it is simply how things work in
> > the digital world, you will have to work around it.
>
> Or, of course, use a scaled integer type like Currency.
This is indeed a question you should ask, but you should generalize it. In
mathematics we consider several groups of numbers:
N - Natural numbers
Z - Integer numbers
Q - Rational numbers
R - Real numbers
C - Complex numbers
Subranges of N, Z and Q can be represented exactly in a computer. R and C
can not, we use the floating point system as approximation. Very often, a
certain calculation that on the first sight might tempt one to use a real,
can be performed in N or Q. In such case floating point is overkill and
thus, you can save yourself a lot of trouble by calculating it in N or Q.
Daniël
More information about the fpc-pascal
mailing list