Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!ames!sgi!shinobu!odin!moose.sgi.com!jwag From: jwag@moose.sgi.com (Chris Wagner) Newsgroups: comp.sys.sgi Subject: Re: How to force floating point exceptions to dump core Keywords: core, signal, sigset, NaN, IEEE floating point Message-ID: <7188@odin.corp.sgi.com> Date: 3 May 90 15:52:07 GMT References: <1521@merlin.bhpmrl.oz> Sender: news@odin.corp.sgi.com Reply-To: jwag@moose.sgi.com (Chris Wagner) Organization: Silicon Graphics, Research & Development Lines: 116 In article <1521@merlin.bhpmrl.oz>, tim@merlin.bhpmrl.oz (Tim Monks) writes: > 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 > #include > #include > #include > > 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@merlin.bhpmrl.oz.au Try including and calling the following function: #include #include #include .globl fpe_enable .ent fpe_enable fpe_enable: cfc1 t0, fpc_csr # grab fpu status register li t1, 0xF10 /*li t1, 0x3f000*/ or t0, t0, t1 # or in enable bits ctc1 t0, fpc_csr # replace fpu status j ra # return .end fpe_enable By default the C runtime startup does not enable floating point exceptions In our next release a complete fp exception package has been added Chris Wagner