Date: Wed, 26 Aug 1998 15:13:52 +0200 From: Martin Cracauer <cracauer@cons.org> To: Stephen Hocking-Senior Programmer PGS Tensor Perth <shocking@prth.pgs.com>, current@FreeBSD.ORG Subject: Re: Floating Point Exceptions, signal handlers & subsequent ops Message-ID: <19980826151352.A21229@cons.org> In-Reply-To: <19980826144302.C20511@cons.org>; from Martin Cracauer on Wed, Aug 26, 1998 at 02:43:02PM %2B0200 References: <199808250753.PAA29567@ariadne.tensor.pgs.com> <19980825180559.A9890@cons.org> <19980826144302.C20511@cons.org>
next in thread | previous in thread | raw e-mail | index | archive | help
In <19980826144302.C20511@cons.org>, Martin Cracauer wrote:
> In <19980825180559.A9890@cons.org>, Martin Cracauer wrote:
> > In <199808250753.PAA29567@ariadne.tensor.pgs.com>, Stephen Hocking-Senior Programmer PGS Tensor Perth wrote:
> > >
> > > I've noticed in one of my applications that the first FP operation after
> > > return from a caught SIGFPE is invalid. I have a signal handler installed that
> > > just prints out some basic info (like "SIGFPE caught"). The first FP op after
> > > this (in my case, converting a long to a double) just gives garbage. Repeat
> > > the same statement and it gives a sensible result. Has anyone else seen this
> > > before I file a PR with code to reproduce the problem?
> >
> > I just did a short test and for me the next FP operation after a
> > caught SIGFPE (division by zero) is still sane (without
> > setjump/jumpjump).
>
> I'm afraid I was talking nonsense here :-( This test program shows the
> problem. Now the question, why did my other test work well...?
Arg, this code doesn't work because it is missing includes, please
ignore it. Give me a break, I'll follow up with a useful example
later.
> #include <stdio.h>
> #include <stdlib.h>
> #include <signal.h>
>
> void
> handler(int s)
> {
> write(1, "sig\n", 4);
> }
>
> int
> main(void)
> {
> double f0;
> double f2;
> double f4;
> double f8;
> double res;
>
> /* Prevent optimization */
> f0 = atof("0.0");
> f2 = atof("2.0");
> f4 = atof("4.0");
> f8 = atof("8.0");
>
> signal (SIGFPE, handler);
>
> res = f2 / f0;
>
> printf("After division by zero: %g\n", res);
>
> res = f4 + f8;
>
> if (res != 12.0) {
> printf("Next operation didn't work: %g\n", res);
> }
> else {
> printf("Next operation worked: %g\n", res);
> }
>
> return 0;
> }
--
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Martin Cracauer <cracauer@cons.org> http://www.cons.org/cracauer
BSD User Group Hamburg, Germany http://www.bsdhh.org/
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19980826151352.A21229>
