home *** CD-ROM | disk | FTP | other *** search
- /*
- * exc.c
- *
- * Purpose: demonstrates changing numeric error handling
- * from passive to active in NDP C-386
- * Copyright (C) MicroWay, Inc 1989
- * Jeremy D. Freeman, Edgartown, MA
- *
- */
-
- /* NDP C-386's default response to a division by zero is
- * passive error handling. That is, the coprocesor will set
- * the appropriate error bit in its status word, return an
- * infinity signed with the exclusive OR of the signs of
- * the operands, and continue processing. Here the
- * programmer has decided that a division by zero is so
- * serious a flaw that the proper response is MicroWay's
- * default active error handling, i.e, dump the the state of
- * the coprocessor to stdout and exit to the operating
- * system. Therefore he has used enab_ex_() to unmask the
- * zero-divide bit in the control word.
- *
- */
- #include <stdio.h>
- #include <dos.h>
-
- #define EVAL 0xffffffff /* error value returned by */
- /* enab_ex_() */
- #define TRUE 1
- #define FALSE 0
-
- unsigned enab_ex_();
-
- void main ()
-
- {
- double x,y,z;
- unsigned save_cw, emask;
-
- x = 1.0;
- y = 0.0;
-
- /* enable zero divide exception trap */
- emask = ZM;
- save_cw = enab_ex_(&emask);
- if (save_cw == EVAL) {
- printf("\nProblem in enab_ex()\n");
- putchar('\7'); /* beep */
- exit(1);
- }
-
- z = x / y;
-
- printf("x = %lf y = %lf z = %lf\n",x,y,z);
-
- } /* end of divz.c */
-
-
-