delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/28/23:42:26

Mime-Version: 1.0
To: jdk AT wpol DOT com, djgpp AT delorie DOT com
From: Nate Eldredge <nate AT cartsys DOT com>
Subject: Re: (none)
Date: Tue, 28 Apr 1998 20:37:11 -0700
Message-ID: <19980429033703.AAB3301@ppp104.cartsys.com>

At 12:25  4/27/1998 GMT, John Kissell wrote:
>My bet is on Dist = a negative value! Put a printf in front of the sqrt
>function to report 'Dist's actual value.

If the code the poster posted is similar to that which causes the problem,
that's impossible. `Dist' is equal to the sum of the squares of three
numbers. The square of a real number is always positive, and the sum of two
or more positive numbers is always positive.

But your advice is reasonable in any case, since `Dist' might for instance
be overflowing.

>
>
>Daniel Delorme wrote:
>> 
>> I have this problem with SIGFPE...
>> 
>> double DistanceBetweenPoints(strPOINT *Pt1, strPOINT *Pt2)
>> {
>>   double Dist;
>> 
>>   Dist = pow(fixtof(Pt1->X - Pt2->X), 2)+
>>          pow(fixtof(Pt1->X - Pt2->X), 2)+
>>          pow(fixtof(Pt1->X - Pt2->X), 2);
>>   Dist = sqrt(Dist);
>>   printf("Dist = %f\n", Dist);  <----- program crashes here with SIGFPE
>> }
>> 
>> traceback:
>> _doprnt+3548
>> _doprnt+1574
>> printf+20
>> DistanceBetweenPoints
>> 
>> and I #included math.h
>> 
>> Why would SIGFPE appear in a mere printf ?
>> What causes SIGFPE anyway ?
>> If I remove the printf, I get SIGFPE at "if (Dist1[I] <= Dist2[J])"
>>   (Dist1[6] and Dist2[6] are float)
>

Nate Eldredge
nate AT cartsys DOT com



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019