config: try to fix float locale issues

This commit is contained in:
Megamouse 2023-02-24 15:26:00 +01:00
parent afad96a52a
commit e46dba43ad
4 changed files with 39 additions and 4 deletions

View file

@ -1,7 +1,6 @@
#include "stdafx.h"
#include "Config.h"
#include "util/types.hpp"
#include "util/yaml.hpp"
#include <charconv>
@ -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<char, 32> 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<int>::format) func, std::string_view value)
{
u64 max = umax;

View file

@ -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

View file

@ -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);

View file

@ -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)