changeset 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 b2103439b401
children 9cadd12e7722
files future.c future.h
diffstat 2 files changed, 21 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/future.c	Wed Jul 18 18:47:44 2012 +0200
@@ -0,0 +1,20 @@
+/* welcome in the 2012 */
+
+/* required by CVI */
+#include <ansi_c.h>
+
+/* an implementation of the C99 `round` function based on `floor` and `ceil` */
+double round(double x)
+{
+	if (x >= 0.0) {
+		double y = floor(x);
+		if (x - y >= 0.5)
+			y += 1.0;
+		return y;
+	} else {
+		double y = ceil(x);
+		if (x - y >= 0.5)
+			y -= 1.0;
+		return y;
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/future.h	Wed Jul 18 18:47:44 2012 +0200
@@ -0,0 +1,1 @@
+double round(double x);