title: Can I speed up my special round function?
body: <p>I have this function:</p>
  
  <pre><code>int round(double val) {
      if (val &gt;= 0) {
          return (int)Math.Floor(val + 0.5);
      }
      return (int)Math.Ceiling(val - 0.5);
  }
  </code></pre>
  
  <p>I call it in my program many times, I mean MANY times, so every milisecond of it's running time matters. Is there any way of having it faster than it is now? Thx</p>
  
  <p>EDIT: </p>
  
  <p>The function is part of algorithm for computing the tangent direction of a line in an image. It is taken from academic article. As it handles the angles in radian values, it uses small, precise numbers.</p>
  
  <p>I/O examples:</p>
  
  <pre><code>0 -&gt; 0
  1 -&gt; 1
  1.1 -&gt; 1
  1.51 -&gt; 2
  -0.1 -&gt; 0
  -1 -&gt; -1
  -1.1 -&gt; -1
  -1.51 -&gt; -2
  </code></pre>
  
  <p>EDIT2:</p>
  
  <p>According to comments, I change the examined function to this one:</p>
  
  <pre><code>int round(double val) {
      return (int)Math.Round(val, MidpointRounding.AwayFromZero);
  }
  </code></pre>
  
  <p>The updated question is: Is the Math.Round function the fastest way of rounding?</p>