prob wid double variable

Status
Not open for further replies.

prancks

Right off the assembly line
m using g++ compiler
have two double variables t1 and t2
both r getting d same value but
t1-t2 is not zero .. its giving sm junk values...
can anybody help me out wid d reason behind this
 

slugger

Banned
Can we see the code? That would make things much easier.

+1

have you defined the variable propelry

i sumtimes face this problem in borland

i define this variable as int

but while performing the op i accidently put in %f and the result is..
 
OP
P

prancks

Right off the assembly line
void update_leaf(struct l_node * leaf, tupple t)
{
unsigned int z;
leaf->count1=leaf->count1+1;
double old=leaf->count1-1;
double temp, t1,t2,t3,t4;
for(z=0;z<c2.dimension;z++)
{
temp=leaf->mean[z];
leaf->mean[z]=(leaf->mean[z]*old+t.point[z])/leaf->count1;

t1=old*pow(leaf->std[z],2)/leaf->count1;
t2=(old*pow(temp,2)+pow(t.point[z],2))/leaf->count1;
t3=pow(leaf->mean[z],2);
t4=t1+t2-t3;
cout<<t1<<"+"<<t2<<"-"<<t3<<"="<<t4;

leaf->std[z]=sqrt(t4);


}




n here leaf->mean[z] is double and t.point[z] is also of type double
 

aakash

Broken In
@ pranks

1. Make sure you have initialized the variable properly. (Just to be safe)
2. Try putting brackets in the equation where t1 is getting a value. Always advisable to perform multiplication first and then division.
 

ray|raven

Think Zen.
^+1, Also dude , post the entire code,
Do we have to guess what the variables such as c2 are?
And please , try following a naming convention.
 
Status
Not open for further replies.
Top Bottom