KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q22317: matherr and Trapping Floating-Point Errors

Article: Q22317
Product(s): See article
Version(s): 4.00 5.00 5.10
Operating System(s): MS-DOS
Keyword(s): ENDUSER | | mspl13_c
Last Modified: 15-JAN-1990

Question:

matherr is not trapping my floating point errors. Could you give me
some advice on what I could be doing wrong?

Response:

matherr (Page 274 in the "Microsoft C Run-Time Library Reference"
manual) does not trap in-line floating-point errors. matherr only
traps floating-point errors generated by functions in our math
libraries. For example, the following program returns control to our
matherr routine, not yours:

   #include <math.h>

   matherr(x)
   struct exception *x;
   {
   x->retval=2;
   return(1);
   }

   main()
   {
   double f;
   f=2.0;
   while (1)
   f*=f;
   }

To trap in-line floating-point errors such as the one above, we
recommend that you use signal with SIGFPE (see the run-time reference
manual).

THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Copyright Microsoft Corporation 1986-2002.