944,023 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 3411
  • Java RSS
Aug 29th, 2005
0

why is double data type giving an garbage value

Expand Post »
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.
Similar Threads
vps
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vps is offline Offline
10 posts
since Jul 2005
Aug 29th, 2005
0

Re: why is double data type giving an garbage value

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.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Aug 29th, 2005
0

Re: why is double data type giving an garbage value

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
vps
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vps is offline Offline
10 posts
since Jul 2005
Aug 29th, 2005
0

Re: why is double data type giving an garbage value

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).
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: plz! its urgent
Next Thread in Java Forum Timeline: Classpath





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC