[postgis-tickets] r15802 - ST_AsGeobuf fix double comparison

bjorn at wololo.org bjorn at wololo.org
Sat Sep 23 11:35:09 PDT 2017


Author: bjornharrtell
Date: 2017-09-23 11:35:09 -0700 (Sat, 23 Sep 2017)
New Revision: 15802

Modified:
   trunk/postgis/geobuf.c
Log:
ST_AsGeobuf fix double comparison
References #3840


Modified: trunk/postgis/geobuf.c
===================================================================
--- trunk/postgis/geobuf.c	2017-09-23 13:31:35 UTC (rev 15801)
+++ trunk/postgis/geobuf.c	2017-09-23 18:35:09 UTC (rev 15802)
@@ -440,7 +440,8 @@
 
 static void analyze_val(struct geobuf_agg_context *ctx, double val)
 {
-	if (ceil(val * ctx->e) / ctx->e != val && ctx->e < MAX_PRECISION)
+	if (fabs((round(val * ctx->e) / ctx->e) - val) >= EPSILON &&
+		ctx->e < MAX_PRECISION)
 		ctx->e *= 10;
 }
 
@@ -454,7 +455,7 @@
 		analyze_val(ctx, pt.y);
 		if (ctx->dimensions == 3)
 			analyze_val(ctx, pt.z);
-		else if (ctx->dimensions == 4)
+		if (ctx->dimensions == 4)
 			analyze_val(ctx, pt.m);
 	}
 }



More information about the postgis-tickets mailing list