<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link="#0563C1" vlink="#954F72"><div class=WordSection1><p class=MsoNormal>I’ve been updating my old programs to use the MATH unit in freepascal and while testing things I came across a runtime error 217 Invalid floating point operation. Here is my test program<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><span style='color:#00B050'>Uses math;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#00B050'>var<o:p></o:p></span></p><p class=MsoNormal><span style='color:#00B050'> variable1:double;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#00B050'> variable2:double;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#00B050'>Begin<o:p></o:p></span></p><p class=MsoNormal><span style='color:#00B050'>variable1:= Infinity;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#00B050'>variable2:= -1*Infinity;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#00B050'>Writeln(variable1,' ',Variable2,' ',Variable1+Variable2);<o:p></o:p></span></p><p class=MsoNormal><span style='color:#00B050'>End.<o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>My output is:<o:p></o:p></p><p class=MsoNormal><span style='color:#0070C0'>Running "i:\programming\test\testmath.exe "<o:p></o:p></span></p><p class=MsoNormal><span style='color:#0070C0'>An unhandled exception occurred at $004015F6:<o:p></o:p></span></p><p class=MsoNormal><span style='color:#0070C0'>EInvalidOp: Invalid floating point operation<o:p></o:p></span></p><p class=MsoNormal><span style='color:#0070C0'> $004015F6 main, line 8 of i:/programming/test/testmath.pas<o:p></o:p></span></p><p class=MsoNormal><span style='color:#0070C0'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#0070C0'> +Inf -Inf<o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>According to the link here: <a href="https://en.wikipedia.org/wiki/NaN">https://en.wikipedia.org/wiki/NaN</a> <o:p></o:p></p><p class=MsoNormal>NaN should be produced:<o:p></o:p></p><p class=MsoNormal>The additions (+∞) + (−∞), (−∞) + (+∞) and equivalent subtractions (+∞) − (+∞) and (−∞) − (−∞).<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I can do things like +infinity*2 and +infinity-3 and even sqr(infinity) and power(infinity,10) the results are still +Inf which is expected… but I can’t do anything involving subtracting infinity from infinity. Here is another test program that illustrates this more clearly:<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><span style='color:#00B050'>Uses math;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#00B050'>var<o:p></o:p></span></p><p class=MsoNormal><span style='color:#00B050'> variable1:double;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#00B050'> variable2:double;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#00B050'>Begin<o:p></o:p></span></p><p class=MsoNormal><span style='color:#00B050'>variable1:= 1/0;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#00B050'>variable2:= -1/0;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#00B050'>Writeln(' V1',variable1);<o:p></o:p></span></p><p class=MsoNormal><span style='color:#00B050'>Writeln(' V2',variable2);<o:p></o:p></span></p><p class=MsoNormal><span style='color:#00B050'>Writeln(' SQRT(-1)',Sqrt(-1));<o:p></o:p></span></p><p class=MsoNormal><span style='color:#00B050'>Writeln(' V1*V1',variable1*variable1);<o:p></o:p></span></p><p class=MsoNormal><span style='color:#00B050'>Writeln(' V1*V2',variable1*variable2);<o:p></o:p></span></p><p class=MsoNormal><span style='color:#00B050'>Writeln(' V1+3',variable1+3);<o:p></o:p></span></p><p class=MsoNormal><span style='color:#00B050'>Writeln(' V1+V1',variable1+variable1);<o:p></o:p></span></p><p class=MsoNormal><span style='color:#00B050'>Writeln(' V1-3',variable1-3);<o:p></o:p></span></p><p class=MsoNormal><span style='color:#00B050'>Writeln(' Sqr(V1)',Sqr(Variable1));<o:p></o:p></span></p><p class=MsoNormal><span style='color:#00B050'>Writeln(' Sqr(V2)',Sqr(Variable2));<o:p></o:p></span></p><p class=MsoNormal><span style='color:#00B050'>Writeln(' Sqrt(-1)',Sqrt(-1));<o:p></o:p></span></p><p class=MsoNormal><span style='color:#00B050'>Writeln(' Sqrt(V1)',Sqrt(Variable1));<o:p></o:p></span></p><p class=MsoNormal><span style='color:#00B050'>Writeln('Power(V1,10)',Power(Variable1,10));<o:p></o:p></span></p><p class=MsoNormal><span style='color:#00B050'>Writeln(' ABS(V2)',ABS(Variable2));<o:p></o:p></span></p><p class=MsoNormal><span style='color:#00B050'>Writeln(' Sqrt(-1*V1)',Sqrt(-1*Variable1));//runtime error 217 Should be NAN<o:p></o:p></span></p><p class=MsoNormal><span style='color:#00B050'>Writeln(' Sqrt(V2)',Sqrt(Variable2)); //runtime error 217 Should be NAN<o:p></o:p></span></p><p class=MsoNormal><span style='color:#00B050'>Writeln(' V1-V1',variable1-variable1); //runtime error 217 Should be NAN<o:p></o:p></span></p><p class=MsoNormal><span style='color:#00B050'>Writeln(' V1+V2',variable1+variable2); //runtime error 217 Should be NAN<o:p></o:p></span></p><p class=MsoNormal><span style='color:#00B050'>End.</span><o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><span style='color:#0070C0'>Running "i:\programming\test\testmath.exe "<o:p></o:p></span></p><p class=MsoNormal><span style='color:#0070C0'> V1 +Inf<o:p></o:p></span></p><p class=MsoNormal><span style='color:#0070C0'> V2 -Inf<o:p></o:p></span></p><p class=MsoNormal><span style='color:#0070C0'> SQRT(-1) Nan<o:p></o:p></span></p><p class=MsoNormal><span style='color:#0070C0'> V1*V1 +Inf<o:p></o:p></span></p><p class=MsoNormal><span style='color:#0070C0'> V1*V2 -Inf<o:p></o:p></span></p><p class=MsoNormal><span style='color:#0070C0'> V1+3 +Inf<o:p></o:p></span></p><p class=MsoNormal><span style='color:#0070C0'> V1+V1 +Inf<o:p></o:p></span></p><p class=MsoNormal><span style='color:#0070C0'> V1-3 +Inf<o:p></o:p></span></p><p class=MsoNormal><span style='color:#0070C0'> Sqr(V1) +Inf<o:p></o:p></span></p><p class=MsoNormal><span style='color:#0070C0'> Sqr(V2) +Inf<o:p></o:p></span></p><p class=MsoNormal><span style='color:#0070C0'> Sqrt(-1) Nan<o:p></o:p></span></p><p class=MsoNormal><span style='color:#0070C0'> Sqrt(V1) +Inf<o:p></o:p></span></p><p class=MsoNormal><span style='color:#0070C0'>Power(V1,10) +Inf<o:p></o:p></span></p><p class=MsoNormal><span style='color:#0070C0'> ABS(V2) +Inf<o:p></o:p></span></p><p class=MsoNormal><span style='color:#0070C0'>An unhandled exception occurred at $00401A43:<o:p></o:p></span></p><p class=MsoNormal><span style='color:#0070C0'>EInvalidOp: Invalid floating point operation<o:p></o:p></span></p><p class=MsoNormal><span style='color:#0070C0'> $00401A43 main, line 22 of I:/Programming/Test/testmath.pas<o:p></o:p></span></p><p class=MsoNormal><span style='color:#0070C0'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#0070C0'> Sqrt(-1*V1)</span><o:p></o:p></p><p class=MsoNormal>It seems to me that the whole purpose of +Inf, -Inf, and NaN was so you could evaluate complex formulas and NOT get a runtime error… Is this behavior just a bug that should be reported? Testing was done with V3.0.4<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>James<o:p></o:p></p></div></body></html>