Help in dealing with floating point exceptions in C on UNIX/VAX

ag0 at k.cc.purdue.edu.UUCP ag0 at k.cc.purdue.edu.UUCP
Wed Feb 18 07:05:14 AEST 1987


In article <635 at sdchema.sdchem.UUCP> tps at sdchemf.UUCP (Tom Stockfisch) writes:
>In article <4441 at brl-adm.ARPA> moss at BRL.ARPA (Gary S. Moss (SLCBR-VLD-V)) writes:
>>See matherr(3M).
>>-moss
>
>What system are you on?
>I can't find this in either my 4.3BSD or Sys V Manual.
>
>|| Tom Stockfisch, UCSD Chemistry	tps%chem at sdcsvax.UCSD

I can't find on my 4.3 system either.  I would suggest using the signal
handler.  You can write a function to be called when a floating point
exception occurs and handle it there.

#include <signal.h>

int	trapfpe();

main {
    signal (SIGFPE, trapfpe);
    .
    .
    }  /* main */

trapfpe()
{
    printf ("trapfpe: ERROR- Floating point exeption\n");
    /****** Handle the error *******/
    }  /* trapfpe */

My usage of the signal facility is a little bit different from the manual
description (which may be confusing to new programmers), but it is simple 
and it works.

			Colin



More information about the Comp.lang.c mailing list