You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2013/08/06 21:27:09 UTC
[2/2] git commit: Fixed JSON::Number output precision,
and added a test.
Fixed JSON::Number output precision, and added a test.
Review: https://reviews.apache.org/r/12951
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/2eb23c01
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/2eb23c01
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/2eb23c01
Branch: refs/heads/master
Commit: 2eb23c01b8d17cb75b4c5512393f66e178306870
Parents: 733a078
Author: Benjamin Mahler <bm...@twitter.com>
Authored: Wed Jul 24 16:03:35 2013 -0700
Committer: Benjamin Mahler <bm...@twitter.com>
Committed: Tue Aug 6 12:13:07 2013 -0700
----------------------------------------------------------------------
.../libprocess/3rdparty/stout/include/stout/json.hpp | 9 ++++++---
.../3rdparty/stout/include/stout/protobuf.hpp | 2 ++
.../libprocess/3rdparty/stout/tests/json_tests.cpp | 14 ++++++++++++++
3 files changed, 22 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/2eb23c01/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp
index e2ef0d3..4406d07 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp
@@ -3,6 +3,7 @@
#include <iomanip>
#include <iostream>
+#include <limits>
#include <list>
#include <map>
#include <string>
@@ -13,7 +14,7 @@
// TODO(jsirois): Implement parsing that constructs JSON objects.
-
+// TODO(bmahler): Evaluate picojson / JSON_Spirit.
namespace JSON {
// Implementation of the JavaScript Object Notation (JSON) grammar
@@ -132,8 +133,10 @@ struct Renderer : boost::static_visitor<>
void operator () (const Number& number) const
{
- out.precision(10);
- out << number.value;
+ // Use the guaranteed accurate precision, see:
+ // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2005.pdf
+ out << std::setprecision(std::numeric_limits<double>::digits10)
+ << number.value;
}
void operator () (const Object& object) const
http://git-wip-us.apache.org/repos/asf/mesos/blob/2eb23c01/3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp
index bd5bc73..0355416 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/protobuf.hpp
@@ -162,6 +162,8 @@ namespace JSON {
struct Protobuf
{
+ // TODO(bmahler): This currently uses the default value for optional
+ // fields but we may want to revisit this decision.
Protobuf(const google::protobuf::Message& message)
{
const google::protobuf::Reflection* reflection = message.GetReflection();
http://git-wip-us.apache.org/repos/asf/mesos/blob/2eb23c01/3rdparty/libprocess/3rdparty/stout/tests/json_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/tests/json_tests.cpp b/3rdparty/libprocess/3rdparty/stout/tests/json_tests.cpp
index c582d70..29ada8a 100644
--- a/3rdparty/libprocess/3rdparty/stout/tests/json_tests.cpp
+++ b/3rdparty/libprocess/3rdparty/stout/tests/json_tests.cpp
@@ -17,3 +17,17 @@ TEST(JsonTest, BinaryData)
EXPECT_EQ("\"\\\"\\\\\\/\\b\\f\\n\\r\\t\\u0000\\u0019 !#[]\\u007F\\u00FF\"",
stringify(s));
}
+
+
+TEST(JsonTest, NumberFormat)
+{
+ // Test whole numbers.
+ EXPECT_EQ("0", stringify(JSON::Number(0.0)));
+ EXPECT_EQ("1", stringify(JSON::Number(1.0)));
+
+ // Negative.
+ EXPECT_EQ("-1", stringify(JSON::Number(-1.0)));
+
+ // Expect at least 15 digits of precision.
+ EXPECT_EQ("1234567890.12345", stringify(JSON::Number(1234567890.12345)));
+}