title: Implement ceil() in C
body: <p>I want to implement my own <code>ceil()</code> in <code>C</code>. Searched through the libraries for source code &amp; found <a href="http://code.google.com/p/dexandroid/source/search?q=ceil.c&amp;origq=ceil.c&amp;btnG=Search%20Trunk" rel="nofollow noreferrer">here</a>, but it seems pretty difficult to understand. I want clean &amp; elegant code.</p>
  
  <p>I also searched on SO, found some answer <a href="https://stackoverflow.com/questions/2796639/implementation-of-ceil-function-in-c">here</a>. None of the answer seems to be correct. One of the answer is:</p>
  
  <pre><code>#define CEILING_POS(X) ((X-(int)(X)) &gt; 0 ? (int)(X+1) : (int)(X))
  #define CEILING_NEG(X) ((X-(int)(X)) &lt; 0 ? (int)(X-1) : (int)(X))
  #define CEILING(X) ( ((X) &gt; 0) ? CEILING_POS(X) : CEILING_NEG(X) )
  </code></pre>
  
  <p>AFAIK, the return type of the <code>ceil()</code> is not int. Will macro be type-safe here?
  Further, will the above implementation work for negative numbers?</p>
  
  <p>What will be the best way to implement it?</p>
  
  <p>Can you provide the clean code?</p>