-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutility.cpp
76 lines (60 loc) · 1.54 KB
/
utility.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "utility.h"
std::string Utility::DateTimeNow()
{
std::stringstream now_stream;
time_t const now_time = time(nullptr);
now_stream << std::put_time(localtime(&now_time), "%F %T");
std::string now = now_stream.str();
return now;
}
double Utility::Interpolation(double y_1, double y_0, double x, double x_1, double x_0)
{
double y = ((y_0 * (x_1 - x)) + (y_1 * (x - x_0))) / (x_1 - x_0);
return y;
}
double Utility::CheckUndefinedNumber(double value)
{
double result = 0;
if (std::isnan(value) || std::isinf(value))
result = 0;
else
result = value;
return result;
}
double Utility::CheckUndefinedNumber(double value, double digit)
{
double result = CheckUndefinedNumber(value);
result = Round(result, digit);
return result;
}
double Utility::Round(double value, double digit)
{
double tmp = round(value * pow(10, digit)) / pow(10, digit);
return tmp;
}
std::string Utility::DecToHex(unsigned char n)
{
int value = static_cast<int>(n);
std::stringstream stream;
stream << std::hex << value;
std::string tmp = stream.str();
return tmp;
}
std::string Utility::BoolToString(bool value)
{
std::string tmp = "";
if (value)
tmp = "True";
else
tmp = "False";
return tmp;
}
std::string Utility::ConvertString(std::vector<double> values)
{
std::string tmp = "";
if (values.size() > 0) {
for (uint i = 0; i < values.size(); i++)
tmp += std::to_string(Round(values.at(i), 4.0)) + " ";
}
return tmp;
}