Repository: avro Updated Branches: refs/heads/master 2ac78613d -> a974984e6
Fix for AVRO-1216 Project: http://git-wip-us.apache.org/repos/asf/avro/repo Commit: http://git-wip-us.apache.org/repos/asf/avro/commit/a974984e Tree: http://git-wip-us.apache.org/repos/asf/avro/tree/a974984e Diff: http://git-wip-us.apache.org/repos/asf/avro/diff/a974984e Branch: refs/heads/master Commit: a974984e6e7150b2c6e757bce9cc994b740094c1 Parents: 2ac7861 Author: Thiruvalluvan M G <[email protected]> Authored: Tue Jan 31 11:08:31 2017 +0530 Committer: Thiruvalluvan M G <[email protected]> Committed: Tue Jan 31 11:08:31 2017 +0530 ---------------------------------------------------------------------- CHANGES.txt | 2 ++ lang/c++/impl/json/JsonIO.hh | 5 +++-- lang/c++/test/CodecTests.cc | 15 +++++++++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/avro/blob/a974984e/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index 23e544e..2d50d6a 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -129,6 +129,8 @@ Trunk (not yet released) AVRO-1995: JSON Parser does not properly check current state (Victor Mota via thiru) + AVRO-1216. Setting precision for the output stream (John McClean via thiru) + Avro 1.8.1 (14 May 2016) INCOMPATIBLE CHANGES http://git-wip-us.apache.org/repos/asf/avro/blob/a974984e/lang/c++/impl/json/JsonIO.hh ---------------------------------------------------------------------- diff --git a/lang/c++/impl/json/JsonIO.hh b/lang/c++/impl/json/JsonIO.hh index 15e3557..c87f73a 100644 --- a/lang/c++/impl/json/JsonIO.hh +++ b/lang/c++/impl/json/JsonIO.hh @@ -24,6 +24,7 @@ #include <string> #include <sstream> #include <boost/math/special_functions/fpclassify.hpp> +#include <boost/lexical_cast.hpp> #include <boost/utility.hpp> #include "Config.hh" @@ -305,7 +306,7 @@ public: void encodeNumber(T t) { sep(); std::ostringstream oss; - oss << t; + oss << boost::lexical_cast<std::string>(t); const std::string& s = oss.str(); out_.writeBytes(reinterpret_cast<const uint8_t*>(&s[0]), s.size()); sep2(); @@ -315,7 +316,7 @@ public: sep(); std::ostringstream oss; if (boost::math::isfinite(t)) { - oss << t; + oss << boost::lexical_cast<std::string>(t); } else if (boost::math::isnan(t)) { oss << "NaN"; } else if (t == std::numeric_limits<double>::infinity()) { http://git-wip-us.apache.org/repos/asf/avro/blob/a974984e/lang/c++/test/CodecTests.cc ---------------------------------------------------------------------- diff --git a/lang/c++/test/CodecTests.cc b/lang/c++/test/CodecTests.cc index a7977b6..f8bbe84 100644 --- a/lang/c++/test/CodecTests.cc +++ b/lang/c++/test/CodecTests.cc @@ -1513,9 +1513,13 @@ static void testLimits(const EncoderPtr& e, const DecoderPtr& d) e->encodeDouble(std::numeric_limits<double>::infinity()); e->encodeDouble(-std::numeric_limits<double>::infinity()); e->encodeDouble(std::numeric_limits<double>::quiet_NaN()); + e->encodeDouble(std::numeric_limits<double>::max()); + e->encodeDouble(std::numeric_limits<double>::min()); e->encodeFloat(std::numeric_limits<float>::infinity()); e->encodeFloat(-std::numeric_limits<float>::infinity()); e->encodeFloat(std::numeric_limits<float>::quiet_NaN()); + e->encodeFloat(std::numeric_limits<float>::max()); + e->encodeFloat(std::numeric_limits<float>::min()); e->flush(); } @@ -1527,13 +1531,16 @@ static void testLimits(const EncoderPtr& e, const DecoderPtr& d) BOOST_CHECK_EQUAL(d->decodeDouble(), -std::numeric_limits<double>::infinity()); BOOST_CHECK(boost::math::isnan(d->decodeDouble())); + BOOST_CHECK(d->decodeDouble() == std::numeric_limits<double>::max()); + BOOST_CHECK(d->decodeDouble() == std::numeric_limits<double>::min()); BOOST_CHECK_EQUAL(d->decodeFloat(), std::numeric_limits<float>::infinity()); BOOST_CHECK_EQUAL(d->decodeFloat(), -std::numeric_limits<float>::infinity()); BOOST_CHECK(boost::math::isnan(d->decodeFloat())); + BOOST_CHECK_CLOSE(d->decodeFloat(), std::numeric_limits<float>::max(), 0.00011); + BOOST_CHECK_CLOSE(d->decodeFloat(), std::numeric_limits<float>::min(), 0.00011); } - } static void testLimitsBinaryCodec() @@ -1547,9 +1554,13 @@ static void testLimitsJsonCodec() "{ \"name\": \"d1\", \"type\": \"double\" }," "{ \"name\": \"d2\", \"type\": \"double\" }," "{ \"name\": \"d3\", \"type\": \"double\" }," + "{ \"name\": \"d4\", \"type\": \"double\" }," + "{ \"name\": \"d5\", \"type\": \"double\" }," "{ \"name\": \"f1\", \"type\": \"float\" }," "{ \"name\": \"f2\", \"type\": \"float\" }," - "{ \"name\": \"f3\", \"type\": \"float\" }" + "{ \"name\": \"f3\", \"type\": \"float\" }," + "{ \"name\": \"f4\", \"type\": \"float\" }," + "{ \"name\": \"f5\", \"type\": \"float\" }" "]}"; ValidSchema schema = parsing::makeValidSchema(s); testLimits(jsonEncoder(schema), jsonDecoder(schema));
