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

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Aug 25 04:03:08 PDT 2012


Author: mmetz
Date: 2012-08-25 04:03:08 -0700 (Sat, 25 Aug 2012)
New Revision: 52885

Modified:
   grass/trunk/lib/raster/color_write.c
Log:
fix GRASS_EPSILON usage

Modified: grass/trunk/lib/raster/color_write.c
===================================================================
--- grass/trunk/lib/raster/color_write.c	2012-08-25 10:37:57 UTC (rev 52884)
+++ grass/trunk/lib/raster/color_write.c	2012-08-25 11:03:08 UTC (rev 52885)
@@ -246,10 +246,16 @@
     double dtmp;
 
     sprintf(str, "%.15g", dval);
+    /* Note that G_trim_decimal() does not trim e.g. 1.0000000e-20 */
     G_trim_decimal(str);
+
     sscanf(str, "%lf", &dtmp);
-    if (dtmp != dval) {  /* if  no zeros after decimal point were trimmed */
-	sprintf(str, "%.15g", dval - GRASS_EPSILON);
+    if (dtmp != dval) {  /* if no zeros after decimal point were trimmed */
+	/* lower dval by fraction of GRASS_EPSILON */
+	if (dval > 0)
+	    sprintf(str, "%.15g", dval * (1 - GRASS_EPSILON));
+	else
+	    sprintf(str, "%.15g", dval * (1 + GRASS_EPSILON));
     }
 }
 
@@ -259,9 +265,14 @@
     double dtmp;
 
     sprintf(str, "%.15g", dval);
+    /* Note that G_trim_decimal() does not trim e.g. 1.0000000e-20 */
     G_trim_decimal(str);
     sscanf(str, "%lf", &dtmp);
     if (dtmp != dval) {  /* if  no zeros after decimal point were trimmed */
-	sprintf(str, "%.15g", dval + GRASS_EPSILON);
+	/* increase dval by fraction of GRASS_EPSILON */
+	if (dval > 0)
+	    sprintf(str, "%.15g", dval * (1 + GRASS_EPSILON));
+	else
+	    sprintf(str, "%.15g", dval * (1 - GRASS_EPSILON));
     }
 }



More information about the grass-commit mailing list