SIGFPE trap

Frank Cianflone frankc at mips.COM
Thu Jan 3 11:22:37 AEST 1991


/*    You may try this:
    calling sequence:

	integer condition
	logical old,new,setfpe
	old = setfpe(condition,new)

The value of condition must be one of the following:

	1 - Invalid Operation Condition
	2 - Divide By Zero Condition
	3 - Inexact Result Condition
	4 - Overflow Condition

The value of new must be .TRUE. or .FALSE. depending on whether we want to
enable or disable the floating point exception signal when the given
condition occurrs.  The return value of the setfpe function is a logical
value indicating if the floating point exception signal was enabled for that
condition when the setfpe function was called.  The following is an example
of the use of the setfpe function: */

	integer SIGFPE,DIVIDE0
	parameter (SIGFPE=8,DIVIDE0=2)
	logical old,setfpe
	external fperror
	data a/0.0/
	old = setfpe(DIVIDE0,.true.)
	isig = signal(SIGFPE,fperror,-1)
	b = 1.0/b
	print *,b
	end
*/

#include <signal.h>
#ifdef SYSV
#include <sys/fpu.h>
#else
#include <machine/fpu.h>
#endif

#define WORD		0
#define INVALID		1
#define DIVIDE0		2
#define INEXACT		3
#define OVERFLOW	4

setfpe_(exception,flag)
   int *exception,*flag;
{
    int retval;
    union fpc_csr fpc_csr;
    extern unsigned long get_fpc_csr();
    extern unsigned long set_fpc_csr();

    fpc_csr.fc_word = get_fpc_csr();
    switch ( *exception ) {
	case WORD:
			retval = fpc_csr.fc_word;
			fpc_csr.fc_word = *flag;
			break;

	case INVALID:	retval = fpc_csr.fc_struct.en_invalid;
			fpc_csr.fc_struct.en_invalid = *flag ? 1 : 0;
			break;

    	case DIVIDE0:	retval = fpc_csr.fc_struct.en_invalid;
			fpc_csr.fc_struct.en_divide0 = *flag ? 1 : 0;
			break;

    	case INEXACT:	retval = fpc_csr.fc_struct.en_invalid;
			fpc_csr.fc_struct.en_inexact = *flag ? 1 : 0;
			break;

    	case OVERFLOW:	retval = fpc_csr.fc_struct.en_invalid;
			fpc_csr.fc_struct.en_overflow = *flag ? 1 : 0;
			break;

	default:	return(0);
    }

    (void)set_fpc_csr(fpc_csr.fc_word);
    return(retval);

}
-- 

Frank Cianflone                      {ames,decwrl,prls,pyramid}!mips!frankc
MIPS Computer Systems                frankc at mips.com
930 Arques Ave, Sunnyvale CA, 94086  Ma Bell: (408)524-7460 Fax: (408)524-7521



More information about the Comp.unix.programmer mailing list