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

Frank Peelo f26p at eircom.net
Tue Oct 20 00:20:50 CEST 2009


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

Frank




More information about the fpc-pascal mailing list