Small bufix related to creation of fmt string for snprintf

This commit is contained in:
Alex Astashyn 2016-12-05 19:03:39 -05:00
parent 2197856395
commit 509447b4d5
2 changed files with 16 additions and 18 deletions

View File

@ -6464,19 +6464,18 @@ class basic_json
}
static constexpr auto d =
std::numeric_limits<number_float_t>::digits10+1;
std::numeric_limits<number_float_t>::digits10;
static_assert(d == 6 or d == 15 or d == 16 or d == 17, "");
// I'm not sure why we need that +1 above, if at all,
static constexpr auto fmt = d == 6 ? "%.7g"
: d == 15 ? "%.16g"
: d == 16 ? "%.17g"
: d == 17 ? "%.18g"
: "%.19g";
// I'm not sure why we need to +1 the precision,
// but without it there's a unit-test that fails
// that asserts precision of the output
static_assert(d == 6 or d == 15 or d == 16 or d == 17, "");
static constexpr auto fmt = d == 6 ? "%.6g"
: d == 15 ? "%.15g"
: d == 16 ? "%.16g"
: d == 17 ? "%.17g"
: "%.18g";
snprintf(m_buf.data(), m_buf.size(), fmt, x);
const std::locale loc;

View File

@ -6464,19 +6464,18 @@ class basic_json
}
static constexpr auto d =
std::numeric_limits<number_float_t>::digits10+1;
std::numeric_limits<number_float_t>::digits10;
static_assert(d == 6 or d == 15 or d == 16 or d == 17, "");
// I'm not sure why we need that +1 above, if at all,
static constexpr auto fmt = d == 6 ? "%.7g"
: d == 15 ? "%.16g"
: d == 16 ? "%.17g"
: d == 17 ? "%.18g"
: "%.19g";
// I'm not sure why we need to +1 the precision,
// but without it there's a unit-test that fails
// that asserts precision of the output
static_assert(d == 6 or d == 15 or d == 16 or d == 17, "");
static constexpr auto fmt = d == 6 ? "%.6g"
: d == 15 ? "%.15g"
: d == 16 ? "%.16g"
: d == 17 ? "%.17g"
: "%.18g";
snprintf(m_buf.data(), m_buf.size(), fmt, x);
const std::locale loc;