# Should you always use Double.compare( double d1, double d2 ) for >= and <=?

Printable View

• 05-09-2012, 09:38 PM
stchman
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.
• 05-09-2012, 09:46 PM
JosAH
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,

Jos
• 05-09-2012, 10:14 PM
stchman
Re: Should you always use Double.compare( double d1, double d2 ) for >= and <=?
Quote:

Originally Posted by JosAH
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,

Jos

The Double.compare( double d1, double d2 ) take primitive arguments?
• 05-10-2012, 02:45 AM
DarrylBurke
Re: Should you always use Double.compare( double d1, double d2 ) for >= and <=?
compare(...) is not compareTo(...)

db
• 05-10-2012, 07:03 AM
JosAH
Re: Should you always use Double.compare( double d1, double d2 ) for >= and <=?
Quote:

Originally Posted by stchman
The Double.compare( double d1, double d2 ) take primitive arguments?

Carefully read the API documentation for the Double class.

kind regards,

Jos