Index: trunk/psLib/src/math/psStats.c
===================================================================
--- trunk/psLib/src/math/psStats.c	(revision 24863)
+++ trunk/psLib/src/math/psStats.c	(revision 24884)
@@ -1734,9 +1734,5 @@
 
     // If the mean is NAN, then generate a warning and set the stdev to NAN.
-    if (isnan(stats->robustMedian)) {
-        stats->fittedStdev = NAN;
-        stats->fittedStdev = NAN;
-        return true;
-    }
+    if (isnan(stats->robustMedian)) goto escape;
 
     float guessStdev = stats->robustStdev;  // pass the guess sigma
@@ -1770,6 +1766,14 @@
             COUNT_WARNING(10, 100, "Failed to calculate the min/max of the input vector.\n");
             psFree(statsMinMax);
-	    stats->fittedStdev = NAN;
-	    stats->fittedStdev = NAN;
+	    goto escape;
+        }
+
+        // If all data points have the same value, then we set the appropriate members of stats and return.
+        if (fabs(max - min) <= FLT_EPSILON) {
+            COUNT_WARNING(10, 100, "All data points have the same value: %f.\n", min);
+            stats->fittedMean = min;
+            stats->fittedStdev = 0.0;
+	    stats->results |= PS_STAT_FITTED_MEAN_V4;
+	    stats->results |= PS_STAT_FITTED_STDEV_V4;
             return true;
         }
@@ -1789,7 +1793,5 @@
             psFree(histogram);
             psFree(statsMinMax);
-	    stats->fittedStdev = NAN;
-	    stats->fittedStdev = NAN;
-            return true;
+	    goto escape;
         }
         if (psTraceGetLevel("psLib.math") >= 8) {
@@ -1823,7 +1825,5 @@
             COUNT_WARNING(10, 100, "Failed to calculate the min/max of the input vector.\n");
             psFree(statsMinMax);
-	    stats->fittedStdev = NAN;
-	    stats->fittedStdev = NAN;
-            return true;
+	    goto escape;
         }
 
@@ -1898,7 +1898,5 @@
                 psFree(histogram);
                 psFree(statsMinMax);
-		stats->fittedStdev = NAN;
-		stats->fittedStdev = NAN;
-                return true;
+		goto escape;
             }
 
@@ -1919,7 +1917,5 @@
 
                 COUNT_WARNING(10, 100, "fit did not converge\n");
-		stats->fittedStdev = NAN;
-		stats->fittedStdev = NAN;
-                return true;
+		goto escape;
             }
 
@@ -1991,7 +1987,5 @@
                 psFree(histogram);
                 psFree(statsMinMax);
-		stats->fittedStdev = NAN;
-		stats->fittedStdev = NAN;
-                return true;
+		goto escape;
             }
 
@@ -2038,4 +2032,12 @@
     psTrace(TRACE, 6, "The fitted stdev is %f.\n", stats->fittedStdev);
 
+    stats->results |= PS_STAT_FITTED_MEAN_V4;
+    stats->results |= PS_STAT_FITTED_STDEV_V4;
+
+    return true;
+
+escape:
+    stats->fittedMean = NAN;
+    stats->fittedStdev = NAN;
     stats->results |= PS_STAT_FITTED_MEAN_V4;
     stats->results |= PS_STAT_FITTED_STDEV_V4;
