title: How to safely floor or ceil a CGFloat to int?
body: <p>I often need to floor or ceil a <code>CGFloat</code> to an <code>int</code>, for calculation of an array index.</p>
  
  <p>The problem I permanently see with <code>floorf(theCGFloat)</code> or <code>ceilf(theCGFloat)</code> is that there can be troubles with floating point inaccuracies.</p>
  
  <p>So what if my <code>CGFloat</code> is <code>2.0f</code> but internally it is represented as <code>1.999999999999f</code> or something like that. I do <code>floorf</code> and get <code>1.0f</code>, which is a float again. And yet I must cast this beast to int which may introduce another problem.</p>
  
  <p>Is there a best practice how to floor or ceil a <code>float</code> to an <code>int</code> such that something like <code>2.0</code> would never accidentally get floored to <code>1</code> and something like <code>2.0</code> would never accidentally get ceiled to <code>2</code>?</p>