# HG changeset patch # User Daniele Nicolodi # Date 1342630064 -7200 # Node ID 9d57d1fcbcd5e92ea6c36fbf9623dc76848dc7dd # Parent b2103439b40136e966c7464489cb0a4ec3e45315 Implementation of the C99 round() function diff -r b2103439b401 -r 9d57d1fcbcd5 future.c --- /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 + +/* 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; + } +} diff -r b2103439b401 -r 9d57d1fcbcd5 future.h --- /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);