15673Smckusick /* Copyright (c) 1982 Regents of the University of California */ 25673Smckusick 3*15126Smckusick static char sccsid[] = "@(#)EXCEPT.c 1.4 10/01/83"; 45673Smckusick 55673Smckusick #include <signal.h> 65673Smckusick 75673Smckusick /* 85673Smckusick * catch runtime arithmetic errors 95673Smckusick */ 105673Smckusick EXCEPT(signum, type) 115673Smckusick int signum, type; 125673Smckusick { 135673Smckusick signal(SIGFPE, EXCEPT); 1410230Smckusick #ifndef vax 155673Smckusick ERROR("Overflow, underflow, or division by zero in arithmetic operation\n"); 165716Smckusic return; 1710230Smckusick #endif notvax 1810230Smckusick #ifdef vax 195716Smckusic /* 205716Smckusic * The values for this switch statement come from page 12-5 of 215716Smckusic * Volume 1 of the 1978 VAX 11/780 Architecture Handbook 225716Smckusic */ 235673Smckusick switch (type) { 24*15126Smckusick case FPE_INTOVF_TRAP: 255673Smckusick ERROR("Integer overflow\n"); 265716Smckusic return; 27*15126Smckusick case FPE_INTDIV_TRAP: 285673Smckusick ERROR("Integer division by zero\n"); 295716Smckusic return; 30*15126Smckusick case FPE_FLTOVF_TRAP: 31*15126Smckusick case FPE_FLTOVF_FAULT: 325673Smckusick ERROR("Real overflow\n"); 335716Smckusic return; 34*15126Smckusick case FPE_FLTDIV_TRAP: 35*15126Smckusick case FPE_FLTDIV_FAULT: 365673Smckusick ERROR("Real division by zero\n"); 375716Smckusic return; 38*15126Smckusick case FPE_FLTUND_TRAP: 39*15126Smckusick case FPE_FLTUND_FAULT: 405673Smckusick ERROR("Real underflow\n"); 415716Smckusic return; 42*15126Smckusick case FPE_DECOVF_TRAP: 43*15126Smckusick case FPE_SUBRNG_TRAP: 445673Smckusick default: 45*15126Smckusick ERROR("Undefined arithmetic exception type (%d)\n", type); 465716Smckusic return; 475673Smckusick } 4810230Smckusick #endif vax 495673Smckusick } 50