forked from sccn/liblsl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcast.cpp
More file actions
30 lines (26 loc) · 738 Bytes
/
cast.cpp
File metadata and controls
30 lines (26 loc) · 738 Bytes
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
#include "cast.h"
#include <iomanip>
#include <locale>
#include <sstream>
template <> std::string lsl::to_string(double str) {
std::ostringstream os;
os.imbue(std::locale::classic());
os << std::setprecision(16) << std::showpoint << str;
return os.str();
}
template <> std::string lsl::to_string(float str) {
std::ostringstream os;
os.imbue(std::locale::classic());
os << std::setprecision(8) << std::showpoint << str;
return os.str();
}
template <> double lsl::from_string(const std::string &str) {
std::istringstream is(str);
is.imbue(std::locale::classic());
double res;
is >> res;
return res;
}
template <> float lsl::from_string(const std::string &str) {
return static_cast<float>(lsl::from_string<double>(str));
}