[fpc-pascal] Division by Zero: EDivByZero and EZeroDivide

Tom Verhoeff T.Verhoeff at tue.nl
Tue Oct 20 14:04:47 CEST 2009


On Mon, Oct 19, 2009 at 11:20:50PM +0100, Frank Peelo wrote:
> Gustavo Enrique Jimenez wrote:
>> 2009/10/18 Tom Verhoeff <T.Verhoeff at tue.nl>:
>>> A simple example is the situation where one needs to calculate
>>> the replacement resistor value R for parallel resistors having
>>> values R1, R2, ..., Rk.  The formula is R = 1/(1/R1 + 1/R2 + ... + 1/Rk).
>>> The formula gives a divide-by-zero if one of the resistors has value 0.
>>> But in that case, the replacement value R also equals 0.  When allowing
>>> infinities, it just works out fine (infinity + x = infinity, 1/infty = 0).
>>> That is precisely why IEEE 754 has infinities.  Also see
>>>
>>>        <http://www.cs.berkeley.edu/~wkahan/ieee754status/why-ieee.pdf>
>>>
>>> for other examples and further motivation.
>>
>> Mmm... the formula R = 1/(1/R1 + 1/R2 + ... + 1/Rk) is only valid if
>> none of Rn=0.
>> Programmers can and must take care of that situation.
>
> Agree: treating 1/0 as you would treat a finite number makes me feel  
> uncomfortable. See for instance
> http://www.cocoa.uk.com/?p=63

One final comment here.  The field of scientific computing, including
numerical methods, is a specialism by itself, and there are many
misunderstandings about it.  Respected experts from this field (including
William Kahan) have developed a floating-point standard and have been
able to convince hardware builders to implement this standard in their
(co)processors.  Compiler writers would do well to trust those experts,
especially if they do not understand them.

So, yes 1/0 is not a finite number, but a (signed) infinity: 1/+0 = +Inf,
1/-0 = -Inf.  Yes, there are two 0s among the floating-point numbers,
and they are all well-behaved, and some operators work (1 + +Inf = +Inf),
and others do not (+Inf + -Inf is undefined).  With good reasons.

Not everybody needs to be a floating-point expert, but compiler users
that do know about this, would want to use the IEEE 754 standard, because
it makes life so much simpler for them.  That may be the reason why
FORTRAN is still used in scientific computing (robust numerical libraries
and good support in the compiler; but otherwise not a language I can like).

	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