You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by mygityf <gi...@git.apache.org> on 2016/02/15 03:48:44 UTC

[GitHub] thrift pull request: THRIFT-3636 The precision is 15 bits after do...

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 <vo...@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 <vo...@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.

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] thrift pull request: THRIFT-3636 The precision is 15 bits after do...

Posted by mygityf <gi...@git.apache.org>.
Github user mygityf commented on a diff in the pull request:

    https://github.com/apache/thrift/pull/870#discussion_r52961339
  
    --- Diff: lib/cpp/src/thrift/protocol/TJSONProtocol.cpp ---
    @@ -524,7 +524,8 @@ namespace {
     std::string doubleToString(double d) {
       std::ostringstream str;
       str.imbue(std::locale::classic());
    -  str.precision(std::numeric_limits<double>::digits10 + 1);
    +  // new precision is 17 equal to max_digits10(c++11) or digits10+2
    +  str.precision(17);
    --- End diff --
    
    It looks better than before.
    Thanks.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] thrift pull request: THRIFT-3636 The precision is 15 bits after do...

Posted by nsuke <gi...@git.apache.org>.
Github user nsuke commented on the pull request:

    https://github.com/apache/thrift/pull/870#issuecomment-184044511
  
    thanks for uncovering it !
    The "2" is for "0." ?
    I think the comment can be improved.
    @hcorg maybe you have better alternative than code comment here ?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] thrift pull request: THRIFT-3636 The precision is 15 bits after do...

Posted by mygityf <gi...@git.apache.org>.
Github user mygityf commented on the pull request:

    https://github.com/apache/thrift/pull/870#issuecomment-184556899
  
    @nsuke I replace the PI and golden ratio with float literals and use the same digits(17) in file lib/cpp/test/JSONProtoTest.cpp.
    The result looks OK in Jenkins checking.
    why CI build failed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] thrift pull request: THRIFT-3636 The precision is 15 bits after do...

Posted by hcorg <gi...@git.apache.org>.
Github user hcorg commented on a diff in the pull request:

    https://github.com/apache/thrift/pull/870#discussion_r52925705
  
    --- Diff: lib/cpp/src/thrift/protocol/TJSONProtocol.cpp ---
    @@ -524,7 +524,8 @@ namespace {
     std::string doubleToString(double d) {
       std::ostringstream str;
       str.imbue(std::locale::classic());
    -  str.precision(std::numeric_limits<double>::digits10 + 1);
    +  // new precision is 17 equal to max_digits10(c++11) or digits10+2
    +  str.precision(17);
    --- End diff --
    
    IMHO
    `const double max_digits10 = 2 + std::numeric_limits<double>::digits10;`
    `str.precision(max_digits10);`
    looks better than comment ;)
    
    I'd even consider naming variable `max_digits10_cpp11`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] thrift pull request: THRIFT-3636 The precision is 15 bits after do...

Posted by nsuke <gi...@git.apache.org>.
Github user nsuke commented on the pull request:

    https://github.com/apache/thrift/pull/870#issuecomment-184687016
  
    @mygityf the failure is unrelated to your patch so no need to worry about that any more.
    
    Would you mind if I remove the comment as per @hcorg 's suggestion, now that we have nicely self explanatory variable ?



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] thrift pull request: THRIFT-3636 The precision is 15 bits after do...

Posted by mygityf <gi...@git.apache.org>.
Github user mygityf commented on the pull request:

    https://github.com/apache/thrift/pull/870#issuecomment-184704422
  
    @nsuke just do it to make it better.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] thrift pull request: THRIFT-3636 The precision is 15 bits after do...

Posted by nsuke <gi...@git.apache.org>.
Github user nsuke commented on the pull request:

    https://github.com/apache/thrift/pull/870#issuecomment-184062525
  
    ok, so 2 is the difference between max_digits10 and digits10.
    since we cannot use c++11 max_digits10 yet, I suggest using 17 directly with a comment or a clearly named local variabe.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] thrift pull request: THRIFT-3636 The precision is 15 bits after do...

Posted by mygityf <gi...@git.apache.org>.
Github user mygityf commented on the pull request:

    https://github.com/apache/thrift/pull/870#issuecomment-184066476
  
    using 17 directly with a comment.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] thrift pull request: THRIFT-3636 The precision is 15 bits after do...

Posted by nsuke <gi...@git.apache.org>.
Github user nsuke commented on the pull request:

    https://github.com/apache/thrift/pull/870#issuecomment-184295292
  
    Actually test is failing quite badly.
    Your fix is fine but the test needs fix too.
    A possible fix is to replace the PI and golden ratio with float literals and use the same digits in the assertions.



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] thrift pull request: THRIFT-3636 The precision is 15 bits after do...

Posted by mygityf <gi...@git.apache.org>.
Github user mygityf commented on the pull request:

    https://github.com/apache/thrift/pull/870#issuecomment-184056891
  
    The "1" is for "0.123456789012345".
    The "2" is for "0.1234567890123456".


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] thrift pull request: THRIFT-3636 The precision is 15 bits after do...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/thrift/pull/870


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] thrift pull request: THRIFT-3636 The precision is 15 bits after do...

Posted by mygityf <gi...@git.apache.org>.
Github user mygityf commented on the pull request:

    https://github.com/apache/thrift/pull/870#issuecomment-184078253
  
    It looks no error detected for Jenkins checking.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---