[GRASS-SVN] r38752 - grass/trunk/lib/raster

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Aug 16 04:36:24 EDT 2009


Author: hamish
Date: 2009-08-16 04:36:23 -0400 (Sun, 16 Aug 2009)
New Revision: 38752

Modified:
   grass/trunk/lib/raster/color_write.c
Log:
standardize on %.15g for doubles instead of mix of %.10f, %.30f (trac #335)

Modified: grass/trunk/lib/raster/color_write.c
===================================================================
--- grass/trunk/lib/raster/color_write.c	2009-08-16 08:18:37 UTC (rev 38751)
+++ grass/trunk/lib/raster/color_write.c	2009-08-16 08:36:23 UTC (rev 38752)
@@ -15,13 +15,9 @@
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
-
 #include <grass/gis.h>
 #include <grass/raster.h>
 
-#define PRECISION 30
-#define THRESHOLD .0000000000000000000000000000005	/* .5 * 10 ^(-30) */
-
 static void write_rules(FILE *, struct _Color_Rule_ *, DCELL, DCELL);
 static void write_new_colors(FILE *, struct Colors *);
 static void write_old_colors(FILE *, struct Colors *);
@@ -128,7 +124,7 @@
     fprintf(fd, "%% %s %s\n", str1, str2);
 
     if (colors->shift) {
-	sprintf(str2, "%.10f", (double)colors->shift);
+	sprintf(str2, "%.15g", (double)colors->shift);
 	G_trim_decimal(str2);
 	fprintf(fd, "shift:%s\n", str2);
     }
@@ -175,7 +171,7 @@
 	if (rule->low.value == dmin)
 	    format_min(str, (double)rule->low.value);
 	else {
-	    sprintf(str, "%.10f", (double)rule->low.value);
+	    sprintf(str, "%.15g", (double)rule->low.value);
 	    G_trim_decimal(str);
 	}
 	fprintf(fd, "%s:%d", str, (int)rule->low.red);
@@ -186,7 +182,7 @@
 	    if (rule->high.value == dmax)
 		format_max(str, (double)rule->high.value);
 	    else {
-		sprintf(str, "%.10f", (double)rule->high.value);
+		sprintf(str, "%.15g", (double)rule->high.value);
 		G_trim_decimal(str);
 	    }
 	    fprintf(fd, " %s:%d", str, (int)rule->high.red);
@@ -243,28 +239,28 @@
     }
 }
 
+
 static void format_min(char *str, double dval)
 {
     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);
     }
 }
 
+
 static void format_max(char *str, double dval)
 {
     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);
     }
 }



More information about the grass-commit mailing list