[GRASS-SVN] r52194 - grass/branches/develbranch_6/lib/gis

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Jun 23 04:56:13 PDT 2012


Author: hamish
Date: 2012-06-23 04:56:13 -0700 (Sat, 23 Jun 2012)
New Revision: 52194

Modified:
   grass/branches/develbranch_6/lib/gis/color_write.c
Log:
write the colr/ file at proper precisions (ticket #335)

Modified: grass/branches/develbranch_6/lib/gis/color_write.c
===================================================================
--- grass/branches/develbranch_6/lib/gis/color_write.c	2012-06-23 11:28:29 UTC (rev 52193)
+++ grass/branches/develbranch_6/lib/gis/color_write.c	2012-06-23 11:56:13 UTC (rev 52194)
@@ -20,9 +20,6 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <grass/gis.h>
-#define PRECISION 30
-#define THRESHOLD .0000000000000000000000000000005
-/* .5 * 10 ^(-30) */
 
 static int write_new_colors(FILE *, struct Colors *);
 static int write_rules(FILE *, struct _Color_Rule_ *, DCELL, DCELL);
@@ -249,13 +246,11 @@
 {
     double dtmp;
 
-    sprintf(str, "%.*f", PRECISION, dval);
+    sprintf(str, "%.15g", dval);
     G_trim_decimal(str);
     sscanf(str, "%lf", &dtmp);
-    if (dtmp != dval) {		/* if  no zeros after decimal point were trimmed */
-	sprintf(str, "%.*f", PRECISION, dval - THRESHOLD);
-	/* because precision is probably higher than PRECISION */
-    }
+    if (dtmp != dval)		/* if  no zeros after decimal point were trimmed */
+	sprintf(str, "%.15g", dval - GRASS_EPSILON);
 
     return 0;
 }
@@ -264,13 +259,11 @@
 {
     double dtmp;
 
-    sprintf(str, "%.*f", PRECISION, dval);
+    sprintf(str, "%.15g", dval);
     G_trim_decimal(str);
     sscanf(str, "%lf", &dtmp);
-    if (dtmp != dval) {		/* if  no zeros after decimal point were trimmed */
-	sprintf(str, "%.*f", PRECISION, dval + THRESHOLD);
-	/* because precision is probably higher than PRECISION */
-    }
+    if (dtmp != dval)		/* if  no zeros after decimal point were trimmed */
+	sprintf(str, "%.15g", dval + GRASS_EPSILON);
 
     return 0;
 }



More information about the grass-commit mailing list