DIGIT-ARC read-only archive · snapshot: July 23, 2026

prob wid double variable

6 posts · originally from https://geek.digit.in/community/threads/prob-wid-double-variable.84481/

P
prancks Original post #1
Apr 5, 2008 at 2:37 PM
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
M
Apr 5, 2008 at 5:03 PM
Can we see the code? That would make things much easier.
slugger
slugger #3
Apr 5, 2008 at 5:50 PM
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..
P
prancks #4
Apr 6, 2008 at 12:41 AM
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
A
aakash #5
Apr 8, 2008 at 4:04 PM
@ 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
Apr 8, 2008 at 4:11 PM
^+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.