From b2fc560701377c0f8e703d3c2433c3f5b4c31715 Mon Sep 17 00:00:00 2001 From: Przemek Pawlas <3606072+Destroy666x@users.noreply.github.com> Date: Thu, 22 Feb 2024 19:47:00 +0100 Subject: [PATCH] Store truncated representation of doubles when used as variables --- lib/utils/utility.cpp | 8 ++++++++ lib/utils/utility.hpp | 1 + lib/variables/variable.cpp | 3 ++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/utils/utility.cpp b/lib/utils/utility.cpp index ce9a2005..fd73a7b7 100644 --- a/lib/utils/utility.cpp +++ b/lib/utils/utility.cpp @@ -7,6 +7,7 @@ #include #include #include +#include namespace advss { @@ -77,6 +78,13 @@ bool CompareIgnoringLineEnding(QString &s1, QString &s2) return true; } +std::string ToString(double value) +{ + std::stringstream stream; + stream << value; + return stream.str(); +} + std::string GetDataFilePath(const std::string &file) { std::string root_path = obs_get_module_data_path(obs_current_module()); diff --git a/lib/utils/utility.hpp b/lib/utils/utility.hpp index 788886a4..aa382d46 100644 --- a/lib/utils/utility.hpp +++ b/lib/utils/utility.hpp @@ -21,6 +21,7 @@ bool ReplaceAll(std::string &str, const std::string &from, EXPORT std::optional GetJsonField(const std::string &json, const std::string &id); EXPORT bool CompareIgnoringLineEnding(QString &s1, QString &s2); +std::string ToString(double value); EXPORT std::string GetDataFilePath(const std::string &file); QString GetDefaultSettingsSaveLocation(); diff --git a/lib/variables/variable.cpp b/lib/variables/variable.cpp index b1c8dd79..5ff9bc84 100644 --- a/lib/variables/variable.cpp +++ b/lib/variables/variable.cpp @@ -1,6 +1,7 @@ #include "variable.hpp" #include "math-helpers.hpp" #include "obs-module-helper.hpp" +#include "utility.hpp" #include @@ -78,7 +79,7 @@ void Variable::SetValue(const std::string &val) void Variable::SetValue(double value) { - _value = std::to_string(value); + _value = ToString(value); _lastUsed = std::chrono::high_resolution_clock::now(); lastVariableChange = std::chrono::high_resolution_clock::now(); }