home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / biology / gsrc208a.zip / EXCEPT.C < prev    next >
C/C++ Source or Header  |  1993-07-16  |  6KB  |  206 lines

  1. #include "copyleft.h"
  2.  
  3. /*
  4.     GEPASI - a simulator of metabolic pathways and other dynamical systems
  5.     Copyright (C) 1989, 1992  Pedro Mendes
  6. */
  7.  
  8. /*************************************/
  9. /*                                   */
  10. /* floating-point exceptions handler */
  11. /*                                   */
  12. /*          MICROSOFT C 6.00         */
  13. /*           QuickC/WIN 1.0          */
  14. /*             ULTRIX cc             */
  15. /*              GNU gcc              */
  16. /*                                   */
  17. /*   (include here compilers that    */
  18. /*   compiled GEPASI successfully)   */
  19. /*                                   */
  20. /*************************************/
  21.  
  22.  
  23. #ifdef _MSC_VER /* Microsoft compilers */
  24.  
  25. #if (_MSC_VER == 610) /* QuickC/WIN compiler */
  26.  
  27. #define FP_INVALID            0x81
  28. #define FP_DENORMAL            0x82
  29. #define FP_ZERODIVIDE        0x83
  30. #define FP_OVERFLOW            0x84
  31. #define FP_UNDERFLOW        0x85
  32. #define FP_INEXACT            0x86
  33. #define FP_UNEMULATED        0x87
  34. #define FP_SQRTNEG            0x88
  35. #define FP_STACKOVERFLOW    0x8a
  36. #define FP_STACKUNDERFLOW    0x8b
  37. #define FP_EXPLICITGEN         0x8c
  38.  
  39. #endif
  40.  
  41. #if( _MSC_VER <= 600) /* MS C 6.00 and previous compilers */
  42.  
  43. #define FP_INVALID            FPE_INVALID
  44. #define FP_DENORMAL            FPE_DENORMAL
  45. #define FP_INEXACT            FPE_INEXACT
  46. #define FP_UNEMULATED        FPE_UNEMULATED
  47. #define FP_SQRTNEG            FPE_SQRTNEG
  48. #define FP_STACKOVERFLOW    FPE_STACKOVERFLOW
  49. #define FP_STACKUNDERFLOW    FPE_STACKUNDERFLOW
  50. #define FP_EXPLICITGEN        FPE_EXPLICITGEN
  51. #define FP_FLT_ZERODIVIDE    FPE_ZERODIVIDE
  52. #define FP_FLT_OVERFLOW        FPE_OVERFLOW
  53. #define FP_FLT_UNDERFLOW    FPE_UNDERFLOW
  54.  
  55. #endif
  56.  
  57. #endif
  58.  
  59. #ifdef _ZTC /* Zortech C compiler */
  60.  
  61. #define FP_INVALID            1
  62. #define FP_DENORMAL            2
  63. #define FP_INEXACT            0x20
  64. #define FP_FLT_ZERODIVIDE    4
  65. #define FP_FLT_OVERFLOW        8
  66. #define FP_FLT_UNDERFLOW    0x10
  67.  
  68. #endif /* _ZTC */
  69.  
  70. #ifdef ultrix /* DEC ULTRIX cc compilers */
  71.  
  72. #define FP_INT_ZERODIVIDE        FPE_INTDIV_TRAP
  73. #define FP_INT_OVERFLOW            FPE_INTOVF_TRAP
  74. #define FP_FLT_ZERODIVIDE        FPE_FLTDIV_TRAP
  75. #define FP_FLT_OVERFLOW            FPE_FLTOVF_TRAP
  76. #define FP_FLT_UNDERFLOW        FPE_FLTUND_TRAP
  77. #define FP_DEC_OVERFLOW            FPE_DECOVF_TRAP
  78. #define FP_OUTOFRANGE            FPE_SUBRNG_TRAP
  79.  
  80. #endif /* ultrix */
  81.  
  82. #ifdef _MSC_VER
  83. void fphandler( int sig, int num )
  84. {
  85.  /* Set global for outside check, since we don't want to do I/O in the handler. */
  86.  fperr = num;
  87.  
  88.  
  89.  /* Initialize floating-point package. */
  90.  _fpreset();
  91.  
  92.  /* Restore calling environment and jump back to setjmp. Return -1 so that      */
  93.  /* setjmp will return false for conditional test.                                */
  94.  beep();
  95.  longjmp( mark, -1 );
  96. }
  97. #endif /* _MSC_VER */
  98.  
  99. #ifdef _ZTC
  100. void fphandler( int sig )
  101. {
  102.  /* Initialize floating-point package. */
  103.  _fpreset();
  104.  
  105.  /* Restore calling environment and jump back to setjmp. Return -1 so that      */
  106.  /* setjmp will return false for conditional test.                                */
  107.  beep();
  108.  longjmp( mark, -1 );
  109. }
  110. #endif /* _ZTC */
  111.  
  112. #ifdef ultrix
  113. void fphandler( int sig, int num, struct sigcontext *scp )
  114. {
  115.  /* Set global for outside check, since we don't want to do I/O in the handler. */
  116.  fperr = num;
  117.  
  118.  /* Restore calling environment and jump back to setjmp. Return -1 so that      */
  119.  /* setjmp will return false for conditional test.                                */
  120.  beep();
  121.  longjmp( mark, -1 );
  122. }
  123. #endif /* ultrix */
  124.  
  125. void fpcheck( void )
  126. {
  127.  switch( fperr )
  128.  {
  129.  
  130. #ifdef _ZTC
  131.   case FP_INVALID:        strcpy( fpstr, "Invalid number" ); break;
  132.  
  133.   case FP_INEXACT:        strcpy( fpstr, "Inexact number" ); break;
  134.  
  135.   case FP_FLT_ZERODIVIDE:     strcpy( fpstr, "Floating point divide by zero" ); break;
  136.  
  137.   case FP_FLT_OVERFLOW:       strcpy( fpstr, "Floating point overflow" ); break;
  138.  
  139.   case FP_FLT_UNDERFLOW:      strcpy( fpstr, "Floating point underflow" ); break;
  140. #endif /* _ZTC */
  141.  
  142. #ifdef _MSC_VER
  143. #if (_MSC_VER < 800)                /* QuickC/WIN or C/C++ 7.0                */
  144.   case FP_INVALID:        strcpy( fpstr, "Invalid number" ); break;
  145.  
  146.   case FP_UNEMULATED:     strcpy( fpstr, "Co-processor function unemulated" ); break;
  147.  
  148.   case FP_SQRTNEG:        strcpy( fpstr, "Square root of negative number" ); break;
  149.  
  150.   case FP_STACKUNDERFLOW: strcpy( fpstr, "Co-processor stack underflow" ); break;
  151.  
  152.   case FP_STACKOVERFLOW:  strcpy( fpstr, "Co-processor stack overflow" ); break;
  153.  
  154.   case FP_OVERFLOW:       strcpy( fpstr, "Floating point overflow" ); break;
  155.  
  156.   case FP_UNDERFLOW:      strcpy( fpstr, "Floating point underflow" ); break;
  157.  
  158.   case FP_ZERODIVIDE:     strcpy( fpstr, "Floating point divide by zero" ); break;
  159.  
  160. #endif /* _MSC_VER<800 */
  161. #if (_MSC_VER == 800)                /* Visual C/C++                     */
  162.   case _FPE_INVALID:        strcpy( fpstr, "Invalid number" ); break;
  163.  
  164.   case _FPE_UNEMULATED:     strcpy( fpstr, "Co-processor function unemulated" ); break;
  165.  
  166.   case _FPE_SQRTNEG:        strcpy( fpstr, "Square root of negative number" ); break;
  167.  
  168.   case _FPE_STACKUNDERFLOW: strcpy( fpstr, "Co-processor stack underflow" ); break;
  169.  
  170.   case _FPE_STACKOVERFLOW:  strcpy( fpstr, "Co-processor stack overflow" ); break;
  171.  
  172.   case _FPE_OVERFLOW:       strcpy( fpstr, "Floating point overflow" ); break;
  173.  
  174.   case _FPE_INEXACT:        strcpy( fpstr, "Inexact number" ); break;
  175.  
  176.   case _FPE_UNDERFLOW:      strcpy( fpstr, "Floating point underflow" ); break;
  177.  
  178.   case _FPE_ZERODIVIDE:     strcpy( fpstr, "Floating point divide by zero" ); break;
  179. #endif /* _MSC_VER==800 */
  180. #endif /* _MSC_VER */
  181.  
  182. #ifdef ultrix
  183.   case FP_DEC_OVERFLOW:
  184. #endif /* ultrix */
  185.  
  186. /*#if( _MSC_VER != 610 )
  187.   case FP_FLT_OVERFLOW:   strcpy( fpstr, "Floating point overflow" ); break;
  188.  
  189.   case FP_FLT_UNDERFLOW:  strcpy( fpstr, "Floating point underflow" ); break;
  190.  
  191.   case FP_FLT_ZERODIVIDE: strcpy( fpstr, "Floating point divide by zero" ); break;
  192. #endif *//*_MSC_VER!=610*/
  193.  
  194. #ifdef ultrix
  195.   case FP_INT_ZERODIVIDE: strcpy( fpstr, "Integer divide by zero" ); break;
  196.  
  197.   case FP_INT_OVERFLOW:   strcpy( fpstr, "Integer overflow" ); break;
  198.  
  199.   case FP_OUTOFRANGE:     strcpy( fpstr, "Subscript out of range" ); break;
  200. #endif /*ultrix */
  201.  
  202.   default:                strcpy( fpstr, "Undefined floating point error" ); break;
  203.  }
  204.  printf( "\n  * %s: (%d)\n", fpstr, fperr );
  205. }
  206.