diff --git a/src/port/rint.c b/src/port/rint.c
index 9c4d775..34ad0a0 100644
--- a/src/port/rint.c
+++ b/src/port/rint.c
@@ -15,5 +15,13 @@
 double
 rint(double x)
 {
+	double f, n = 0.0;
+
+	f = modf(x, &n);
+	if (((int) n % 2) == 0 && f == 0.5)
+		return floor(x);
+	else if (((int) n % 2) == 0 && f == -0.5)
+		return ceil(x);
+
 	return (x >= 0.0) ? floor(x + 0.5) : ceil(x - 0.5);
 }
