diff 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
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;
+	}
+}