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).