[fpc-pascal] Division by Zero: EDivByZero and EZeroDivide
Tom Verhoeff
T.Verhoeff at tue.nl
Mon Oct 19 11:07:41 CEST 2009
On Sun, Oct 18, 2009 at 02:49:40PM -0200, Jorge Aldo G. de F. Junior wrote:
> Wouldnt a NaN (Not a number) be more "matematically correct" result (I saw
> that on an old book about i387)
No, read Kahan's article that I pointed to.
> Matematically division by zero is an "mathematical impossibility", so NaN
> would be more logical
There are situations (that occur e.g. in numerical approximations of
mathematical models in physics) where division by zero is a well-defined
infinity. For that reason, the IEEE 754 floating-point standard has
distinct plus zero, minus zero, plus infinity, and minus infinity.
There are precise (and useful) rules to calculate with these special
numbers. They are not NaNs.
Many processors fully support the IEEE 754 standard, but many compilers
don't. Partial support of the standard in the compiler makes the standard
much less useful.
In our department, especially the numericists disliked (the old)
Pascal because of the fixed array sizes and the lack of good support
for floating-point arithmetic (i.e. IEEE 754 since 1985). I guess few
(Free)Pascal users nowadays come from the numerical/scientific computing
community.
Another (longish) "must read" about floating-point:
David Goldberg.
"What Every Computer Scientist Should Know about Floating-Point Arithmetic".
<http://www.validlab.com/goldberg/paper.ps>
Note that IEEE Std 754 was revised in 2008, see e.g.
<http://en.wikipedia.org/wiki/IEEE_754-2008>
Best regards,
Tom
--
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
mailing list