Index: liblwgeom/ptarray.c
===================================================================
--- liblwgeom/ptarray.c	(revision 5920)
+++ liblwgeom/ptarray.c	(working copy)
@@ -115,30 +115,19 @@
 BOX2DFLOAT4 *
 ptarray_compute_box2d(const POINTARRAY *pa)
 {
-	int t;
-	POINT2D pt;
+	BOX3D box3d;
 	BOX2DFLOAT4 *result;
 
-	if (pa->npoints == 0) return NULL;
+	/* Note: we perform the calculation using BOX3D and then
+	   convert to BOX2DFLOAT4 to prevent cumulative floating
+	   point rounding errors when calculating using BOX2DFLOAT4
+	   directly. */
 
 	result = lwalloc(sizeof(BOX2DFLOAT4));
 
-	getPoint2d_p(pa, 0, &pt);
+	ptarray_compute_box3d_p(pa, &box3d);
+	box3d_to_box2df_p(&box3d, result);
 
-	result->xmin = pt.x;
-	result->xmax = pt.x;
-	result->ymin = pt.y;
-	result->ymax = pt.y;
-
-	for (t=1; t<pa->npoints; t++)
-	{
-		getPoint2d_p(pa, t, &pt);
-		if (pt.x < result->xmin) result->xmin = pt.x;
-		if (pt.y < result->ymin) result->ymin = pt.y;
-		if (pt.x > result->xmax) result->xmax = pt.x;
-		if (pt.y > result->ymax) result->ymax = pt.y;
-	}
-
 	return result;
 }
 
