Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 05-04-2008, 02:37 PM   #1 (permalink)
Right Off the Assembly Line
 
Join Date: Apr 2008
Posts: 2
Default prob wid double variable


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
prancks is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 05-04-2008, 05:03 PM   #2 (permalink)
18 Till I Die............
 
Join Date: Jul 2004
Location: India, Mumbai, Marine Lines
Posts: 5,792
Default Re: prob wid double variable

Can we see the code? That would make things much easier.
__________________
http://www.bash.org/?258908
mehulved is offline  
Old 05-04-2008, 05:50 PM   #3 (permalink)
Banned
 
slugger's Avatar
 
Join Date: May 2004
Location: Baudland
Posts: 2,433
Default Re: prob wid double variable

Quote:
Originally Posted by mehulved View Post
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..
slugger is offline  
Old 06-04-2008, 12:41 AM   #4 (permalink)
Right Off the Assembly Line
 
Join Date: Apr 2008
Posts: 2
Default Re: prob wid double variable

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
prancks is offline  
Old 08-04-2008, 04:04 PM   #5 (permalink)
Apprentice
 
Join Date: Apr 2004
Location: India
Posts: 50
Default Re: prob wid double variable

@ 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.
__________________
Aakash Shah
aakash is offline  
Old 08-04-2008, 04:11 PM   #6 (permalink)
Think Zen.
 
ray|raven's Avatar
 
Join Date: Dec 2005
Posts: 1,498
Default Re: prob wid double variable

^+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.
__________________
Do what you will; but not because you must. -- Zen Quote
ray|raven is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how add environment variable in ubuntu mak1012 Open Source 17 17-09-2007 05:48 PM
Help with SC:DOUBLE AGENT ratzee199 Gamerz 11 15-05-2007 12:37 PM
cant declare a string variable... geekgod Open Source 13 12-08-2006 06:09 AM
In Excel How to use cell ref as a variable abhijitroy Software Q&A 1 10-07-2006 02:32 PM
Right double click nil_3 QnA (read only) 10 31-12-2005 04:29 AM

 
Latest Threads
- by Charan
- by Sarath
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 12:56 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2