Home arrow static arrow Java Programming [Archive] - Is there a bug in jdk?
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Is there a bug in jdk?
This topic has 14 replies on 1 page.

Posts:56
Registered: 7/9/02
Is there a bug in jdk?  
Jun 30, 2004 5:43 AM



 
Hi,

When i try adding 0.14+001 it gives

0.15000000000000002

I tried both 1.4.2_02 and 1.4.2_04.
 

Posts:196
Registered: 6/29/04
Re: Is there a bug in jdk?  
Jun 30, 2004 5:57 AM (reply 1 of 14)



 
Hi,

When i try adding 0.14+001 it gives

0.15000000000000002

I tried both 1.4.2_02 and 1.4.2_04.

This is a known problem.
Just to be safe, you should subtract 0.00000000000000002 from all floating point values you calculate.
 

Posts:1,995
Registered: 12/10/00
Re: Is there a bug in jdk?  
Jun 30, 2004 5:57 AM (reply 2 of 14)



 
There are many things to do before claiming a bug. Basic ones:
1. Do a [url http://onesearch.sun.com/search/developers/index.jsp?col=devforums&qp_name=Java+Programming&qp=forum%3A31&qt=%2Badd+%2Bdouble+%2Bprecision]search[/url], someone might have met the problem before.

2. Paste a short code example that can be compiled by others. Post real code, for example you added 0.14+0.01 and not 0.14+001 as you posted.

3. Write descriptive titles, claiming that you found a bug will not attract more people and is considered rude.

HTH
Mike

 

Posts:2,909
Registered: 13.8.2003
Re: Is there a bug in jdk?  
Jun 30, 2004 6:03 AM (reply 3 of 14)



 
Q: Is there a bug in jdk?

A: Yes, many bugs but you're not gonna find them.
 

Posts:21,719
Registered: 98-02-20
Re: Is there a bug in jdk?  
Jun 30, 2004 6:03 AM (reply 4 of 14)



 
[url=http://docs.sun.com/source/806-3568/ncg_goldberg.html]What Every Computer Scientist Should Know About Floating Point Numbers[/url]

Bug, indeed.

%
 

Posts:56
Registered: 7/9/02
Re: Is there a bug in jdk?  
Jun 30, 2004 6:13 AM (reply 5 of 14)



 
Ok, excuse me.

But if you realized, i didn't claim that i found a bug, i just asked a question if there is a bug.

I just wanna solve my problem.

Looks like subtracting 0.00000000000000002 does not solve the problem always.

System.out.println(4.14+0.01-0.00000000000000002);

gives 4.1499999999999995

What do you suggest?
 

Posts:580
Registered: 8/21/02
Re: Is there a bug in jdk?  
Jun 30, 2004 6:16 AM (reply 6 of 14)



 

Looks like subtracting 0.00000000000000002 does not
solve the problem always.

That was sarcasm dear. Try to search the forum to find solution to this "problem"
 

Posts:1,995
Registered: 12/10/00
Re: Is there a bug in jdk?  
Jun 30, 2004 6:17 AM (reply 7 of 14)



 
The second thread from the search limk I pasted should lead you to solution... That is if you cared to do some self-education job yourself

Mike
 

Posts:2,830
Registered: 9/1/03
Re: Is there a bug in jdk?  
Jun 30, 2004 6:24 AM (reply 8 of 14)



 
What do you suggest?

Try adding .00000000000005, and keep repeating this until you
get to the correct result.
 

Posts:56
Registered: 7/9/02
Re: Is there a bug in jdk?  
Jun 30, 2004 6:30 AM (reply 9 of 14)



 
Thanks for the link.
 

Posts:1,652
Registered: 8/4/03
Re: Is there a bug in jdk?  
Jun 30, 2004 7:09 AM (reply 10 of 14)



 
As another poster has said, there are many bugs in Java as well as a few vaguries that just don't make much sense to me personally. Most of them are very well documented and as has been recommended by other posters you can find them by doing a search. Handy things search engines.

If you were to find an as yet undiscovered bug in the JDK, that would elevate you into a rather select group, most of whom work for Sun Microsystems.

All of that said. Assuming that when something doesn't behave the way you anticipate it behaving is a bug in the JDK is symptomatic of a rather dangerous trait, that being blaming something or someone else when there's a problem.

99.999999999% of the time, abherant behavior on the part of your code is going to be the result of one and only one thing, a mistake at some point by you. Now I'm not saying that that makes you a bad programmer or anything of the sort, what I'm saying is that it makes you just like the rest of us. What you must understand though is that it's not the fault of the JDK (most of the time), and it's not the fault of the server platform (most of the time) and it's not the fault of the JVM (most of the time). It's your problem, and it's your responsibility to fix.

Embrace the idea that it's your problem, and things will go much more smoothly for you.

Good luck.
 

Posts:21,719
Registered: 98-02-20
Re: Is there a bug in jdk?  
Jun 30, 2004 7:20 AM (reply 11 of 14)



 
I suggest that you understand that this is how floating point numbers work.

If you don't like the appearance you're getting, try java.text.NumberFormat or java.text.DecimalFormat to round it into something more appealing.

Don't blame the JVM when there are problems. Assume that you're doing something wrong and you'll get farther faster.

%
 

Posts:196
Registered: 6/29/04
Re: Is there a bug in jdk?  
Jun 30, 2004 7:20 AM (reply 12 of 14)



 
99.999999999% of the time, abherant behavior on the part of your code is going to be the result of one and only one thing, a mistake at some point by you.

^^^^^^^^^^^^^^^^^^^ Look at that! Another precision bug!
 

Posts:1,652
Registered: 8/4/03
Re: Is there a bug in jdk?  
Jun 30, 2004 7:22 AM (reply 13 of 14)



 
99.999999999% of the time, abherant behavior on the
part of your code is going to be the result of one and
only one thing, a mistake at some point by you.

^^^^^^^^^^^^^^^^^^^ Look at that! Another precision
bug!

ROLLS ON THE FLOOR LAUGHING OFF SEVERAL EXTRANEOUS BODY PARTS

 

Posts:24,036
Registered: 2/3/03
Re: Is there a bug in jdk?  
Jun 30, 2004 7:38 AM (reply 14 of 14)



 
Piling on, but pithy words, nonetheless:

Don't claim that you have found a bug. When you are having problems with a piece of software, don't claim you have found a bug unless you are very, very sure of your ground. Hint: unless you can provide a source-code patch that fixes the problem, or a regression test against a previous version that demonstrates incorrect behavior, you are probably not sure enough.

Remember, there are a lot of other users that are not experiencing your problem. Otherwise you would have learned about it while reading the documentation and searching the Web (you did do that before complaining, didn't you?). This means that very probably it is you who are doing something wrong, not the software.

From [url=http://www.catb.org/~esr/faqs/smart-questions.html]How To Ask Questions The Smart Way[/url] by Eric Steven Raymond
 
This topic has 14 replies on 1 page.