Fix for printing long doubles bug in dump_float
When you use long double as a floating point type with the current version of this file and try to dump json it prints trash instead of actual number. This if-else fixes the problem. On using long double you just need to add an 'L' modifier before 'g' in format string.
This commit is contained in:
parent
da6b908c4f
commit
1885f4bc5f
@ -832,7 +832,12 @@ class serializer
|
||||
|
||||
// the actual conversion
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
||||
std::ptrdiff_t len = (std::snprintf)(number_buffer.data(), number_buffer.size(), "%.*g", d, x);
|
||||
std::ptrdiff_t len;
|
||||
if constexpr (std::is_same_v<number_float_t, long double>) {
|
||||
len = (std::snprintf)(number_buffer.data(), number_buffer.size(), "%.*Lg", d, x);
|
||||
} else {
|
||||
len = (std::snprintf)(number_buffer.data(), number_buffer.size(), "%.*g", d, x);
|
||||
}
|
||||
|
||||
// negative value indicates an error
|
||||
JSON_ASSERT(len > 0);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user