From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <24e8030bb296cc275117eb3d93aff579.axp-list@archive.invalid> X-Archive-Original-Message-ID: <199802120049.TAA07622@ulexite.nist.gov> Date: Thu, 12 Feb 1998 05:01:34 +0000 From: Jim Paradis Subject: Re: Another Floating Point Weirdness Francesco Callari wrote: > > Apropos of FP weirdness. > Can someone tell me why the following program will get > a floating point exception (SIGFPE) ? > > #include > #include > #include > > int main(int argc, char* argv[]) > { > int i, j; > double v,m; /* works fine with m=0.0 */ > > assert(finite(m)); /* passes this test */ > > for (j=-10; j<=0; j++) { > v=exp(-(double)j); > if (v > m ) { /* dies with SIGFPE here */ > m=v; > } > } > } Since "m" is uninitialized, it's anybody's guess as to what its initial value actually is. In most cases, it will be some stack pointer address. This gets interpreted as an IEEE *denormal* number. Since this is not an "infinity", it passes the "finite" test. Note that if you build the program with "-mieee", you avoid the SIGFPE. But in general, uninitialized variables are a bad idea. -- Jim Paradis jrp@jrp.tiac.net "The early bird gets the worm. http://www.tiac.net/users/jrp/index.html If you want something else for breakfast, get up later." -- To unsubscribe: send e-mail to axp-list-request@redhat.com with 'unsubscribe' as the subject. Do not send it to axp-list@redhat.com