On Mon, Oct 19, 2009 at 02:57:10PM -0300, Gustavo Enrique Jimenez wrote: > 2009/10/18 Tom Verhoeff <t.verho...@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.
No, that is just the point. The "easy" formula is actually not not correct for zero resistors when adopting classical evaluation rules. However, it works out fine with infinities. Take the case of two resistors 1/(1/R1 + 1/R2) = R1 R2 / (R1 + R2) The left-hand side is continuous at R1=0 and at R2=0, but strictly speaking not defined in those points. The formula on the right is the same for R1, R2 not zero and it does not have a problem at R1=0 or R2=0 (unless R1=R2=0). For more than two resistors, rewriting as in the right-hand side is (practically) out of the question, but the same holds. Point is that for such rational functions, the use of infinities is well-defined and works well. Numericists want to evaluate the left-hand side, rather than doing a case analysis or rewriting it. 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 _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal