Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #7640: tally calculation precision error #7641

Merged
merged 3 commits into from
Nov 2, 2020

Conversation

yihuang
Copy link
Collaborator

@yihuang yihuang commented Oct 23, 2020

Solution:

  • change (a / b) * c to a * c / b

Description

closes: #7640


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer
  • Review Codecov Report in the comment section below once CI passes

@codecov
Copy link

codecov bot commented Oct 23, 2020

Codecov Report

Merging #7641 into master will decrease coverage by 0.00%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #7641      +/-   ##
==========================================
- Coverage   54.34%   54.34%   -0.01%     
==========================================
  Files         610      610              
  Lines       38629    38627       -2     
==========================================
- Hits        20992    20990       -2     
  Misses      15493    15493              
  Partials     2144     2144              

Copy link
Contributor

@amaury1093 amaury1093 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've never looked at Dec's code, I thought Dec would handle arithmetic like this correctly. Anyways, this lgtm too, but I would prefer having someone with more experience on this code have a look too.

Copy link
Collaborator

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! can you add a test case that matches your example from the issue?

@cwgoes
Copy link
Contributor

cwgoes commented Oct 23, 2020

We should always be using this order of operations, I wonder if we can lint for it somehow.

@sunnya97
Copy link
Member

@amaurymartiny Dec has limited precision, hardcode defaulted to 18 decimal points

@yihuang
Copy link
Collaborator Author

yihuang commented Oct 26, 2020

Thanks! can you add a test case that matches your example from the issue?

I don't know how to setup related chain environment in unit tests, or simulation tests, not clear about how the simulation framework works either, I need to read more about that.

@fedekunze
Copy link
Collaborator

I don't know how to setup related chain environment in unit tests, or simulation tests, not clear about how the simulation framework works either, I need to read more about that.

@yihuang It could just be a Dec unit test on types/dec_test.go

@yihuang
Copy link
Collaborator Author

yihuang commented Oct 27, 2020

I don't know how to setup related chain environment in unit tests, or simulation tests, not clear about how the simulation framework works either, I need to read more about that.

@yihuang It could just be a Dec unit test on types/dec_test.go

just added a simple test case.

Copy link
Contributor

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

@fedekunze
Copy link
Collaborator

I think this PR requires a Bug Fix changelog entry

Solution:
- change `(a / b) * c` to `a * b / c`
@yihuang
Copy link
Collaborator Author

yihuang commented Oct 31, 2020

I think this PR requires a Bug Fix changelog entry

thanks, done.

@amaury1093 amaury1093 added the A:automerge Automatically merge PR once all prerequisites pass. label Nov 2, 2020
@mergify mergify bot merged commit aff88bb into cosmos:master Nov 2, 2020
@odeke-em odeke-em mentioned this pull request Nov 10, 2020
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:automerge Automatically merge PR once all prerequisites pass.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tally calculation has precision issue
7 participants