编程论坛's Archiver

kevin8888 发表于 2006-5-28 10:19

请教溢出检测

<P 0pt? 0cm>有一个<FONT face="Times New Roman">C++</FONT>函数(不是<FONT face="Times New Roman">VC</FONT>),里面有很多算法,运行时有可能出现溢出(如分母为零,求绝对值大于1的反三角函数asin等)的情况,我希望溢出时能给出提示,我试过<FONT face="Times New Roman">try-catch(…)</FONT>,但好象不好用,谁能帮我解决这个问题?能做个试验吗?谢谢!</P>
<P 0pt? 0cm>例如:</P>
<P 0pt? 0cm><FONT face="Times New Roman">function(double a,double b,double c,)</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">{</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">  try</FONT></P>
<P 0cm 10.5pt? mso-char-indent-size: 1.0; mso-char-indent-count: 10.5pt; TEXT-INDENT: 0pt;><FONT face="Times New Roman">{</FONT></P>
<P 0cm 10.5pt? mso-char-indent-size: 1.0; mso-char-indent-count: 10.5pt; TEXT-INDENT: 0pt;><FONT face="Times New Roman">    …</FONT></P>
<P 0cm 10.5pt? mso-char-indent-size: 1.0; mso-char-indent-count: 10.5pt; TEXT-INDENT: 0pt;><FONT face="Times New Roman">    …</FONT></P>
<P 0cm 10.5pt? mso-char-indent-size: mso-char-indent-count: TEXT-INDENT: 0pt; 3.0; 31.5pt;><FONT face="Times New Roman">c=a/b;      //b可能</FONT>为零</P>
<P 0cm 10.5pt? mso-char-indent-size: mso-char-indent-count: TEXT-INDENT: 0pt; 3.0; 31.5pt;><FONT face="Times New Roman">…</FONT></P>
<P 0cm 10.5pt? mso-char-indent-size: mso-char-indent-count: TEXT-INDENT: 0pt; 3.0; 31.5pt;><FONT face="Times New Roman">...</FONT></P>
<P 0cm 10.5pt? mso-char-indent-size: 1.0; mso-char-indent-count: 10.5pt; TEXT-INDENT: 0pt;><FONT face="Times New Roman">}</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman"><O:P></O:P></FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">  catch(…)</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">  {</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">    …</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">    …</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">  }</FONT></P>
<P 0pt? 0cm><FONT face="Times New Roman">}</FONT></P>

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.