Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Invalid floating point operation 1

Status
Not open for further replies.

puk5629

Programmer
Jul 11, 2010
13
GB
Hi,

Everytime i run the programme, it shows'Invalid floating point operation' at the line, Homogeneous:=1-((Nraysmax-Nraysmin)/(Nraysmax+Nraysmin));. Can someone tell me why?

Following is the coding.

procedure TForm1.Homo(var homogeneous:double);
var
i,Nrays,ibin,jbin:integer;
Nxpoints,Nypoints,Nraysmax,Nraysmin:integer;
xrange,yrange,xbin,ybin,Xmin,Xmax,Ymin,Ymax:double;
begin
Xmin:=0; //set initial point for x
xrange:=1;
yrange:=1; //set the range of area
Nxpoints:=3; //set how many area it will be divided to
Nypoints:=3; //if 100, then nxpoints & nypoints =11, if 10000 = 101
Nraysmax:=0;
Nraysmin:=Nofrays; //initialise
Homogeneous:=0;
Nrays:=0;

for ibin := 1 to Nxpoints-1 do
begin
xbin:=(xrange*ibin)/(Nxpoints-1);
Xmax:=xbin; //set the next point for x
Ymin:=0;
for jbin := 1 to Nypoints-1 do
begin
ybin:=(yrange*jbin)/(Nypoints-1);
Ymax:=ybin; //set the next point for y

for i := 0 to Nofrays - 1 do
begin
if (Newrayposition[i,0]>=Xmin)and(Newrayposition[i,0]<=Xmax)and(Newrayposition[i,1]>=Ymin)and(Newrayposition[i,1]<=Ymax)and(Newrayposition[i,2]=1.4)then
Inc(Nrays);
end;

if Nrays>Nraysmax then
Nraysmax:=Nrays; //set max Nrays
if Nrays<Nraysmin then
Nraysmin:=Nrays; //set min Nrays
Nrays:=0;
//ShowMessage('Nraysmax = '+FloatToStr(Nraysmax));
//ShowMessage('Nraysmin = '+FloatToStr(Nraysmin));
Ymin:=Ymax;
end;
Xmin:=Xmax;
end;
Homogeneous:=1-((Nraysmax-Nraysmin)/(Nraysmax+Nraysmin)); //calculate homogeneous
ShowMessage('Homogeneous = '+FloatToStr(Homogeneous));
end;
 
What are the values of the variables at the time it crashed?
 
In this line of code:
Code:
Homogeneous:=1-((Nraysmax-Nraysmin)/(Nraysmax+Nraysmin));

What are the values of:
Nraysmax
Nraysmin
 
I'm trying to count the number of values falling between the X and Y min and max. So for those that fall under the condition given it will count the number and check whether it is larger than Nraysmax and Nraysmin or not. The initial value of Nraysmax is 0 and Nraysmin is Nofrays where Nrays will never be greater then Nofrays.

for example, if Nofrays=100, then initial Nraysmax=0, Nraysmin=100. So if Nrays=50 for the 1st condition, then Nraysmax=50, Nraysmin=50. if Nrays=30 for the 2nd condition, then Nraysmax=50 and Nraysmin=30.
 
In this line of code:

Homogeneous:=1-((Nraysmax-Nraysmin)/(Nraysmax+Nraysmin));

the Nraysmax=0 and Nraysmin=0
 
Division by zero is undefined in the mathematical world. For computers - division by zero is an error. Typically you would write something like:

Code:
if Nraysmax+Nraysmin = 0 then 
  Homogeneous := 0 
else
  Homogeneous:=1-((Nraysmax-Nraysmin)/(Nraysmax+Nraysmin));
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top