home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / IRIT / IRITS.ZIP / MATHERR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-05  |  2.9 KB  |  103 lines

  1. /*****************************************************************************
  2. *   "Irit" - the 3d polygonal solid modeller.                     *
  3. *                                         *
  4. * Written by:  Gershon Elber                Ver 0.2, Mar. 1990   *
  5. ******************************************************************************
  6. * Module to handle floating point errors:                     *
  7. *****************************************************************************/
  8.  
  9. #ifdef __MSDOS__
  10. #include <graphics.h>
  11. #include <float.h>
  12. #endif /* __MSDOS__ */
  13.  
  14. #include <math.h>
  15. #include <string.h>
  16. #include <stdio.h>
  17. #include "program.h"
  18. #include "windowsg.h"
  19.  
  20. #ifndef __MSDOS__
  21. #include "xgraphic.h"
  22. #endif /* __MSDOS__ */
  23.  
  24. static int MathErrorNum = 0;
  25. static char MathErrorFunc[LINE_LEN] = "";
  26.  
  27. #ifdef __MSDOS__
  28.  
  29. /*****************************************************************************
  30. * Routine to trap math errors -    set GlobalMathError to error number, and     *
  31. * GlobalMathFunc to the    math function with the error. Return TRUE to         *
  32. * make it believe that everything is ok. now...                     *
  33. *****************************************************************************/
  34. int matherr(struct exception *except)
  35. {
  36.     strcpy(MathErrorFunc, except -> name);
  37.     MathErrorNum = except -> type;
  38.     except -> retval = 1.0;           /* return something reasonable... */
  39.  
  40.     return TRUE;
  41. }
  42.  
  43. #endif /* __MSDOS__ */
  44.  
  45. /*****************************************************************************
  46. * Routine to return last floating point (function) error if was one:         *
  47. *****************************************************************************/
  48. int MathError(char **FuncName)
  49. {
  50.     int Temp;
  51.  
  52.     *FuncName = MathErrorFunc;
  53.  
  54.     Temp = MathErrorNum;
  55.     MathErrorNum = 0;
  56.     return Temp;
  57. }
  58.  
  59. /*****************************************************************************
  60. * Routine to print lower level floating point error message.             *
  61. * This routine should be called by SIGFPE signal trapping handler.         *
  62. *****************************************************************************/
  63. void PrintFPError(int Type)
  64. {
  65.     char s[LINE_LEN];
  66.  
  67.     strcpy(s, "Fatal Floating Point Error: ");
  68.  
  69.     switch (Type) {
  70. #ifdef __MSDOS__
  71.     case FPE_INTOVFLOW:
  72.         strcat(s, "integer overflow");
  73.         break;
  74.     case FPE_INTDIV0:
  75.         strcat(s, "integer divide by zero");
  76.         break;
  77.     case FPE_INVALID:
  78.         strcat(s, "invalid operation");
  79.         break;
  80.     case FPE_ZERODIVIDE:
  81.         strcat(s, "division by zero");
  82.         break;
  83.     case FPE_OVERFLOW:
  84.         strcat(s, "numeric overflow");
  85.         break;
  86.     case FPE_UNDERFLOW:
  87.         strcat(s, "numeric underflow");
  88.         break;
  89.     case FPE_INEXACT:
  90.         strcat(s, "precision lost");
  91.         break;
  92.     case FPE_EXPLICITGEN:
  93.         strcat(s, "explicit signal");
  94.         break;
  95. #endif /* __MSDOS__ */
  96.     default:
  97.         strcat(s, "Undefined error");
  98.         break;
  99.     }
  100.  
  101.     WndwInputWindowPutStr(s, RED);
  102. }
  103.