Q: how to detect a overflow (or underflow) floating point calculation?

Q: how to detect a overflow (or underflow) floating point calculation?

Post by Ma » Sun, 15 Jun 2003 09:43:21



Hi,

I want to detect an overflow (or underfolow) floating point
calculation.  Do you know how?

I figure out a way below but it just partly works (only for
SW_ZERODIVIDE events). In the code below, d2 is apparently overflow.
But ui gets a value of zero instead of _SW_OVERFLOW (0x00000004) when
I debug the code.  If I change d1 to 0., then ui is _SW_ZERODIVIDE
(0x00000008) as desired.  Do you know why? Thanks for any advise.
Tony

_clearfp();
double d1 = 100.;
double d2 = DBL_MAX * d1;
unsigned int ui = _statusfp();
if (ui > 1)
{
  // handle the error
  .....

Quote:}

 
 
 

Q: how to detect a overflow (or underflow) floating point calculation?

Post by Barry S. Kyke » Sun, 15 Jun 2003 11:54:13


_fpclass

--
Best regards,

Barry S. Kyker


Quote:> Hi,

> I want to detect an overflow (or underfolow) floating point
> calculation.  Do you know how?

> I figure out a way below but it just partly works (only for
> SW_ZERODIVIDE events). In the code below, d2 is apparently overflow.
> But ui gets a value of zero instead of _SW_OVERFLOW (0x00000004) when
> I debug the code.  If I change d1 to 0., then ui is _SW_ZERODIVIDE
> (0x00000008) as desired.  Do you know why? Thanks for any advise.
> Tony

> _clearfp();
> double d1 = 100.;
> double d2 = DBL_MAX * d1;
> unsigned int ui = _statusfp();
> if (ui > 1)
> {
>   // handle the error
>   .....
> }