🔨 clean up
This commit is contained in:
parent
b91805e1f0
commit
7435d54e97
1 changed files with 4 additions and 19 deletions
23
src/json.hpp
23
src/json.hpp
|
@ -6663,17 +6663,16 @@ class serializer
|
||||||
const bool is_negative = std::is_same<NumberType, number_integer_t>::value and (x < 0);
|
const bool is_negative = std::is_same<NumberType, number_integer_t>::value and (x < 0);
|
||||||
std::size_t i = 0;
|
std::size_t i = 0;
|
||||||
|
|
||||||
// spare 1 byte for '\0'
|
while (x != 0)
|
||||||
while (x != 0 and i < number_buffer.size() - 1)
|
|
||||||
{
|
{
|
||||||
|
// spare 1 byte for '\0'
|
||||||
|
assert(i < number_buffer.size() - 1);
|
||||||
|
|
||||||
const auto digit = std::labs(static_cast<long>(x % 10));
|
const auto digit = std::labs(static_cast<long>(x % 10));
|
||||||
number_buffer[i++] = static_cast<char>('0' + digit);
|
number_buffer[i++] = static_cast<char>('0' + digit);
|
||||||
x /= 10;
|
x /= 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure the number has been processed completely
|
|
||||||
assert(x == 0);
|
|
||||||
|
|
||||||
if (is_negative)
|
if (is_negative)
|
||||||
{
|
{
|
||||||
// make sure there is capacity for the '-'
|
// make sure there is capacity for the '-'
|
||||||
|
@ -6702,20 +6701,6 @@ class serializer
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// special case for 0.0 and -0.0
|
|
||||||
if (x == 0)
|
|
||||||
{
|
|
||||||
if (std::signbit(x))
|
|
||||||
{
|
|
||||||
o->write_characters("-0.0", 4);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
o->write_characters("0.0", 3);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// get number of digits for a text -> float -> text round-trip
|
// get number of digits for a text -> float -> text round-trip
|
||||||
static constexpr auto d = std::numeric_limits<number_float_t>::digits10;
|
static constexpr auto d = std::numeric_limits<number_float_t>::digits10;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue