Results 1 to 5 of 5
- 05-09-2012, 09:38 PM #1
Should you always use Double.compare( double d1, double d2 ) for >= and <=?
Hello all.
I was looking over the API and reading some documentation. There is a compelling case to when trying to do a direct comparison ( == ) for one double to be equal to another double.
I was wanting to know if this is really necessary when using <, <=, >, or >= operators?
Thanks.If you aren't programming in Java, well that's just too bad.
I'd rather be using Ubuntu.
- 05-09-2012, 09:46 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
Re: Should you always use Double.compare( double d1, double d2 ) for >= and <=?
Primitve types (such a double with a lower case 'd') can (and must) be compared with the operators <, <=, >, >=, == and !=. It's only the class types (such as Double etc.) that need to be compared using a method such as the compareTo( ... ) method.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 05-09-2012, 10:14 PM #3
- 05-10-2012, 02:45 AM #4
Re: Should you always use Double.compare( double d1, double d2 ) for >= and <=?
compare(...) is not compareTo(...)
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 05-10-2012, 07:03 AM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
double a * double b = weird output
By GPB in forum New To JavaReplies: 3Last Post: 03-26-2010, 10:40 AM -
Check if double is double
By marshalthrone in forum New To JavaReplies: 8Last Post: 09-30-2009, 02:51 PM -
non-static method add(double,double) cannot be referenced from a static context
By cravi85 in forum Java SoftwareReplies: 5Last Post: 03-21-2009, 09:32 PM -
Double
By Xystus777 in forum New To JavaReplies: 2Last Post: 01-21-2009, 10:39 AM -
Double.valueOf() vs Double.parseDouble()
By greenbean in forum New To JavaReplies: 10Last Post: 01-12-2009, 08:39 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks