mirror of
https://github.com/nlohmann/json.git
synced 2026-10-15 10:47:13 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9dc5ba1d22 |
No files matched your search
@@ -184,7 +184,10 @@ JSON_HEDLEY_ALWAYS_INLINE shortest_decimal to_shortest(std::uint64_t bits) noexc
|
|||||||
const uint128_parts p10 = pow10(-dec_exp - 1);
|
const uint128_parts p10 = pow10(-dec_exp - 1);
|
||||||
const uint128_parts p = umul192_hi128(p10.high, p10.low, bin_sig << static_cast<unsigned>(shift));
|
const uint128_parts p = umul192_hi128(p10.high, p10.low, bin_sig << static_cast<unsigned>(shift));
|
||||||
std::uint64_t integral = p.high >> static_cast<unsigned>(extra_shift);
|
std::uint64_t integral = p.high >> static_cast<unsigned>(extra_shift);
|
||||||
const std::uint64_t fractional = (p.high << static_cast<unsigned>(64 - extra_shift)) | (p.low >> static_cast<unsigned>(extra_shift));
|
// (no casts in the shifts: MSVC 2015 warns C4554 on them despite the parentheses)
|
||||||
|
constexpr unsigned fractional_low_shift = static_cast<unsigned>(extra_shift);
|
||||||
|
constexpr unsigned fractional_high_shift = 64u - fractional_low_shift;
|
||||||
|
const std::uint64_t fractional = (p.high << fractional_high_shift) | (p.low >> fractional_low_shift);
|
||||||
std::uint64_t digit = 0;
|
std::uint64_t digit = 0;
|
||||||
bool round_up = false;
|
bool round_up = false;
|
||||||
bool round_down = false;
|
bool round_down = false;
|
||||||
|
|||||||
Generated
+4
-1
@@ -25874,7 +25874,10 @@ JSON_HEDLEY_ALWAYS_INLINE shortest_decimal to_shortest(std::uint64_t bits) noexc
|
|||||||
const uint128_parts p10 = pow10(-dec_exp - 1);
|
const uint128_parts p10 = pow10(-dec_exp - 1);
|
||||||
const uint128_parts p = umul192_hi128(p10.high, p10.low, bin_sig << static_cast<unsigned>(shift));
|
const uint128_parts p = umul192_hi128(p10.high, p10.low, bin_sig << static_cast<unsigned>(shift));
|
||||||
std::uint64_t integral = p.high >> static_cast<unsigned>(extra_shift);
|
std::uint64_t integral = p.high >> static_cast<unsigned>(extra_shift);
|
||||||
const std::uint64_t fractional = (p.high << static_cast<unsigned>(64 - extra_shift)) | (p.low >> static_cast<unsigned>(extra_shift));
|
// (no casts in the shifts: MSVC 2015 warns C4554 on them despite the parentheses)
|
||||||
|
constexpr unsigned fractional_low_shift = static_cast<unsigned>(extra_shift);
|
||||||
|
constexpr unsigned fractional_high_shift = 64u - fractional_low_shift;
|
||||||
|
const std::uint64_t fractional = (p.high << fractional_high_shift) | (p.low >> fractional_low_shift);
|
||||||
std::uint64_t digit = 0;
|
std::uint64_t digit = 0;
|
||||||
bool round_up = false;
|
bool round_up = false;
|
||||||
bool round_down = false;
|
bool round_down = false;
|
||||||
|
|||||||
@@ -21,11 +21,8 @@ using nlohmann::detail::dtoa_impl::reinterpret_bits;
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <iomanip>
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <locale>
|
|
||||||
#include <random>
|
#include <random>
|
||||||
#include <sstream>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -689,20 +686,13 @@ void check_shortest(double v)
|
|||||||
const std::string& digits = de.first;
|
const std::string& digits = de.first;
|
||||||
if (digits.size() > 1)
|
if (digits.size() > 1)
|
||||||
{
|
{
|
||||||
// the decimals of one digit fewer next to the value
|
// the decimals of one digit fewer next to the value: v lies within
|
||||||
// (a stream rather than snprintf("%.*e"), whose output GCC cannot bound)
|
// half a unit of the last digit of text, so the closest ones are the
|
||||||
std::ostringstream shorter;
|
// truncated digits and their successor
|
||||||
shorter.imbue(std::locale::classic());
|
// (not a stream with std::setprecision(digits.size() - 2): the
|
||||||
shorter << std::scientific << std::setprecision(static_cast<int>(digits.size()) - 2) << v;
|
// standard library of MSVC 2017 ignores a precision of 0)
|
||||||
const auto near = digits_and_exponent(shorter.str());
|
const std::string m = digits.substr(0, digits.size() - 1);
|
||||||
// as an integer with digits.size() - 1 digits
|
const int e = de.second + 1;
|
||||||
std::string m = near.first;
|
|
||||||
int e = near.second;
|
|
||||||
while (m.size() < digits.size() - 1)
|
|
||||||
{
|
|
||||||
m += '0';
|
|
||||||
--e;
|
|
||||||
}
|
|
||||||
const std::uint64_t mid = std::stoull(m);
|
const std::uint64_t mid = std::stoull(m);
|
||||||
for (const std::uint64_t candidate :
|
for (const std::uint64_t candidate :
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user