Chris Gatcombe
2008-08-01 15:26:51 UTC
Hi,
I have some legacy code (BCB6) using pow() which is giving me an
overflow error. It appears like a MessageBox() popup with the text "pow:
OVERFLOW error", but I do not see anything like this anywhere in my
source code.
Try/Catch does not seem to do anything, and I'm not using _matherr() or
any of the 8087 FPU control functions. Even if I do use _matherr() I
still can't catch the overflow.
My code looks like this:
[DebugPrintThreadId() prints a debug message to the error/event log]
[f64 is a typedef for double]
f64
qc_pow(
f64 const in_x,
f64 const in_y)
{
.
.
.
DebugPrintThreadId(fname,"Begin");
f64 retval;
msg = "in_x = " + to_str(in_x) + ", in_y = " + to_str(in_y);
DebugPrintThreadId(fname,msg);
DebugPrintThreadId(fname,"Calling pow()...");
errno = 0;
try
{
if (in_x > 1e200) DebugPrintThreadId(fname,"in_x too big");
if (in_y > 200) DebugPrintThreadId(fname,"in_y too big");
retval = std::pow(in_x,in_y);
}
catch (...)
{
DebugPrintThreadId(fname,"Caught exception");
if (in_x < 0) retval = -std::numeric_limits<f64>::max();
if (in_x > 0) retval = std::numeric_limits<f64>::max();
}
DebugPrintThreadId(fname,"...returned from pow()");
msg = "errno = " + to_str(errno);
DebugPrintThreadId(fname,msg);
.
.
.
}
My error log looks like this:
.
.
[qc_pow] Begin
[qc_pow] in_x = 10, in_y = 321.864
[qc_pow] Calling pow()...
[qc_pow] in_y too big
.
.
There is no message from the catch block, nor from the final "..returned
from" message. Its like qc_pow() just aborted.
What am I missing (or misunderstanding) here?
Thanks,
Chris.
I have some legacy code (BCB6) using pow() which is giving me an
overflow error. It appears like a MessageBox() popup with the text "pow:
OVERFLOW error", but I do not see anything like this anywhere in my
source code.
Try/Catch does not seem to do anything, and I'm not using _matherr() or
any of the 8087 FPU control functions. Even if I do use _matherr() I
still can't catch the overflow.
My code looks like this:
[DebugPrintThreadId() prints a debug message to the error/event log]
[f64 is a typedef for double]
f64
qc_pow(
f64 const in_x,
f64 const in_y)
{
.
.
.
DebugPrintThreadId(fname,"Begin");
f64 retval;
msg = "in_x = " + to_str(in_x) + ", in_y = " + to_str(in_y);
DebugPrintThreadId(fname,msg);
DebugPrintThreadId(fname,"Calling pow()...");
errno = 0;
try
{
if (in_x > 1e200) DebugPrintThreadId(fname,"in_x too big");
if (in_y > 200) DebugPrintThreadId(fname,"in_y too big");
retval = std::pow(in_x,in_y);
}
catch (...)
{
DebugPrintThreadId(fname,"Caught exception");
if (in_x < 0) retval = -std::numeric_limits<f64>::max();
if (in_x > 0) retval = std::numeric_limits<f64>::max();
}
DebugPrintThreadId(fname,"...returned from pow()");
msg = "errno = " + to_str(errno);
DebugPrintThreadId(fname,msg);
.
.
.
}
My error log looks like this:
.
.
[qc_pow] Begin
[qc_pow] in_x = 10, in_y = 321.864
[qc_pow] Calling pow()...
[qc_pow] in_y too big
.
.
There is no message from the catch block, nor from the final "..returned
from" message. Its like qc_pow() just aborted.
What am I missing (or misunderstanding) here?
Thanks,
Chris.