/*
 * SUMMARY:      Round.c - Round a double to the nearest int
 * USAGE:        Part of DHSVM
 *
 * AUTHOR:       Bart Nijssen
 * ORG:          University of Washington, Department of Civil Engineering
 * E-MAIL:       nijssen@u.washington.edu
 * ORIG-DATE:    Apr-96
 * LAST-MOD: Mon Apr 14 13:33:51 1997 by Bart Nijssen <nijssen@meter.ce.washington.edu>
 * DESCRIPTION:  Round a double to the nearest int
 * DESCRIP-END.
 * FUNCTIONS:    Round()
 * COMMENTS:     
 */

#ifndef lint
static char vcid[] = "$Id: Round.c,v 1.2 2001/03/31 00:10:34 waichler Exp $";
#endif /* lint */

#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "round.h"
#include "DHSVMerror.h"

/*****************************************************************************
  Round()
*****************************************************************************/
int Round(double x)
{
  int RoundX;

  if (x < INT_MIN || x > INT_MAX) {
    printf("%f\n", x);
    ReportError("Round()", 16);
  }
  if ((fabs(x) - floor(fabs(x))) < 0.5) 
      RoundX = (int) ((x < 0) ? ceil(x) : floor(x));
  else 
      RoundX = (int) ((x < 0) ? floor(x) : ceil(x));
    
  return RoundX;
}


