From 13766fc4352aef5e67ced52d7c723201d708b155 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 16 Nov 2026 07:03:33 +0100 Subject: [PATCH] Fix stale comments in include/ - json_view.hpp: find_key() returns the first member with a duplicate key, not the last one (as find_member() and the API documentation say). - binary_writer.hpp: throw_size_marker_required() throws other_error.502, not other_error.407. - serializer.hpp, number_parse.hpp, to_chars.hpp: doubles are no longer converted with Grisu2 but with the shortest digits of Zmij; Grisu2 is only used for binary32 and other formats. Comments only; the amalgamation is regenerated. Signed-off-by: Niels Lohmann --- include/nlohmann/detail/conversions/to_chars.hpp | 7 ++++--- include/nlohmann/detail/input/number_parse.hpp | 2 +- include/nlohmann/detail/output/binary_writer.hpp | 2 +- include/nlohmann/detail/output/serializer.hpp | 5 +++-- include/nlohmann/json_view.hpp | 2 +- single_include/nlohmann/json.hpp | 16 +++++++++------- single_include/nlohmann/json_view.hpp | 2 +- 7 files changed, 20 insertions(+), 16 deletions(-) diff --git a/include/nlohmann/detail/conversions/to_chars.hpp b/include/nlohmann/detail/conversions/to_chars.hpp index 6cfb9b8e7..67a708f62 100644 --- a/include/nlohmann/detail/conversions/to_chars.hpp +++ b/include/nlohmann/detail/conversions/to_chars.hpp @@ -48,10 +48,11 @@ namespace detail { /*! -@brief implements the Grisu2 algorithm for binary to decimal floating-point -conversion. +@brief implements binary to decimal floating-point conversion: the shortest +digits of Zmij (see zmij.hpp) for IEEE 754 binary64 numbers, and the Grisu2 +algorithm for all other formats. -This implementation is a slightly modified version of the reference +The Grisu2 implementation is a slightly modified version of the reference implementation which may be obtained from http://florian.loitsch.com/publications (bench.tar.gz). diff --git a/include/nlohmann/detail/input/number_parse.hpp b/include/nlohmann/detail/input/number_parse.hpp index 71215d3df..41d8b1ae5 100644 --- a/include/nlohmann/detail/input/number_parse.hpp +++ b/include/nlohmann/detail/input/number_parse.hpp @@ -257,7 +257,7 @@ struct ieee_binary_format<53> // binary64 These formats (float, double, and long double where it is binary64, e.g. with MSVC or on Apple arm64) are converted by parse_float_native(). The -predicate is the one the serializer uses to choose Grisu2. +predicate is the one the serializer uses to choose to_chars() over snprintf. */ template struct has_native_float_format diff --git a/include/nlohmann/detail/output/binary_writer.hpp b/include/nlohmann/detail/output/binary_writer.hpp index cf114b82f..c23dc0738 100644 --- a/include/nlohmann/detail/output/binary_writer.hpp +++ b/include/nlohmann/detail/output/binary_writer.hpp @@ -915,7 +915,7 @@ class binary_writer JSON_THROW(out_of_range::create(exception_id::subtype_out_of_range, concat("subtype ", std::to_string(subtype), " is too large for ", what, " (max 255)"), &j)); } - /// @throw other_error.407 always + /// @throw other_error.502 always JSON_HEDLEY_NO_RETURN JSON_HEDLEY_NEVER_INLINE static void throw_size_marker_required(const BasicJsonType& j) { diff --git a/include/nlohmann/detail/output/serializer.hpp b/include/nlohmann/detail/output/serializer.hpp index eeba0a9de..3f2800d8a 100644 --- a/include/nlohmann/detail/output/serializer.hpp +++ b/include/nlohmann/detail/output/serializer.hpp @@ -2033,8 +2033,9 @@ class serializer } // If number_float_t is an IEEE-754 single or double precision number, - // use the Grisu2 algorithm to produce short numbers which are - // guaranteed to round-trip, using strtof and strtod, resp. + // use to_chars() to produce short numbers which are guaranteed to + // round-trip, using strtof and strtod, resp. (the shortest digits of + // Zmij for binary64, the Grisu2 algorithm for binary32). // // NB: The test below works if == . static constexpr bool is_ieee_single_or_double diff --git a/include/nlohmann/json_view.hpp b/include/nlohmann/json_view.hpp index b922d82dd..e54867d54 100644 --- a/include/nlohmann/json_view.hpp +++ b/include/nlohmann/json_view.hpp @@ -849,7 +849,7 @@ class basic_json_view return !navigation::editable() || m_doc->edits == nullptr; } - /// the member of this object with @a key (the last one if the key occurs more than once), or nullptr + /// the member of this object with @a key (the first one if the key occurs more than once), or nullptr NLOHMANN_VIEW_ALWAYS_INLINE const node* find_key(string_view_t key) const { return find_key(key, std::integral_constant {}); diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 473bfa894..5c351f558 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -11642,7 +11642,7 @@ struct ieee_binary_format<53> // binary64 These formats (float, double, and long double where it is binary64, e.g. with MSVC or on Apple arm64) are converted by parse_float_native(). The -predicate is the one the serializer uses to choose Grisu2. +predicate is the one the serializer uses to choose to_chars() over snprintf. */ template struct has_native_float_format @@ -31147,7 +31147,7 @@ class binary_writer JSON_THROW(out_of_range::create(exception_id::subtype_out_of_range, concat("subtype ", std::to_string(subtype), " is too large for ", what, " (max 255)"), &j)); } - /// @throw other_error.407 always + /// @throw other_error.502 always JSON_HEDLEY_NO_RETURN JSON_HEDLEY_NEVER_INLINE static void throw_size_marker_required(const BasicJsonType& j) { @@ -36006,10 +36006,11 @@ namespace detail { /*! -@brief implements the Grisu2 algorithm for binary to decimal floating-point -conversion. +@brief implements binary to decimal floating-point conversion: the shortest +digits of Zmij (see zmij.hpp) for IEEE 754 binary64 numbers, and the Grisu2 +algorithm for all other formats. -This implementation is a slightly modified version of the reference +The Grisu2 implementation is a slightly modified version of the reference implementation which may be obtained from http://florian.loitsch.com/publications (bench.tar.gz). @@ -39519,8 +39520,9 @@ class serializer } // If number_float_t is an IEEE-754 single or double precision number, - // use the Grisu2 algorithm to produce short numbers which are - // guaranteed to round-trip, using strtof and strtod, resp. + // use to_chars() to produce short numbers which are guaranteed to + // round-trip, using strtof and strtod, resp. (the shortest digits of + // Zmij for binary64, the Grisu2 algorithm for binary32). // // NB: The test below works if == . static constexpr bool is_ieee_single_or_double diff --git a/single_include/nlohmann/json_view.hpp b/single_include/nlohmann/json_view.hpp index 233a55487..b9ad5df72 100644 --- a/single_include/nlohmann/json_view.hpp +++ b/single_include/nlohmann/json_view.hpp @@ -11016,7 +11016,7 @@ class basic_json_view return !navigation::editable() || m_doc->edits == nullptr; } - /// the member of this object with @a key (the last one if the key occurs more than once), or nullptr + /// the member of this object with @a key (the first one if the key occurs more than once), or nullptr NLOHMANN_VIEW_ALWAYS_INLINE const node* find_key(string_view_t key) const { return find_key(key, std::integral_constant {});