[ https://issues.apache.org/jira/browse/THRIFT-3636?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15146866#comment-15146866 ]
ASF GitHub Bot commented on THRIFT-3636: ---------------------------------------- GitHub user mygityf opened a pull request: https://github.com/apache/thrift/pull/870 THRIFT-3636 The precision is 15 bits after dot of casting from double to string in Thrift-cpp-library- json-protocol. Cpp json protocol double precision should be 16 bits You can merge this pull request into a Git repository by running: $ git pull https://github.com/mygityf/thrift cpp-json-protocol-double-precision-should-be-16bits Alternatively you can review and apply these changes as the patch at: https://github.com/apache/thrift/pull/870.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #870 ---- commit 93f0c9836dbcbb9564413c3f4a20e85799cafb7d Author: Wang Yaofu <voip...@sina.cn> Date: 2016-02-15T02:43:09Z THRIFT-3636 The precision is 15 bits after dot of casting from double to string in Thrift-cpp-library- json-protocol. The precision is 15 bits after dot of format casting from double to string in Thrift-cpp-library- json-protocol. But the expected precision is 16 bits after dot in Thrift-json-protocol. The solution: To Change code 'str.precision(std::numeric_limits<double>::digits10 + 1);' to 'str.precision(std::numeric_limits<double>::digits10 + 2);' in function doubeToString file TJSONProtocol.cpp at line 524, e.g: before: In C++ TJSONProtocol.cpp: double a = 1.12345678906666663; string astr = doubleToString(a); double b = stringToDouble(astr); the result as below: a = 1.1234567890666667 astr = "1.123456789066667" b = 1.1234567890666669 after changing: the result as below: a = 1.1234567890666667 astr = "1.1234567890666667" b = 1.1234567890666667 This result is expected. commit e0bebd14f9df02d31603506b72eb5dbcfea74ce6 Author: Wang Yaofu <voip...@sina.cn> Date: 2016-02-15T02:46:48Z THRIFT-3636 The precision is 15 bits after dot of casting from double to string in Thrift-cpp-library- json-protocol. The precision is 15 bits after dot of format casting from double to string in Thrift-cpp-library- json-protocol. But the expected precision is 16 bits after dot in Thrift-json-protocol. The solution: To Change code 'str.precision(std::numeric_limits<double>::digits10 + 1);' to 'str.precision(std::numeric_limits<double>::digits10 + 2);' in function doubeToString file TJSONProtocol.cpp at line 524, e.g: before: In C++ TJsonProtocol.cpp: double a = 1.12345678906666663; string astr = doubleToString(a); double b = stringToDouble(astr); the result as below: a = 1.1234567890666667 astr = "1.123456789066667" b = 1.1234567890666669 after changing: the result as below: a = 1.1234567890666667 astr = "1.1234567890666667" b = 1.1234567890666667 This result is expected. ---- > The precision is 15 bits after dot of casting from double to string in > Thrift-cpp-library- json-protocol. > --------------------------------------------------------------------------------------------------------- > > Key: THRIFT-3636 > URL: https://issues.apache.org/jira/browse/THRIFT-3636 > Project: Thrift > Issue Type: Bug > Components: C++ - Library > Affects Versions: 0.9.3 > Environment: Linux Max Windows > Reporter: WangYaofu > Assignee: WangYaofu > Fix For: 0.9.4 > > > The precision is 15 bits after dot of format casting from double to string in > Thrift-cpp-library- json-protocol. > But the expected precision is 16 bits after dot in Thrift-json-protocol. > The solution: > To Change code 'str.precision(std::numeric_limits<double>::digits10 + 1);' to > 'str.precision(std::numeric_limits<double>::digits10 + 2);' > in function doubeToString file TJSONProtocol.cpp at line 524, > e.g: > before: > In C++ TJsonProtocol.cpp: > double a = 1.12345678906666663; > string astr = doubleToString(a); > double b = stringToDouble(astr); > the result as below: > a = 1.1234567890666667 > astr = "1.123456789066667" > b = 1.1234567890666669 > after changing: > the result as below: > a = 1.1234567890666667 > astr = "1.1234567890666667" > b = 1.1234567890666667 > This result is expected. -- This message was sent by Atlassian JIRA (v6.3.4#6332)