why is double data type giving an garbage value

Reply

Join Date: Jul 2005
Posts: 10
Reputation: vps is an unknown quantity at this point 
Solved Threads: 0
vps vps is offline Offline
Newbie Poster

why is double data type giving an garbage value

 
0
  #1
Aug 29th, 2005
hi

i am using a variable as double
and passing pointer of it as parameter to an api
this is all hapening in JNI.
after i read the value i am getting an garbage value
can anybody tel me y is it hapenning,
using an float variable instead of double solves my problem.
but y is double so.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: why is double data type giving an garbage value

 
0
  #2
Aug 29th, 2005
hmm, you seem to be missing the w and h keys on your keyboard.

As to your "problem", your native program is probably setting the value to a 32 bit floating point number.
Double in Java is a 64 bit floating point number. Either use a 64 bit floating point data type in the native code or use float in Java which is 32 bit.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 10
Reputation: vps is an unknown quantity at this point 
Solved Threads: 0
vps vps is offline Offline
Newbie Poster

Re: why is double data type giving an garbage value

 
0
  #3
Aug 29th, 2005
Thanx for the reply

but why is it giving me an value like 7.16485306107743e-040 , n if i run in while loop it gives me different value each time even after the variable is intialized to ZERO i.e. 0.00
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: why is double data type giving an garbage value

 
0
  #4
Aug 29th, 2005
http://docs.sun.com/source/806-3568/ncg_goldberg.html has the answers to that.
It's a must read for anyone working with floating point arithmetic.

Basically what you're seeing is the imperfection of the storage of floating point numbers in fixed precision numbers based on integers (which is how every computer stores them).
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC