comparison future.c @ 16:9d57d1fcbcd5

Implementation of the C99 round() function
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Wed, 18 Jul 2012 18:47:44 +0200
parents
children be814b934eca
comparison
equal deleted inserted replaced
15:b2103439b401 16:9d57d1fcbcd5
1 /* welcome in the 2012 */
2
3 /* required by CVI */
4 #include <ansi_c.h>
5
6 /* an implementation of the C99 `round` function based on `floor` and `ceil` */
7 double round(double x)
8 {
9 if (x >= 0.0) {
10 double y = floor(x);
11 if (x - y >= 0.5)
12 y += 1.0;
13 return y;
14 } else {
15 double y = ceil(x);
16 if (x - y >= 0.5)
17 y -= 1.0;
18 return y;
19 }
20 }