summaryrefslogtreecommitdiff
path: root/nuttx/libc/math/lib_round.c
diff options
context:
space:
mode:
Diffstat (limited to 'nuttx/libc/math/lib_round.c')
-rw-r--r--nuttx/libc/math/lib_round.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/nuttx/libc/math/lib_round.c b/nuttx/libc/math/lib_round.c
new file mode 100644
index 000000000..6191cee5b
--- /dev/null
+++ b/nuttx/libc/math/lib_round.c
@@ -0,0 +1,40 @@
+/************************************************************************
+ * lib/math/lib_round.c
+ *
+ * This file is a part of NuttX:
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * (C) 2012 Petteri Aimonen <jpa@nx.mail.kapsi.fi>
+ *
+ ************************************************************************/
+
+/************************************************************************
+ * Included Files
+ ************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <math.h>
+
+/************************************************************************
+ * Public Functions
+ ************************************************************************/
+
+#ifdef CONFIG_HAVE_DOUBLE
+double round(double x)
+{
+ double f = modf(x, &x);
+ if (x <= 0.0 && f <= -0.5)
+ {
+ x -= 1.0;
+ }
+
+ if (x >= 0.0 && f >= 0.5)
+ {
+ x += 1.0;
+ }
+
+ return x;
+}
+#endif