home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.ms-windows.programmer.misc
- Path: sparky!uunet!mcsun!sunic!aun.uninett.no!ugle.unit.no!humpty.edb.tih.no!fiero.edb.tih.no!modeld.no!manger.modeld.no!magmy
- From: magmy@modeld.no (Magne Myrtveit)
- Subject: Math error handling
- Message-ID: <u2mrjqqcuC@manger.modeld.no>
- Sender: magmy@modeld.no (Magne Myrtveit)
- Reply-To: magmy@modeld.no
- Posting-Front-End: Winix Conference v 91.06.07.01 (running under MS-Windows)
- Date: Mon, 17 Aug 92 22:08:33 +0000
- Lines: 63
-
- BACKGROUND
- -----------------------------------------------------------------
- I want to handle math errors in my program (the program computes
- values based on user input, and is supposed not to abort whenever
- a user enters illegal inputs).
-
- I have experimented with the following functions for handling
- math errors:
-
- _matherr(...)
- signal(...)
- _fpreset()
- errno
- _control87(...)
- _status87()
- _clear87()
-
- In a C program compiled for DOS things works OK, but when
- compiled using C++ and the MFC library, i do not get the
- _status87() and _clear87() functions to return the expected result.
-
- TEST PROGRAM
- -----------------------------------------------------------------
- Fragments of my test program looks like this:
-
- ...
- #include <math.h>
- #include <float.h>
-
- main() {
-
- // Set IEEE control register
-
- _control87(
- _EM_INVALID |
- _EM_DENORMAL |
- _EM_ZERODIVIDE |
- _EM_OVERFLOW |
- _EM_UNDERFLOW |
- _EM_INEXACT, _MCW_EM);
-
- // Perform divide by zero
-
- double A;
- double B = 0.0;
- int S;
-
- A = 10.0 / B;
-
- S = _clear87();
-
- // The value of 'S' is zero at this point
-
- } // main
-
- ALTERNATIVE SOLUTION
- -----------------------------------------------------------------
- I have solved the problem temporarily by catching error exceptions
- using 'signal'. All ths same I'd like to have the explanation of why
- the above code does not work.
-
- Sincerely,
- Magne Myrtveit
-