From 65a2f67b912fbf6a45d18587ac1a3554c6697634 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 10 Oct 2026 11:05:12 +0200 Subject: [PATCH] Write doubles from their bits only where double is IEEE 754 binary64 Signed-off-by: Niels Lohmann --- include/nlohmann/detail/view/serializer.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/nlohmann/detail/view/serializer.hpp b/include/nlohmann/detail/view/serializer.hpp index eeff92851..8e5c6dc1c 100644 --- a/include/nlohmann/detail/view/serializer.hpp +++ b/include/nlohmann/detail/view/serializer.hpp @@ -257,6 +257,8 @@ class view_serializer using nav = navigation; using string_t = typename BasicJsonType::string_t; using number_float_t = typename BasicJsonType::number_float_t; + /// doubles that are IEEE 754 binary64 are written from their bits (Zmij) + using fast_double = std::integral_constant < bool, std::is_same::value && ::nlohmann::detail::dtoa_impl::is_binary64::value >; public: view_serializer(const document_data& d, string_t& out, std::size_t estimate, const dump_style& style) @@ -526,7 +528,7 @@ class view_serializer room(n->len); copy(src + n->off, n->len); } - else if (enabled(std::is_same::value)) + else if (enabled(fast_double::value)) { room(64); w = write_double_at(w, *n); @@ -716,7 +718,7 @@ class view_serializer /// a float node as dump() writes it void write_float_node(const node& n) { - write_float_node(n, std::is_same {}); + write_float_node(n, fast_double {}); } void write_float_node(const node& n, std::false_type /*other*/)