title: Matching FORTRAN rounding in C#
body: <p>FORTRAN provides several functions to convert a double precision number to an integral value.  The method used for truncation/rounding differs.  I am converting complex scientific algorithms which use these.</p>
  
  <p>According to FORTRAN documentation:<br>
  <b>aint(x)</b> returns the integral value between x and 0, nearest x.<br>
  <b>anint(x)</b> returns the nearest integral value to x, except halfway cases are
           rounded to the integral value larger in magnitude.<br>
  <b>nint(x)</b> converts x into int format rounding to the nearest int value, except
           halfway cases are rounded to the int value larger in magnitude.</p>
  
  <p><b>Does anyone have an implementation of these in C#?</b>
  It might be tricky getting it right.</p>
  
  <p>(int)x appears to match aint()<br>
  Convert.ToInt32(x) does not match any of the above.<br>
  Trunc(x) does not match any of the above.<br>
  Round(x) might match anint or nint. <br></p>
  
  <p>The difference between anint and nint seems to be the return type, where anint returns a double precision value but nint returns an integer.  Both are used (acutal sample):<br>
  DOUBLE PRECISION A, B, C, D, E, F, G<br>
  ... values set here ...<br>
  F = ANINT(A-B) + ANINT(C-D) + ANINT(B+D-E)<br>
  G = NINT(F) + 1D0;<br>
  Perhaps a FORTRAN expert could help clarify why the author chose to use both (I am assuming it was intentional).</p>