home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / os / mswindo / programm / misc / 1371 < prev    next >
Encoding:
Text File  |  1992-08-17  |  1.9 KB  |  75 lines

  1. Newsgroups: comp.os.ms-windows.programmer.misc
  2. 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
  3. From: magmy@modeld.no (Magne Myrtveit)
  4. Subject: Math error handling
  5. Message-ID: <u2mrjqqcuC@manger.modeld.no>
  6. Sender: magmy@modeld.no (Magne Myrtveit)
  7. Reply-To: magmy@modeld.no
  8. Posting-Front-End: Winix Conference v 91.06.07.01 (running under MS-Windows)
  9. Date: Mon, 17 Aug 92 22:08:33 +0000
  10. Lines: 63
  11.  
  12. BACKGROUND
  13. -----------------------------------------------------------------
  14. I want to handle math errors in my program (the program computes
  15. values based on user input, and is supposed not to abort whenever
  16. a user enters illegal inputs).
  17.  
  18. I have experimented with the following functions for handling
  19. math errors:
  20.  
  21.     _matherr(...)
  22.     signal(...)
  23.     _fpreset()
  24.     errno
  25.     _control87(...)
  26.     _status87()
  27.     _clear87()
  28.  
  29. In a C program compiled for DOS things works OK, but when
  30. compiled using C++ and the MFC library, i do not get the
  31. _status87() and _clear87() functions to return the expected result.
  32.  
  33. TEST PROGRAM
  34. -----------------------------------------------------------------
  35. Fragments of my test program looks like this:
  36.  
  37.    ...
  38.    #include <math.h>
  39.    #include <float.h>
  40.  
  41.    main() {
  42.  
  43.    // Set IEEE control register
  44.  
  45.       _control87(
  46.         _EM_INVALID |
  47.         _EM_DENORMAL |
  48.         _EM_ZERODIVIDE |
  49.         _EM_OVERFLOW |
  50.         _EM_UNDERFLOW |
  51.         _EM_INEXACT, _MCW_EM);
  52.  
  53.    // Perform divide by zero
  54.  
  55.       double A;
  56.       double B = 0.0;
  57.       int S;
  58.  
  59.       A = 10.0 / B;
  60.  
  61.       S = _clear87();
  62.  
  63.    // The value of 'S' is zero at this point
  64.  
  65.    }  // main
  66.  
  67. ALTERNATIVE SOLUTION
  68. -----------------------------------------------------------------
  69. I have solved the problem temporarily by catching error exceptions
  70. using 'signal'. All ths same I'd like to have the explanation of why
  71. the above code does not work.
  72.  
  73. Sincerely,
  74. Magne Myrtveit
  75.