home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c329 / 2.img / EXAMPLES / EXC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-21  |  1.5 KB  |  59 lines

  1. /*
  2.  * exc.c
  3.  *
  4.  * Purpose: demonstrates changing numeric error handling
  5.  * from passive to active in NDP C-386
  6.  * Copyright (C) MicroWay, Inc 1989
  7.  * Jeremy D. Freeman, Edgartown, MA
  8.  *
  9.  */
  10.  
  11. /* NDP C-386's default response to a division by zero is
  12.  * passive error handling. That is, the coprocesor will set
  13.  * the appropriate error bit in its status word, return an
  14.  * infinity signed with the exclusive OR of the signs of
  15.  * the operands, and continue processing. Here the 
  16.  * programmer has decided that a division by zero is so
  17.  * serious a flaw that the proper response is MicroWay's
  18.  * default active error handling, i.e, dump the the state of
  19.  * the coprocessor to stdout and exit to the operating
  20.  * system. Therefore he has used enab_ex_() to unmask the
  21.  * zero-divide bit in the control word.
  22.  * 
  23.  */
  24. #include <stdio.h>
  25. #include <dos.h>
  26.  
  27. #define EVAL    0xffffffff      /* error value returned by */
  28.                                                 /* enab_ex_() */
  29. #define TRUE    1
  30. #define FALSE   0
  31.  
  32. unsigned enab_ex_();
  33.  
  34. void main ()
  35.  
  36. {
  37.         double x,y,z;
  38.         unsigned save_cw, emask;
  39.         
  40.         x = 1.0;
  41.         y = 0.0;
  42.         
  43. /* enable zero divide exception trap */
  44.         emask = ZM;
  45.         save_cw = enab_ex_(&emask); 
  46.         if (save_cw == EVAL) {
  47.                 printf("\nProblem in enab_ex()\n");
  48.                 putchar('\7');  /* beep */
  49.                 exit(1);
  50.         }
  51.  
  52.         z = x / y;
  53.  
  54.         printf("x = %lf y = %lf z = %lf\n",x,y,z);
  55.  
  56. }       /* end of divz.c */
  57.  
  58.  
  59.