How to force floating point exceptions to dump core

Tim Monks tim at merlin.bhpmrl.oz
Wed May 2 13:22:33 AEST 1990


How do you force floating point exceptions to dump core in C on an SG ? 

The reason I want to do this is I've got a longish program which
generates NaN's somewhere. I thought the easiest way to track
down the problem was to set up an exception handler which would
capture SIGFPE signals and take appropriate action. I didn't manage
to get even that far, I couldn't even make the program baulk at NaN's.


I've tried some variations on the following with no success:

--8<----------------------------------------------------------------------
#include <stdio.h>
#include <math.h>
#include <signal.h>
#include <fp_class.h>

main(argc, argv)

int     argc;
char    **argv;

{

    void	Report_class(double);
    double	x,zero;


    /* set up a signal trap */
    signal(SIGFPE, SIG_DFL);


    /* try to trap Infinity */
    zero = 0.0;
    x = 1.0/zero;

    /* 
    I wanted the program to dump core on the previous line, 
    but it carried on, so we have a look at what we got.
    */
    Report_class(x);


    /* Now try to trap NaN */
    x = zero/zero;
    Report_class(x);
}



void Report_class(double x)
{
    int		type;

    type = fp_class_d(x);
    if (type == FP_SNAN)
	fprintf(stderr,"X = %lf is a signalling NaN\n",x);
    else if (type == FP_QNAN)
	fprintf(stderr,"X = %lf is a quiet NaN\n",x);
    else if (type == FP_POS_INF)
	fprintf(stderr,"X = %lf is positive infinity\n",x);
    else if (type == FP_NEG_INF)
	fprintf(stderr,"X = %lf is negative infinity\n",x);
    else
	fprintf(stderr,"X = %lf is something quite different !!!\n",x);
}
--8<----------------------------------------------------------------------

And the program gives the following output: (240GTX, Irix 3.2.2)
	    X = Infinity is positive infinity
	    X = NaN is a quiet NaN
but definitely no core!  

How do you make quiet NaN's noisy ? (a signaling NaN)

I've RTFM, but haven't found any enlightenment on this. Can someone
point me at the relevant FM to read, or provide a solution.

On this topic, how does SG propagate NaN's and Infinity through
arithmetic and math library operations ?


I'll post a summary if there's any demand for one.

Thanks in advance.
-- 
Dr. Tim Monks                                

Image Processing & Data Analysis Group   |   (direct) (+61-3)566-7448
BHP Melbourne Research Laboratories      |   (switch) (+61-3)560-7066
245 Wellington Rd, Mulgrave, 3170,       |   (fax)    (+61-3)561-6709
AUSTRALIA                                |   (EMAIL)  tim at merlin.bhpmrl.oz.au



More information about the Comp.sys.sgi mailing list