/*
 *
 *                      rintx.c
 *
 *
 *   rintx(x) -  it ought to work as the original Unix function rint
 *
 *   Marek Krawus, PCC, March '89
 *
 */
#include <math.h>

int
rintx(x)
float    x;
 {
    float    left, right;
    int      l, r;

    /*  to the nearest int from left */
    l = floor(x);
    left = x - l; 

    /* to the nearest int from right */
    r = ceil(x);
    right = r - x; 

    if ((left - right) == 0)
      {
        if ((r/2)*2 == r)  
	   return(r);
        else
	   return(l);
      }
    else
      { if ((left - right) > 0)
           {
	     return(r); 
           }
        else
	   {
             return(l);
           }
      }
 }
