title: Use of Ceil and Integers
body: <p>So I just got my grade back from a school project that I did well on, but the grader took five points off because I didn't make a call to ceil(...).  Its a parallel computing course using CUDA, but the question isn't directly related to any CUDA feature.</p>
  
  <p>Here is the "offending" line:</p>
  
  <pre><code>dim3 dimGrid(n / dimBlock.x, n / dimBlock.y);
  </code></pre>
  
  <p>His claim is that I should have done:</p>
  
  <pre><code>dim3 dimGrid(ceil(n / dimBlock.x), ceil(n / dimBlock.y));
  </code></pre>
  
  <p>So my question is, why would I be marked off for this if n and dimBlock.* are integers?  Their result will be calculated before ceil is even called and truncated.  Thus it seems silly to mark off for that.</p>
  
  <p>The following examples below seem to show that GCC optimizes the call out anyway when using -O2.</p>
  
  <p>With ceil:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;math.h&gt;
  
  int main()
  {
          int m = 3, n = 5, o;
  
          o = ceil(n / m);
          printf("%d\n", o);
          return 0;
  }
  </code></pre>
  
  <p>Without:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;math.h&gt;
  
  int main()
  {
          int m = 3, n = 5, o;
  
          o = n / m;
          printf("%d\n", o);
          return 0;
  }
  </code></pre>
  
  <p>While I understand its only five points, I still want to understand why if I am completely wrong.</p>