fix: increase sdk.Dec maxApproxRootIterations (#12229)
## Description `ApproxRoot` return incorrect value for large `sdk.Dec` because maxApproxRootIterations is not big enough, I increase it to 300 --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [x] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [x] confirmed `!` in the type prefix if API or client breaking change - [x] confirmed all author checklist items have been addressed - [x] reviewed state machine logic - [x] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [x] manually tested (if applicable)
This commit is contained in:
parent
669db988a5
commit
6a3d10bc57
@ -68,6 +68,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
* (types) [#12154](https://github.com/cosmos/cosmos-sdk/pull/12154) Add `baseAccountGetter` to avoid invalid account error when create vesting account.
|
||||
* (x/authz) [#12184](https://github.com/cosmos/cosmos-sdk/pull/12184) Fix MsgExec not verifying the validity of nested messages.
|
||||
* (x/crisis) [#12208](https://github.com/cosmos/cosmos-sdk/pull/12208) Fix progress index of crisis invariant assertion logs.
|
||||
* (types) [#12229](https://github.com/cosmos/cosmos-sdk/pull/12229) Increase sdk.Dec maxApproxRootIterations to 300
|
||||
|
||||
## [v0.46.0-rc1](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.0-rc1) - 2022-05-23
|
||||
|
||||
|
||||
@ -34,7 +34,7 @@ const (
|
||||
maxDecBitLen = MaxBitLen + decimalTruncateBits
|
||||
|
||||
// max number of iterations in ApproxRoot function
|
||||
maxApproxRootIterations = 100
|
||||
maxApproxRootIterations = 300
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@ -433,11 +433,12 @@ func (s *decimalTestSuite) TestApproxRoot() {
|
||||
{sdk.SmallestDec(), 2, sdk.NewDecWithPrec(1, 9)}, // 1e-18 ^ (0.5) => 1e-9
|
||||
{sdk.SmallestDec(), 3, sdk.MustNewDecFromStr("0.000000999999999997")}, // 1e-18 ^ (1/3) => 1e-6
|
||||
{sdk.NewDecWithPrec(1, 8), 3, sdk.MustNewDecFromStr("0.002154434690031900")}, // 1e-8 ^ (1/3) ≈ 0.00215443469
|
||||
{sdk.MustNewDecFromStr("9000002314687921634000000000000000000021394871242000000000000000"), 2, sdk.MustNewDecFromStr("94868342004527103646332858502867.899477053226766107")},
|
||||
}
|
||||
|
||||
// In the case of 1e-8 ^ (1/3), the result repeats every 5 iterations starting from iteration 24
|
||||
// (i.e. 24, 29, 34, ... give the same result) and never converges enough. The maximum number of
|
||||
// iterations (100) causes the result at iteration 100 to be returned, regardless of convergence.
|
||||
// iterations (300) causes the result at iteration 300 to be returned, regardless of convergence.
|
||||
|
||||
for i, tc := range testCases {
|
||||
res, err := tc.input.ApproxRoot(tc.root)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user