title: rint not present in Visual Studio 2010 math.h and equivalent of CUDA rint
body: <p>I'm porting a CUDA code to C++ and using Visual Studio 2010. The CUDA code uses the <code>rint</code> function, which does not seem to be present in the Visual Studio 2010 math.h, so it seems that I need to implement it by myself.</p>
  
  <p>According to this <a href="http://developer.download.nvidia.com/compute/cuda/4_2/rel/toolkit/docs/online/group__CUDA__MATH__DOUBLE_g3b8026edb2f2e441669845f0f3fa3bf7.html" rel="nofollow">link</a>, the CUDA <code>rint</code> function </p>
  
  <p><em>rounds x to the nearest integer value in floating-point format, with halfway cases rounded towards zero.</em></p>
  
  <p>I think I could use the casting to <code>int</code> which discards the fractional part, effectively rounding towards zero, so I ended-up with the following function</p>
  
  <pre><code>inline double rint(double x)
  {
      int temp; temp = (x &gt;= 0. ? (int)(x + 0.5) : (int)(x - 0.5));
      return (double)temp;
  }
  </code></pre>
  
  <p>which has two different castings, one to <code>int</code> and one to <code>double</code>.</p>
  
  <p>I have three questions:</p>
  
  <ol>
  <li>Is the above function fully equivalent to CUDA <code>rint</code> for "small" numbers? Will it fail for "large" numbers that cannot be represented as an <code>int</code>?</li>
  <li>Is there any more computationlly efficient way (rather than using two castings) of defining <code>rint</code>?</li>
  </ol>
  
  <p>Thank you very much in advance.</p>