diff --git a/Utilities/Config.cpp b/Utilities/Config.cpp index a66007b076..545bb17e7e 100644 --- a/Utilities/Config.cpp +++ b/Utilities/Config.cpp @@ -1,7 +1,6 @@ #include "stdafx.h" #include "Config.h" #include "util/types.hpp" - #include "util/yaml.hpp" #include @@ -184,6 +183,27 @@ bool try_to_float(f64* out, std::string_view value, f64 min, f64 max) return true; } +bool try_to_string(std::string* out, const f64& value) +{ +#ifdef __APPLE__ + if (out) *out = std::to_string(value); + return true; +#else + std::array str{}; + + if (auto [ptr, ec] = std::to_chars(str.data(), str.data() + str.size(), value, std::chars_format::fixed); ec == std::errc()) + { + if (out) *out = std::string(str.data(), ptr); + return true; + } + else + { + if (out) cfg_log.error("cfg::try_to_string(): could not convert value '%f' to string. error='%s'", value, std::make_error_code(ec).message()); + return false; + } +#endif +} + bool cfg::try_to_enum_value(u64* out, decltype(&fmt_class_string::format) func, std::string_view value) { u64 max = umax; diff --git a/Utilities/Config.h b/Utilities/Config.h index 5f8b188ff4..889b058a53 100644 --- a/Utilities/Config.h +++ b/Utilities/Config.h @@ -384,12 +384,24 @@ namespace cfg std::string to_string() const override { - return std::to_string(m_value); + std::string result; + if (try_to_string(&result, m_value)) + { + return result; + } + + return "0.0"; } std::string def_to_string() const override { - return std::to_string(def); + std::string result; + if (try_to_string(&result, def)) + { + return result; + } + + return "0.0"; } bool from_string(std::string_view value, bool /*dynamic*/ = false) override diff --git a/Utilities/StrUtil.h b/Utilities/StrUtil.h index da64fafa35..456a0634d3 100644 --- a/Utilities/StrUtil.h +++ b/Utilities/StrUtil.h @@ -31,6 +31,9 @@ bool try_to_uint64(u64* out, std::string_view value, u64 min, u64 max); // Convert string to float bool try_to_float(f64* out, std::string_view value, f64 min, f64 max); +// Convert float to string locale independent +bool try_to_string(std::string* out, const f64& value); + // Get the file extension of a file path ("png", "jpg", etc.) std::string get_file_extension(const std::string& file_path); diff --git a/rpcs3/Emu/Cell/SPUThread.cpp b/rpcs3/Emu/Cell/SPUThread.cpp index 82dd8cb4d1..e59a4c8449 100644 --- a/rpcs3/Emu/Cell/SPUThread.cpp +++ b/rpcs3/Emu/Cell/SPUThread.cpp @@ -2768,7 +2768,7 @@ bool spu_thread::do_list_transfer(spu_mfc_cmd& args) u32 s_size = data0._u32[0]; - // We need to verify matching between odd and even elements (vector test is position independant) + // We need to verify matching between odd and even elements (vector test is position independent) // 0-5 is the most unlikely couple match for many reasons so it skips the entire check very efficiently in most cases // Assumes padding bits should match if (optimization_compatible == MFC_GET_CMD && s_size == data0._u32[2] && arg_size >= fetch_size * 8)