Mail Archives: djgpp/1998/03/05/02:45:42
D. Huizenga wrote:
>
> Hi.
>
> I have a realativly simple question: is it possible to trap errors in
> DJGPP after they occur? What I mean is if something like an FPE occurs,
> is it possible to have DJGPP run a function which attempts to correct
> the problem? This is probably a really stupid question, but thanks for
> your help.
Yes, you can.
volatile int merr=0;
static unsigned int fpcw;
void math_handler(int sig){
fpcw = _clear87() & 0xff;
printf("SIGFPE: %x\n",fpcw);
merr = fpcw;
}
int main(int argc, char **argv){
double foo,bar;
signal(SIGFPE,math_handler);
foo=0.; bar = 1.;
bar = bar/foo;
return 0;
}
You also may want to include <libm/math.h>,
say
_fdlib_version = _SVID_;
_control87(EM_UNDERFLOW, ~EM_UNDERFLOW);
_control87(EM_INEXACT, ~EM_INEXACT);
and define your own
int matherr(struct exception *e)
to correct errors...
--
Ciao
Tom
*************************************************************
* Thomas Demmer *
* Lehrstuhl fuer Stroemungsmechanik *
* Ruhr-Uni-Bochum *
* Universitaetsstr. 150 *
* D-44780 Bochum *
* Tel: +49 234 700 6434 *
* Fax: +49 234 709 4162 *
* http://www.lstm.ruhr-uni-bochum.de/~demmer *
*************************************************************
- Raw text -