home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / calculat / rpn30src.zip / MATHERR.C < prev    next >
C/C++ Source or Header  |  1990-05-23  |  1KB  |  50 lines

  1. /**
  2.  ** matherr.c
  3.  **
  4.  ** Try to handle math errors semi-gracefully, instead of just crashing.
  5.  **/
  6. #include <math.h>
  7. #include <float.h>    /** for _fpreset() prototype **/
  8. #include "debug.h"
  9. #include "rpn.h"
  10. #include "display.h"    /** for prterr() prototype **/
  11. #include "ftns.h"
  12.  
  13. int cdecl matherr (struct exception *a)
  14. {
  15.     char *errtype;
  16.  
  17.     math_error = 1;
  18.     switch (a->type) {
  19.     case DOMAIN:
  20.         errtype = "domain";
  21.         break;
  22.     case SING:
  23.         errtype = "singularity";
  24.         break;
  25.     case OVERFLOW:
  26.         errtype = "overflow";
  27.         break;
  28.     case UNDERFLOW:
  29.         errtype = "underflow";
  30.         break;
  31.     case TLOSS:
  32.         errtype = "significant-loss";
  33.         break;
  34.     default:
  35.         errtype = "Unrecognized!";
  36.         break;
  37.     }
  38.     DBG_FPRINTF((errfile,"matherr: name: %s\ntype: %d, errtype: %s\n"
  39.         "arg1: %f, arg2: %f, retval: %f\n",
  40.         a->name, a->type, errtype, a->arg1, a->arg2, a->retval));
  41.  
  42.     prterr(a->name, errtype);
  43.     a->retval = lastx;
  44.     if (stack_popped)
  45.         push();
  46.     lastx = tmpLX;
  47.     _fpreset();        /** reset the math chip **/
  48.     return 1;
  49. }
  50.