🔨 cleanup after #915

parent 010e5960
...@@ -8,6 +8,7 @@ SRCS = develop/json.hpp \ ...@@ -8,6 +8,7 @@ SRCS = develop/json.hpp \
develop/detail/exceptions.hpp \ develop/detail/exceptions.hpp \
develop/detail/value_t.hpp \ develop/detail/value_t.hpp \
develop/detail/conversions/from_json.hpp \ develop/detail/conversions/from_json.hpp \
develop/detail/conversions/to_chars.hpp \
develop/detail/conversions/to_json.hpp \ develop/detail/conversions/to_json.hpp \
develop/detail/parsing/input_adapters.hpp \ develop/detail/parsing/input_adapters.hpp \
develop/detail/parsing/lexer.hpp \ develop/detail/parsing/lexer.hpp \
......
...@@ -821,8 +821,6 @@ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR I ...@@ -821,8 +821,6 @@ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR I
The class contains the UTF-8 Decoder from Bjoern Hoehrmann which is licensed under the [MIT License](http://opensource.org/licenses/MIT) (see above). Copyright &copy; 2008-2009 [Björn Hoehrmann](http://bjoern.hoehrmann.de/) <bjoern@hoehrmann.de> The class contains the UTF-8 Decoder from Bjoern Hoehrmann which is licensed under the [MIT License](http://opensource.org/licenses/MIT) (see above). Copyright &copy; 2008-2009 [Björn Hoehrmann](http://bjoern.hoehrmann.de/) <bjoern@hoehrmann.de>
* * *
The class contains a slightly modified version of the Grisu2 algorithm from Florian Loitsch which is licensed under the [MIT License](http://opensource.org/licenses/MIT) (see above). Copyright &copy; 2009 [Florian Loitsch](http://florian.loitsch.com/) The class contains a slightly modified version of the Grisu2 algorithm from Florian Loitsch which is licensed under the [MIT License](http://opensource.org/licenses/MIT) (see above). Copyright &copy; 2009 [Florian Loitsch](http://florian.loitsch.com/)
## Contact ## Contact
...@@ -934,6 +932,7 @@ I deeply appreciate the help of the following people. ...@@ -934,6 +932,7 @@ I deeply appreciate the help of the following people.
- [Matthias Möller](https://github.com/TinyTinni) added a `.natvis` for the MSVC debug view. - [Matthias Möller](https://github.com/TinyTinni) added a `.natvis` for the MSVC debug view.
- [bogemic](https://github.com/bogemic) fixed some C++17 deprecation warnings. - [bogemic](https://github.com/bogemic) fixed some C++17 deprecation warnings.
- [Eren Okka](https://github.com/erengy) fixed some MSVC warnings. - [Eren Okka](https://github.com/erengy) fixed some MSVC warnings.
- [abolz](https://github.com/abolz) integrated the Grisu2 algorithm for proper floating-point formatting, allowing more roundtrip checks to succeed.
Thanks a lot for helping out! Please [let me know](mailto:mail@nlohmann.me) if I forgot someone. Thanks a lot for helping out! Please [let me know](mailto:mail@nlohmann.me) if I forgot someone.
......
This diff is collapsed.
...@@ -483,8 +483,8 @@ class serializer ...@@ -483,8 +483,8 @@ class serializer
} }
// If number_float_t is an IEEE-754 single or double precision number, // If number_float_t is an IEEE-754 single or double precision number,
// use the Grisu2 algorithm to produce short numbers which are guaranteed // use the Grisu2 algorithm to produce short numbers which are
// to round-trip, using strtof and strtod, resp. // guaranteed to round-trip, using strtof and strtod, resp.
// //
// NB: The test below works if <long double> == <double>. // NB: The test below works if <long double> == <double>.
static constexpr bool is_ieee_single_or_double static constexpr bool is_ieee_single_or_double
......
This diff is collapsed.
...@@ -60,26 +60,28 @@ static float make_float(uint64_t f, int e) ...@@ -60,26 +60,28 @@ static float make_float(uint64_t f, int e)
constexpr int kDenormalExponent = 1 - kExponentBias; constexpr int kDenormalExponent = 1 - kExponentBias;
constexpr int kMaxExponent = 0xFF - kExponentBias; constexpr int kMaxExponent = 0xFF - kExponentBias;
while (f > kHiddenBit + kSignificandMask) { while (f > kHiddenBit + kSignificandMask)
{
f >>= 1; f >>= 1;
e++; e++;
} }
if (e >= kMaxExponent) { if (e >= kMaxExponent)
{
return std::numeric_limits<float>::infinity(); return std::numeric_limits<float>::infinity();
} }
if (e < kDenormalExponent) { if (e < kDenormalExponent)
{
return 0.0; return 0.0;
} }
while (e > kDenormalExponent && (f & kHiddenBit) == 0) { while (e > kDenormalExponent && (f & kHiddenBit) == 0)
{
f <<= 1; f <<= 1;
e--; e--;
} }
uint64_t biased_exponent; uint64_t biased_exponent = (e == kDenormalExponent && (f & kHiddenBit) == 0)
if (e == kDenormalExponent && (f & kHiddenBit) == 0) ? 0
biased_exponent = 0; : static_cast<uint64_t>(e + kExponentBias);
else
biased_exponent = static_cast<uint64_t>(e + kExponentBias);
uint64_t bits = (f & kSignificandMask) | (biased_exponent << kPhysicalSignificandSize); uint64_t bits = (f & kSignificandMask) | (biased_exponent << kPhysicalSignificandSize);
return reinterpret_bits<float>(static_cast<uint32_t>(bits)); return reinterpret_bits<float>(static_cast<uint32_t>(bits));
...@@ -110,26 +112,28 @@ static double make_double(uint64_t f, int e) ...@@ -110,26 +112,28 @@ static double make_double(uint64_t f, int e)
constexpr int kDenormalExponent = 1 - kExponentBias; constexpr int kDenormalExponent = 1 - kExponentBias;
constexpr int kMaxExponent = 0x7FF - kExponentBias; constexpr int kMaxExponent = 0x7FF - kExponentBias;
while (f > kHiddenBit + kSignificandMask) { while (f > kHiddenBit + kSignificandMask)
{
f >>= 1; f >>= 1;
e++; e++;
} }
if (e >= kMaxExponent) { if (e >= kMaxExponent)
{
return std::numeric_limits<double>::infinity(); return std::numeric_limits<double>::infinity();
} }
if (e < kDenormalExponent) { if (e < kDenormalExponent)
{
return 0.0; return 0.0;
} }
while (e > kDenormalExponent && (f & kHiddenBit) == 0) { while (e > kDenormalExponent && (f & kHiddenBit) == 0)
{
f <<= 1; f <<= 1;
e--; e--;
} }
uint64_t biased_exponent; uint64_t biased_exponent = (e == kDenormalExponent && (f & kHiddenBit) == 0)
if (e == kDenormalExponent && (f & kHiddenBit) == 0) ? 0
biased_exponent = 0; : static_cast<uint64_t>(e + kExponentBias);
else
biased_exponent = static_cast<uint64_t>(e + kExponentBias);
uint64_t bits = (f & kSignificandMask) | (biased_exponent << kPhysicalSignificandSize); uint64_t bits = (f & kSignificandMask) | (biased_exponent << kPhysicalSignificandSize);
return reinterpret_bits<double>(bits); return reinterpret_bits<double>(bits);
...@@ -139,7 +143,7 @@ TEST_CASE("digit gen") ...@@ -139,7 +143,7 @@ TEST_CASE("digit gen")
{ {
SECTION("single precision") SECTION("single precision")
{ {
auto check_float = [](float number, const std::string& digits, int expected_exponent) auto check_float = [](float number, const std::string & digits, int expected_exponent)
{ {
CAPTURE(number); CAPTURE(number);
CAPTURE(digits); CAPTURE(digits);
...@@ -203,7 +207,7 @@ TEST_CASE("digit gen") ...@@ -203,7 +207,7 @@ TEST_CASE("digit gen")
SECTION("double precision") SECTION("double precision")
{ {
auto check_double = [](double number, const std::string& digits, int expected_exponent) auto check_double = [](double number, const std::string & digits, int expected_exponent)
{ {
CAPTURE(number); CAPTURE(number);
CAPTURE(digits); CAPTURE(digits);
...@@ -349,7 +353,7 @@ TEST_CASE("formatting") ...@@ -349,7 +353,7 @@ TEST_CASE("formatting")
{ {
SECTION("single precision") SECTION("single precision")
{ {
auto check_float = [](float number, const std::string& expected) auto check_float = [](float number, const std::string & expected)
{ {
char buf[32]; char buf[32];
char* end = nlohmann::detail::to_chars(buf, buf + 32, number); char* end = nlohmann::detail::to_chars(buf, buf + 32, number);
...@@ -357,7 +361,7 @@ TEST_CASE("formatting") ...@@ -357,7 +361,7 @@ TEST_CASE("formatting")
CHECK(actual == expected); CHECK(actual == expected);
}; };
// %.9g // %.9g
check_float( -1.2345e-22f, "-1.2345e-22" ); // -1.23450004e-22 check_float( -1.2345e-22f, "-1.2345e-22" ); // -1.23450004e-22
check_float( -1.2345e-21f, "-1.2345e-21" ); // -1.23450002e-21 check_float( -1.2345e-21f, "-1.2345e-21" ); // -1.23450002e-21
check_float( -1.2345e-20f, "-1.2345e-20" ); // -1.23450002e-20 check_float( -1.2345e-20f, "-1.2345e-20" ); // -1.23450002e-20
...@@ -409,7 +413,7 @@ TEST_CASE("formatting") ...@@ -409,7 +413,7 @@ TEST_CASE("formatting")
SECTION("double precision") SECTION("double precision")
{ {
auto check_double = [](double number, const std::string& expected) auto check_double = [](double number, const std::string & expected)
{ {
char buf[32]; char buf[32];
char* end = nlohmann::detail::to_chars(buf, buf + 32, number); char* end = nlohmann::detail::to_chars(buf, buf + 32, number);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment