MFC Floating Pt Error 
Author Message
 MFC Floating Pt Error

#include <float.h>
#include <math.h>
void myErrFn()
{
    double x, y, z;
    x =1.0;
    y = 0.0;
    z = x / y;
    int ierr = _fpclass(z);
    switch (ierr)
        {
        case _FPCLASS_PINF:
        . . . .
        }
    if (_isnan(z))
        {
        AfxMessage(......);
        }

Quote:
}

I simulated a [double xx =  1.0 DIV 0.0 ] and I got an 1.#J result under
debug which I think its correct. But if I trap the actual fperror code
using function _fpclass(xx) and the result is _FPCLASS_PZ (positive zero) --
should I not get _FPCLASS_PINF (positive infinity) instead?

Also I run the same routine twice in a row, the 1st instance I get an
_FPCLASS_PZ but the second time I cannot trap the _fpclass() return at all -
the _fpclass() does not seem to return any code as defined in the set
_FPCLASS_PZ _FPCLASS_NZ... etc... I have implemented the full set of
_FPCLASS_?? from float.h and checked with MSDN. So the switch fails!

Also, I tried [ -1.0 / 0.0 ] which gave -1.#J which is correct, but the
_fpclass() gives nothing -- ie gave a code that cannot be mapped into the
defined _FPCLASS_?? set as given in the documentation and in the float.h
file.

Similarly, _isnan() only works first time, 2nd time it does not indicate
that it is not a NAN, although I can see in debug that it is an 1.#J !

The whole float.h package appears confusing. . . .there are at least 4 sets
of different floating error codes - the _SW_???? , _FPCLASS_???? _EM_????
_FPE_????? ----> is there a better superset that I can use???

Must I do something else to detect what floating pt error is raised in
addition to using _fpclass()?



Mon, 01 Sep 2003 15:06:47 GMT  
 MFC Floating Pt Error
I thought IEEE 754 defines division by zero as NaN   .. try again
defining xyx as floats .. what may be getting you is the limit on sig
fig in double

Dave

On Wed, 14 Mar 2001 23:06:47 -0800, "Mick"

Quote:

>#include <float.h>
>#include <math.h>
>void myErrFn()
>{
>    double x, y, z;
>    x =1.0;
>    y = 0.0;
>    z = x / y;
>    int ierr = _fpclass(z);
>    switch (ierr)
>        {
>        case _FPCLASS_PINF:
>        . . . .
>        }
>    if (_isnan(z))
>        {
>        AfxMessage(......);
>        }
>}

>I simulated a [double xx =  1.0 DIV 0.0 ] and I got an 1.#J result under
>debug which I think its correct. But if I trap the actual fperror code
>using function _fpclass(xx) and the result is _FPCLASS_PZ (positive zero) --
>should I not get _FPCLASS_PINF (positive infinity) instead?

>Also I run the same routine twice in a row, the 1st instance I get an
>_FPCLASS_PZ but the second time I cannot trap the _fpclass() return at all -
>the _fpclass() does not seem to return any code as defined in the set
>_FPCLASS_PZ _FPCLASS_NZ... etc... I have implemented the full set of
>_FPCLASS_?? from float.h and checked with MSDN. So the switch fails!

>Also, I tried [ -1.0 / 0.0 ] which gave -1.#J which is correct, but the
>_fpclass() gives nothing -- ie gave a code that cannot be mapped into the
>defined _FPCLASS_?? set as given in the documentation and in the float.h
>file.

>Similarly, _isnan() only works first time, 2nd time it does not indicate
>that it is not a NAN, although I can see in debug that it is an 1.#J !

>The whole float.h package appears confusing. . . .there are at least 4 sets
>of different floating error codes - the _SW_???? , _FPCLASS_???? _EM_????
>_FPE_????? ----> is there a better superset that I can use???

>Must I do something else to detect what floating pt error is raised in
>addition to using _fpclass()?



Mon, 01 Sep 2003 00:23:25 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. floating pt errors..

2. Intel Floating Pt Error

3. turbo C floating pt error quetion

4. Are there std Floating Pt. Exts.?

5. floating pt. cast as int

6. floating pt.: roundoff or truncate?

7. floating pt in TC

8. Minus Sign and Float. Pt. Edit Control

9. Pt 1/2: Pointer errors

10. Pt 2/2: Pointer errors

11. float != float and floats as return types

12. fatal error C1189: #error : MFC requires C++ compilation (use a .cpp suffix)

 

 
Powered by phpBB® Forum Software