From: Thomas Demmer Newsgroups: comp.os.msdos.djgpp Subject: Re: sqrt() in DJGPP Date: Fri, 20 Feb 1998 10:37:15 +0100 Organization: Lehrstuhl fuer Stroemungsmechanik Lines: 53 Message-ID: <34ED4ECB.5A5C0CBC@LSTM.Ruhr-UNI-Bochum.De> References: <01bd3da9$a0052120$0cf234d1 AT mpanian DOT awinc DOT com> NNTP-Posting-Host: bvb.lstm.ruhr-uni-bochum.de Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Lucas Panian wrote: > > Hi, > > When I try to run my program, it crashes with SIGFPE...I used symify to > find that it was in the following section of code(all variables are already > declared) > > A = Y1 * ( Z2 - Z3 ) + Y2 * ( Z3 - Z1 ) + Y3 * ( Z1 - Z2 ); > B = Z1 * ( X2 - X3 ) + Z2 * ( X3 - X1 ) + Z3 * ( X1 - X2 ); > C = X1 * ( Y2 - Y3 ) + X1 * ( Y3 - Y1 ) + X3 * ( Y1 - Y2 ); > > Distance = sqrt (A*A + B*B + C*C); > > Normal.X = (A / Distance) + VPoint[0]->Lx; // It crashes on this line. > Normal.Y = (B / Distance) + VPoint[0]->Ly; > Normal.Z = (C / Distance) + VPoint[0]->Lz; > > I'm pretty sure SIGFPE is a 'Not-A-Number' error. I'm pretty sure the bad > number is 'Distance.'(have done a little bit of detective work...). So, > they only thing I can think of is an error in the return value of the > sqrt() function. Am I right in this assumption? Any help would be greatly > appreciated. Thanks. ;) I doubt that this is a bug in sqrt(), as it basically boils down to one or two 87-assembler instructions. More probable, you forgot to include , so the compiler assumes the prototype int sqrt( _what_ever_A_s__type_is ); or, Distance happens to be zero, which may or may not be possible following the logic of your code. Recompile the program with the options gcc -Wall -pedantic-errors foo.c to find how to avoid the first possibility, re-think your program's logic to avoid the second. -- 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 * *************************************************************