From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10ba33,fd21959b44c0a9b0 X-Google-Attributes: gid10ba33,public X-Google-Thread: 111c93,fd21959b44c0a9b0 X-Google-Attributes: gid111c93,public From: "H.W. Stockman" Subject: Re: small doubles, g++, glibc, and linux/alpha problems Date: 1998/03/08 Message-ID: <35033E60.29BB@swcp.com>#1/1 X-Deja-AN: 332091309 Content-Transfer-Encoding: 7bit References: <3503303E.3E5B5838@ix.netcom.com> To: C R Johnson Content-Type: text/plain; charset=us-ascii Organization: Lentil Sorbet, Inc. Mime-Version: 1.0 Reply-To: hwstock@swcp.com Newsgroups: gnu.g++.help,comp.os.linux.alpha C R Johnson wrote: > > g++ 2.7 and egcs 1.0.1 running on a linux-alpha-glibc > system > is not taking kindly to small double values - those funky > near zero values that you know should be zero, but have > stupid values > like 2.38723e-314. > > The problem does not show itself on my linux-intel-glibc > system. > > #include > #include > > int main() > { > cerr << "hello" << endl; > > double u = 2.38723e-314; > > cerr << "u = " << u << " M_PI = " << M_PI << endl; > cerr << "u * M_PI = " << u * M_PI << endl; > > return 0; > } > > The results: > > on linux - alpha - glibc > +++++++++++++++++++++++++++++++++++++ > > [cliff@van cliff]$ g++ hello.c++ -g -o hello <-- using gcc > 2.7.1 > [cliff@van cliff]$ ./hello > hello > u = Floating point exception (core dumped) > [cliff@van cliff]$ eg++ hello.c++ -g -o hello <-- using > egcs 1.0.1 > [cliff@van cliff]$ ./hello > hello > u = 2.38723e-314 M_PI = 3.14159 > u * M_PI = Floating point exception (core dumped) > > slightly different results, but both hosed. > > on linux - intel - glibc > +++++++++++++++++++++++++ > > [cliff@brother_brent cliff]$ eg++ hello.c++ -g -o hello > [cliff@brother_brent cliff]$ hello > hello > u = 2.38723e-314 M_PI = 3.14159 > u * M_PI = 7.4997e-314 > > No problem ( with either compiler ) . > > Can anybody explain this? Is it a known problem? Can it be > fixed. Must I > resort to float's? On an x86, 2.38723e-314 is a valid representation as a denormal, and can be loaded onto the processor as such. The alpha does not handle denormals in the processor, and generates an exception when they are encountered. You can't represent 2.38723e-314 as a normal IEEE double precision number.