CARLsim  6.1.0
CARLsim: a GPU-accelerated SNN simulator
Util.cpp
Go to the documentation of this file.
1 #include "Util.h"
2 
3 #include <cmath>
4 #include <sstream>
5 #include <stdexcept>
6 
7 using namespace std;
8 
14 float stringToFloat(const string &str) {
15  stringstream stream(str);
16  float value;
17  stream >> value;
18 
19  if (stream.fail())
20  throw std::invalid_argument(string("stringToFloat: Could not convert ") + str + string(" to float."));
21 
22  return value;
23 }
24 
30 double stringToDouble(const string &str) {
31  stringstream stream(str);
32  double value;
33  stream >> value;
34 
35  if (stream.fail())
36  throw std::invalid_argument(string("stringToDouble: Could not convert ") + str + string(" to double."));
37 
38  return value;
39 }
40 
42 bool equals(const float x, const float y, float epsilon) {
43  return abs(x - y) < epsilon;
44 }
45 
47 bool equals(const double x, const double y, double epsilon) {
48  return abs(x - y) < epsilon;
49 }
float stringToFloat(const string &str)
Definition: Util.cpp:14
bool equals(const float x, const float y, float epsilon)
Definition: Util.cpp:42
double stringToDouble(const string &str)
Definition: Util.cpp:30