From b8d05f72ea29e2f0a308a4958958fef13fe41102 Mon Sep 17 00:00:00 2001 From: Niels Date: Thu, 4 Jun 2015 19:43:29 +0200 Subject: [PATCH] fixed float serialization (#81 and #80) --- src/json.hpp | 6 +----- src/json.hpp.re2c | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/json.hpp b/src/json.hpp index c0a630e1..3dbeb65a 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -2284,11 +2284,7 @@ class basic_json { // 15 digits of precision allows round-trip IEEE 754 // string->double->string - using std::snprintf; - const auto sz = static_cast(snprintf(nullptr, 0, "%.15g", m_value.number_float)); - std::vector buf(sz + 1); - snprintf(&buf[0], buf.size(), "%.15g", m_value.number_float); - o << buf.data(); + o << std::setprecision(15) << m_value.number_float; return; } diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index 572690bc..cace230d 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -2284,11 +2284,7 @@ class basic_json { // 15 digits of precision allows round-trip IEEE 754 // string->double->string - using std::snprintf; - const auto sz = static_cast(snprintf(nullptr, 0, "%.15g", m_value.number_float)); - std::vector buf(sz + 1); - snprintf(&buf[0], buf.size(), "%.15g", m_value.number_float); - o << buf.data(); + o << std::setprecision(15) << m_value.number_float; return; }