Mail Archives: djgpp/1998/02/20/18:15:42
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 <math.h>, 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 *
*************************************************************
- Raw text -