[fpc-pascal] Re: Why this evaluates on "if" wrong ?
T.Verhoeff at tue.nl
Mon Oct 29 15:41:11 CET 2007
On Mon, Oct 29, 2007 at 07:30:03AM -0700, L wrote:
> > It's just one more funny thing one must realize,
> > when comparing real numbers with some exact
> > real constants. After this, I will try to never
> > compare doubles directly, but using tricks like
> > above. Because, in this digital world
> > 1 + 0.4 - 0.4 <> 1.
> My opinion:
> This is ludicrous.
> The end user is using a high level language and should not care whether the
> computer is digital or analog.
Unfortunately, there is a problem. One can try to hide it (as calculators
attempt to do), but in the longer run that is going to be unsuccessful
and even dangerous.
The mathematical structures of floating point numbers and of real numbers
do not match, and cannot be made to match faithfully.
See e.g. any good textbook on numerical mathematics. However, most
of those texts are not so accessible to the layman. I have written
a short article on it for secondary educations, that I hope is more
Gyula Horvath, Tom Verhoeff.
``Numerical Difficulties in Pre-University Informatics Education
Informatics in Education, Vol. 2, Number 1, pp.21-38.
URL checked OK
(Sidenote: If your program only needs to deal with decimal fractions,
then it is stronly advised not to use Real/Single/Double, but e.g. Currency.
Floating-point numbers are useful in scientific and engineering applications.)
E-MAIL: T.Verhoeff @ TUE.NL | Dept. of Math. & Comp. Science
PHONE: +31 40 247 41 25 | Technische Universiteit Eindhoven
FAX: +31 40 247 54 04 | PO Box 513, NL-5600 MB Eindhoven
http://www.win.tue.nl/~wstomv/ | The Netherlands
More information about the fpc-pascal