Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8257086

Clarify differences between {Float, Double}.equals and ==

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 17
    • 16
    • core-libs
    • None
    • b08

      The equals methods on Float and Double are *not* just wrappers around the corresponding == operator because the IEEE 754 == operator does *not* define an equivalence relation. The properties of an equivalence relation are broken by NaN (since NaN is not equal to itself) and by -0.0/+0.0. While -0.0 and +0.0 compare as equal, they are distinct values that can change the value of a result of an operation; for example, +1.0/+0.0 is positive infinity while +1.0/-0.0 is negative infinity.

      This situation could be more clearly motivated than the oblique "This definition allows hash tables to operate properly." statement equals methods.

            darcy Joe Darcy
            darcy Joe Darcy
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: