[comp.sys.mips] SIGFPE and atan2

rossc@extro.ucc.su.oz.au (Ross Cartlidge) (09/19/90)

When I called do a:-

atan2(1.0, 0.0)

on a M/2000 running RISC/OS 4.5 I get a
divide by zero exception. On other machines I have
tried I do not. As atan2(1.0, 0.0) is defined (PI/2)
does anyone know why I get this exception. If I don't
enable div by zero exceptions it gives the correct answer.

The programs below demonstrates the problem on a MIPS
as compared to a Sun 4/60.

#include <signal.h>
#include <sys/fpu.h>
#include <math.h>

main()
{
	double	f;
	double	z;
	int	c();
	union fpc_csr	csr;

	signal(SIGFPE, c);
	csr.fc_word = get_fpc_csr();
	csr.fc_struct.en_divide0 = 1;
	csr.fc_struct.en_overflow = 1;
	csr.fc_struct.en_invalid = 1;
	set_fpc_csr(csr.fc_word);
	
	f = atan2(1.0, 0.0);
	printf("f = %f\n", f);
}

c()
{
	printf("FPE\n");
}

This program shows the behaviour on a Sun 4/60:-

#include <signal.h>
#include <math.h>

main()
{
	double	f;
	double	z;
	int	c();
	char	*out;

	printf("%d\n", ieee_handler("set","all",c));
	printf("out = %s\n", out);
	
	f = atan2(1.0, 0.0);
	printf("f = %f\n", f);
}

c()
{
	printf("FPE\n");
}
--
________________________________________________________________________
Ross Rodney Cartlidge			    |   rossc@extro.ucc.su.oz.au
University Computing Service, H08	    |   Phone:     +61 2 6923497
University of Sydney, NSW 2006, Australia   |   FAX:       +61 2 6606557