Wouldnt a NaN (Not a number) be more "matematically correct" result (I saw that on an old book about i387)<br><br>Matematically division by zero is an "mathematical impossibility", so NaN would be more logical<br>
<br>Is there a way to deal with NaN's and other i387 (and similars) conventions directly in Pascal ?<br><br>Something like :<br><br>If A / B = NaN then something();<br><br><div class="gmail_quote">2009/10/18 Tom Verhoeff <span dir="ltr"><<a href="mailto:T.Verhoeff@tue.nl">T.Verhoeff@tue.nl</a>></span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">On Sat, Oct 17, 2009 at 01:57:28PM +0200, Bart wrote:<br>
><br>
> Is there a reason why in fpc both floating point and integer division<br>
> by zero raise an EDivByZero exception?<br>
><br>
> See: <a href="http://docwiki.embarcadero.com/VCL/en/SysUtils.EZeroDivide" target="_blank">http://docwiki.embarcadero.com/VCL/en/SysUtils.EZeroDivide</a><br>
><br>
> SysUtils.EZeroDivide exception is raised when an application attempts<br>
> to divide a floating-point value by zero.<br>
> Note: Integer divide-by-zero errors raise the SysUtils.EDivByZero exception.<br>
<br>
It would be nicer if one had the ability to make floating-point division<br>
by zero return an IEEE 754 plus/minus infinity, without raising an<br>
exception. This is e.g. useful when one needs to evaluate rational<br>
functions. Without such an infinity, you need to make a nasty case<br>
analysis, which furthermore depends on the rational function.<br>
<br>
A simple example is the situation where one needs to calculate<br>
the replacement resistor value R for parallel resistors having<br>
values R1, R2, ..., Rk. The formula is R = 1/(1/R1 + 1/R2 + ... + 1/Rk).<br>
The formula gives a divide-by-zero if one of the resistors has value 0.<br>
But in that case, the replacement value R also equals 0. When allowing<br>
infinities, it just works out fine (infinity + x = infinity, 1/infty = 0).<br>
That is precisely why IEEE 754 has infinities. Also see<br>
<br>
<<a href="http://www.cs.berkeley.edu/%7Ewkahan/ieee754status/why-ieee.pdf" target="_blank">http://www.cs.berkeley.edu/~wkahan/ieee754status/why-ieee.pdf</a>><br>
<br>
for other examples and further motivation.<br>
<br>
Unfortunately, many compilers still do not fully support the IEEE 754<br>
floating-point standard.<br>
<br>
Best regards,<br>
<br>
Tom<br>
<font color="#888888">--<br>
E-MAIL: T.Verhoeff @ <a href="http://TUE.NL" target="_blank">TUE.NL</a> | Dept. of Math. & Comp. Science<br>
PHONE: +31 40 247 41 25 | Technische Universiteit Eindhoven<br>
FAX: +31 40 247 54 04 | PO Box 513, NL-5600 MB Eindhoven<br>
<a href="http://www.win.tue.nl/%7Ewstomv/" target="_blank">http://www.win.tue.nl/~wstomv/</a> | The Netherlands<br>
_______________________________________________<br>
fpc-pascal maillist - <a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a><br>
<a href="http://lists.freepascal.org/mailman/listinfo/fpc-pascal" target="_blank">http://lists.freepascal.org/mailman/listinfo/fpc-pascal</a><br>
</font></blockquote></div><br>