title: Checking if float is equivalent to an integer value in python
body: <p>In Python 3, I am checking whether a given value is triangular, that is, it can be represented as <code>n * (n + 1) / 2</code> for some positive integer <code>n</code>.</p>
  <p>Can I just write:</p>
  <pre><code>import math
  
  def is_triangular1(x):
      num = (1 / 2) * (math.sqrt(8 * x + 1) - 1)
      return int(num) == num
  </code></pre>
  <p>Or do I need to do check within a tolerance instead?</p>
  <pre><code>epsilon = 0.000000000001
  def is_triangular2(x):
      num = (1 / 2) * (math.sqrt(8 * x + 1) - 1)
      return abs(int(num) - num) &lt; epsilon
  </code></pre>
  <p>I checked that both of the functions return same results for <code>x</code> up to 1,000,000. But I am not sure if generally speaking <code>int(x) == x</code> will always correctly determine whether a number is integer, because of the cases when for example 5 is represented as 4.99999999999997 etc.</p>
  <p>As far as I know, the second way is the correct one if I do it in C, but I am not sure about Python 3.</p>