forked from jhamman/DHSVM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Round.c
executable file
·40 lines (36 loc) · 1.01 KB
/
Round.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
* 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: [email protected]
* ORIG-DATE: Apr-96
* DESCRIPTION: Round a double to the nearest int
* DESCRIP-END.
* FUNCTIONS: Round()
* COMMENTS:
* $Id: Round.c,v 1.4 2003/07/01 21:26:23 olivier Exp $
*/
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "functions.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;
}