aboutsummaryrefslogtreecommitdiff
path: root/src/port/rint.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/port/rint.c')
-rw-r--r--src/port/rint.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/port/rint.c b/src/port/rint.c
new file mode 100644
index 00000000000..53ed8cbcdf8
--- /dev/null
+++ b/src/port/rint.c
@@ -0,0 +1,37 @@
+/*-------------------------------------------------------------------------
+ *
+ * rint.c
+ * rint() implementation
+ *
+ * Copyright (c) 1999, repas AEG Automation GmbH
+ *
+ *
+ * IDENTIFICATION
+ * $Header: /cvsroot/pgsql/src/port/rint.c,v 1.1 2003/05/09 16:26:29 momjian Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
+
+#include "c.h"
+#include <math.h>
+
+double
+rint(double x)
+{
+ double f,
+ n = 0.;
+
+ f = modf(x, &n);
+
+ if (x > 0.)
+ {
+ if (f > .5)
+ n += 1.;
+ }
+ else if (x < 0.)
+ {
+ if (f < -.5)
+ n -= 1.;
+ }
+ return n;
+}