diff --git a/goffice/math/go-rangefunc.c b/goffice/math/go-rangefunc.c
index 2eb1567..98797df 100644
--- a/goffice/math/go-rangefunc.c
+++ b/goffice/math/go-rangefunc.c
@@ -307,22 +307,42 @@ SUFFIX(go_range_constant) (DOUBLE const *xs, int n)
 int
 SUFFIX(go_range_increasing) (DOUBLE const *xs, int n)
 {
-	int i;
+	int i = 0;
+	DOUBLE last;
 	g_return_val_if_fail (n == 0 || xs != NULL, 0);
-	for (i = 1; i < n; i++)
-		if (xs[i - 1] >= xs[i])
+	while ( i < n && !SUFFIX (go_finite) (xs[i]))
+		i++;
+	if (i == n)
+		return 0;
+	last = xs[i];
+	for (i = i + 1; i < n; i++) {
+		if (!go_finite (xs[i]))
+		    continue;
+		if (last >= xs[i])
 			return 0;
+		last = xs[i];
+	}
 	return 1;
 }
 
 int
 SUFFIX(go_range_decreasing) (DOUBLE const *xs, int n)
 {
-	int i;
+	int i = 0;
+	DOUBLE last;
 	g_return_val_if_fail (n == 0 || xs != NULL, 0);
-	for (i = 1; i < n; i++)
-		if (xs[i - 1] <= xs[i])
+	while ( i < n && !SUFFIX (go_finite) (xs[i]))
+		i++;
+	if (i == n)
+		return 0;
+	last = xs[i];
+	for (i = i + 1; i < n; i++) {
+		if (!go_finite (xs[i]))
+		    continue;
+		if (last <= xs[i])
 			return 0;
+		last = xs[i];
+	}
 	return 1;
 }
 

