Results 1 to 5 of 5
  1. #1
    stchman's Avatar
    stchman is offline Member
    Join Date
    Apr 2011
    Location
    Saint Louis, Missouri
    Posts
    97
    Rep Power
    0

    Default 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.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

    Default 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
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    stchman's Avatar
    stchman is offline Member
    Join Date
    Apr 2011
    Location
    Saint Louis, Missouri
    Posts
    97
    Rep Power
    0

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

    Quote Originally Posted by JosAH View Post
    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?
    If you aren't programming in Java, well that's just too bad.
    I'd rather be using Ubuntu.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

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

    compare(...) is not compareTo(...)

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

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

    Quote Originally Posted by stchman View Post
    The Double.compare( double d1, double d2 ) take primitive arguments?
    Carefully read the API documentation for the Double class.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. double a * double b = weird output
    By GPB in forum New To Java
    Replies: 3
    Last Post: 03-26-2010, 10:40 AM
  2. Check if double is double
    By marshalthrone in forum New To Java
    Replies: 8
    Last Post: 09-30-2009, 02:51 PM
  3. Replies: 5
    Last Post: 03-21-2009, 09:32 PM
  4. Double
    By Xystus777 in forum New To Java
    Replies: 2
    Last Post: 01-21-2009, 10:39 AM
  5. Double.valueOf() vs Double.parseDouble()
    By greenbean in forum New To Java
    Replies: 10
    Last Post: 01-12-2009, 08:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •