title: Can I compare whether two floating-point number are equal in Kotlin?
body: <p>The following code is from <a href="https://kotlinlang.org/docs/reference/functions.html?q=&amp;p=0" rel="noreferrer">https://kotlinlang.org/docs/reference/functions.html?q=&amp;p=0</a></p>
  
  <p>This code calculates the fixpoint of cosine, which is a mathematical constant. It simply calls Math.cos repeatedly starting at 1.0 until the result doesn't change any more, yielding a result of 0.7390851332151607. </p>
  
  <p>In my mind, we can't compare whether two floating-point number are equal, so I think that the result of <code>if (x == y)</code> is always false, right?</p>
  
  <pre><code>private fun findFixPoint(): Double {
      var x = 1.0
      while (true) {
          val y = Math.cos(x)
          if (x == y) return y
          x = y
      }
  }
  </code></pre>