mirror of
https://github.com/fmtlib/fmt.git
synced 2025-01-27 06:35:37 +00:00
Workaround a bug in formatting long double in MinGW
This commit is contained in:
parent
1c72e7062b
commit
673a4525f6
@ -72,15 +72,31 @@ using fmt::pad;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
// Format value using the standard library.
|
||||||
|
template <typename Char, typename T>
|
||||||
|
std::basic_string<Char> std_format(const T &value) {
|
||||||
|
std::basic_ostringstream<Char> os;
|
||||||
|
os << value;
|
||||||
|
return os.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __MINGW32__
|
||||||
|
// Workaround a bug in formatting long double in MinGW.
|
||||||
|
template <typename Char>
|
||||||
|
std::basic_string<Char> std_format(long double value) {
|
||||||
|
char buffer[100];
|
||||||
|
sprintf_s(buffer, sizeof(buffer), "%Lg", value);
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Checks if writing value to BasicWriter<Char> produces the same result
|
// Checks if writing value to BasicWriter<Char> produces the same result
|
||||||
// as writing it to std::basic_ostringstream<Char>.
|
// as writing it to std::basic_ostringstream<Char>.
|
||||||
template <typename Char, typename T>
|
template <typename Char, typename T>
|
||||||
::testing::AssertionResult check_write(const T &value, const char *type) {
|
::testing::AssertionResult check_write(const T &value, const char *type) {
|
||||||
std::basic_ostringstream<Char> os;
|
|
||||||
os << value;
|
|
||||||
std::basic_string<Char> expected = os.str();
|
|
||||||
std::basic_string<Char> actual =
|
std::basic_string<Char> actual =
|
||||||
(fmt::BasicMemoryWriter<Char>() << value).str();
|
(fmt::BasicMemoryWriter<Char>() << value).str();
|
||||||
|
std::basic_string<Char> expected = std_format<Char>(value);
|
||||||
if (expected == actual)
|
if (expected == actual)
|
||||||
return ::testing::AssertionSuccess();
|
return ::testing::AssertionSuccess();
|
||||||
return ::testing::AssertionFailure()
|
return ::testing::AssertionFailure()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user