]> AND Private Git Repository - loba.git/blobdiff - cost_func.cpp
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
Use verbose level for logging results of final checks on total load.
[loba.git] / cost_func.cpp
index bdea62ee95d86a63d648954ffdbda208100d1bb3..73111999216e837fe156e5dbc0eb23d0c6ef3f7c 100644 (file)
@@ -3,23 +3,24 @@
 #include <cstring>
 #include <iterator>
 #include <sstream>
+
 #include "cost_func.h"
 
-cost_func::cost_func(const char *param)
+cost_func::cost_func(const charparam)
 {
     int len = strlen(param);
     char tmpbuf[len + 1];
-    char *tmp = tmpbuf;
+    chartmp = tmpbuf;
     memcpy(tmp, param, len + 1);
     degree = std::count(tmp, tmp + len, ',');
     factor = new double[degree + 1];
     for (int i = degree ; i > 0 ; i--) {
-        char *next = strchr(tmp, ',');
+        charnext = strchr(tmp, ',');
         *next++ = '\0';
-        factor[i] = atof(tmp);
+        std::istringstream(tmp) >> factor[i];
         tmp = next;
     }
-    factor[0] = atof(tmp);
+    std::istringstream(tmp) >> factor[0];
 }
 
 cost_func::~cost_func()
@@ -40,10 +41,10 @@ cost_func& cost_func::operator=(const cost_func& ref)
 
 double cost_func::operator()(double amount) const
 {
-    double ret = factor[degree];
+    double result = factor[degree];
     for (int i = degree - 1; i >= 0 ; i--)
-        ret = amount * ret + factor[i];
-    return ret;
+        result = amount * result + factor[i];
+    return result;
 }
 
 std::string cost_func::to_string()