xref: /csrg-svn/usr.bin/pascal/libpc/EXCEPT.c (revision 62092)
140865Sbostic /*-
2*62092Sbostic  * Copyright (c) 1982, 1993
3*62092Sbostic  *	The Regents of the University of California.  All rights reserved.
440865Sbostic  *
540865Sbostic  * %sccs.include.redist.c%
640865Sbostic  */
75673Smckusick 
840865Sbostic #ifndef lint
9*62092Sbostic static char sccsid[] = "@(#)EXCEPT.c	8.1 (Berkeley) 06/06/93";
1040865Sbostic #endif /* not lint */
115673Smckusick 
125673Smckusick #include	<signal.h>
135673Smckusick 
145673Smckusick /*
155673Smckusick  * catch runtime arithmetic errors
165673Smckusick  */
EXCEPT(signum,type)175673Smckusick EXCEPT(signum, type)
185673Smckusick 	int signum, type;
195673Smckusick {
205673Smckusick 	signal(SIGFPE, EXCEPT);
2110230Smckusick #ifndef vax
225673Smckusick 	ERROR("Overflow, underflow, or division by zero in arithmetic operation\n");
235716Smckusic 	return;
2410230Smckusick #endif notvax
2510230Smckusick #ifdef vax
265716Smckusic 	/*
275716Smckusic 	 * The values for this switch statement come from page 12-5 of
285716Smckusic 	 * Volume 1 of the 1978 VAX 11/780 Architecture Handbook
295716Smckusic 	 */
305673Smckusick 	switch (type) {
3115126Smckusick 	case FPE_INTOVF_TRAP:
325673Smckusick 		ERROR("Integer overflow\n");
335716Smckusic 		return;
3415126Smckusick 	case FPE_INTDIV_TRAP:
355673Smckusick 		ERROR("Integer division by zero\n");
365716Smckusic 		return;
3715126Smckusick 	case FPE_FLTOVF_TRAP:
3815126Smckusick 	case FPE_FLTOVF_FAULT:
395673Smckusick 		ERROR("Real overflow\n");
405716Smckusic 		return;
4115126Smckusick 	case FPE_FLTDIV_TRAP:
4215126Smckusick 	case FPE_FLTDIV_FAULT:
435673Smckusick 		ERROR("Real division by zero\n");
445716Smckusic 		return;
4515126Smckusick 	case FPE_FLTUND_TRAP:
4615126Smckusick 	case FPE_FLTUND_FAULT:
475673Smckusick 		ERROR("Real underflow\n");
485716Smckusic 		return;
4915126Smckusick 	case FPE_DECOVF_TRAP:
5015126Smckusick 	case FPE_SUBRNG_TRAP:
515673Smckusick 	default:
5215126Smckusick 		ERROR("Undefined arithmetic exception type (%d)\n", type);
535716Smckusic 		return;
545673Smckusick 	}
5510230Smckusick #endif vax
565673Smckusick }
57