aboutsummaryrefslogtreecommitdiff
path: root/src/utils.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.cc')
-rw-r--r--src/utils.cc8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/utils.cc b/src/utils.cc
index 75f13a3..94118ed 100644
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -45,6 +45,14 @@ int utils::parseInt(const std::string& s) {
}
}
+double utils::parseDouble(const std::string& s) {
+ try {
+ return std::stod(s);
+ } catch(std::exception& e) {
+ throw std::runtime_error("A double was expected but " + s + " was given");
+ }
+}
+
void utils::saveJson(const nlohmann::json& data, const fs::path& path) {
std::ofstream f(path);
f << std::setw(4) << data << std::endl;