diff base/LogRange.cpp @ 1038:cc27f35aa75c cxx11

Introducing the signed 64-bit frame index type, and fixing build failures from inclusion of -Wconversion with -Werror. Not finished yet.
author Chris Cannam
date Tue, 03 Mar 2015 15:18:24 +0000
parents 1424aa29ae95
children 31f01931b781
line wrap: on
line diff
--- a/base/LogRange.cpp	Tue Mar 03 09:33:59 2015 +0000
+++ b/base/LogRange.cpp	Tue Mar 03 15:18:24 2015 +0000
@@ -74,20 +74,20 @@
     return powf(10.0, value);
 }
 
-static float
-sd(const std::vector<float> &values, size_t start, size_t n)
+static double
+sd(const std::vector<float> &values, int start, int n)
 {
-    float sum = 0.f, mean = 0.f, variance = 0.f;
-    for (size_t i = 0; i < n; ++i) {
+    double sum = 0.f, mean = 0.f, variance = 0.f;
+    for (int i = 0; i < n; ++i) {
         sum += values[start + i];
     }
     mean = sum / n;
-    for (size_t i = 0; i < n; ++i) {
-        float diff = values[start + i] - mean;
+    for (int i = 0; i < n; ++i) {
+        double diff = values[start + i] - mean;
         variance += diff * diff;
     }
     variance = variance / n;
-    return sqrtf(variance);
+    return sqrt(variance);
 }
 
 bool
@@ -97,12 +97,13 @@
     // calculate the standard deviation of each set; if the two SDs
     // are very different, it's likely that a log scale would be good.
 
-    if (values.size() < 4) return false;
+    int n = int(values.size());
+    if (n < 4) return false;
     std::sort(values.begin(), values.end());
-    size_t mi = values.size() / 2;
+    int mi = n / 2;
 
-    float sd0 = sd(values, 0, mi);
-    float sd1 = sd(values, mi, values.size() - mi);
+    double sd0 = sd(values, 0, mi);
+    double sd1 = sd(values, mi, n - mi);
 
     SVDEBUG << "LogRange::useLogScale: sd0 = "
               << sd0 << ", sd1 = " << sd1 << endl;
@@ -111,7 +112,7 @@
 
     // I wonder what method of determining "one sd much bigger than
     // the other" would be appropriate here...
-    if (std::max(sd0, sd1) / std::min(sd0, sd1) > 10.f) return true;
+    if (std::max(sd0, sd1) / std::min(sd0, sd1) > 10.) return true;
     else return false;
 }