From owner-freebsd-hackers Thu Mar 11 9:49: 2 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from wall.polstra.com (rtrwan160.accessone.com [206.213.115.74]) by hub.freebsd.org (Postfix) with ESMTP id 17A7114CAA for ; Thu, 11 Mar 1999 09:48:59 -0800 (PST) (envelope-from jdp@polstra.com) Received: from vashon.polstra.com (vashon.polstra.com [206.213.73.13]) by wall.polstra.com (8.9.1/8.9.1) with ESMTP id JAA17720; Thu, 11 Mar 1999 09:48:40 -0800 (PST) (envelope-from jdp@polstra.com) From: John Polstra Received: (from jdp@localhost) by vashon.polstra.com (8.9.2/8.9.1) id JAA57916; Thu, 11 Mar 1999 09:48:40 -0800 (PST) (envelope-from jdp@polstra.com) Date: Thu, 11 Mar 1999 09:48:40 -0800 (PST) Message-Id: <199903111748.JAA57916@vashon.polstra.com> To: cjclark@home.com Subject: Re: FP Math Problem In-Reply-To: <199903042248.RAA08114@cc942873-a.ewndsr1.nj.home.com> Organization: Polstra & Co., Seattle, WA Cc: hackers@freebsd.org Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG In article <199903042248.RAA08114@cc942873-a.ewndsr1.nj.home.com>, Crist J. Clark wrote: > I am trying to figure out why the following program produces a > floating point exception and core dumps. > > #include > #include > #include > > int main() > { > > double a = 1e200; > double b; > > printf("fpgetmask: %o\n",fpgetmask()); > > printf("a: %e\n",a); > > b = a*a; > > printf("isinf: %d\n",isinf(b)); > > printf("isnan: %d\n",isnan(b)); > > printf("b > DBL_MAX: %d\n",b>DBL_MAX); > > printf("b: %e\n",b); > > return 0; > } > > My output is, > > [112:~/tmp] ./dtest > fpgetmask: 15 > a: 1.000000e+200 > isinf: 0 > isnan: 0 > Floating exception (core dumped) > > I started with this on -questions and (although the thread got > sidetracked by a bad test program I presented at the beginning) other > FreeBSDers have not reproduced the error, but get what I would expect, > > % ./dtest > fpgetmask: 15 > a: 1.000000e+200 > isinf: 1 > isnan: 0 > b > DBL_MAX: 1 > b: inf > > However, I get the FPE and core dump on my three FreeBSD machines > (different hardware on each). I played around with this a little bit on a Pentium-II. I also got the floating exception. There _should_ be a floating exception, but it should happen at the "b = a*a" statement, I believe. If you add a second "b = a*a" after it, then you do get the FPE. As the code is written, for some reason nothing is stored into b at all. That's why some people get the core dump later on and others don't. (It might also depend on the specific FP hardware.) You can confirm this by initializing b to 1.0. Bruce Evans could probably explain this. You might wish to ask him about it. John -- John Polstra jdp@polstra.com John D. Polstra & Co., Inc. Seattle, Washington USA "Nobody ever went broke underestimating the taste of the American public." -- H. L. Mencken To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message