Commit Graph

25 Commits

Author SHA1 Message Date
riyueguang
9f5ee3a083
chore: fix some comments (#21085)
Signed-off-by: riyueguang <rustruby@outlook.com>
2024-07-26 11:00:15 +00:00
Tuan Tran
b5319483ed
chore(docs): fix comments that do not start with the name of the exported element. (#20906) 2024-07-10 06:00:36 +00:00
Dev Ojha
90cbb022d5
perf(math): Significantly speedup Dec quo truncate and quo Roundup (#20034)
Co-authored-by: Marko <marko@baricevic.me>
Co-authored-by: marbar3778 <marbar3778@yahoo.com>
Co-authored-by: Alex Peters <alpe@users.noreply.github.com>
2024-05-30 10:44:14 +00:00
Qt
35c4243da9
docs(math): update math docs (#19590) 2024-02-28 15:48:57 +00:00
Dev Ojha
72eae6dc50
perf(math): Use Dec Bigintmut API (#19479) 2024-02-19 16:45:59 +00:00
Dev Ojha
4db9838ae6
perf: Remove an extra heap allocation from NewLegacyDec (#19466)
Co-authored-by: Marko <marbar3778@yahoo.com>
2024-02-19 09:15:57 +00:00
Dev Ojha
0f113520f9
perf: Remove unneeded cmp in Ceil and marshalTo (#19467) 2024-02-19 08:21:47 +00:00
Cosmos SDK
8f0d5b15f0
chore: typos fixes by cosmos-sdk bot (#18689)
Co-authored-by: github-merge-queue <github-merge-queue@users.noreply.github.com>
Co-authored-by: Julien Robert <julien@rbrt.fr>
Co-authored-by: marbar3778 <marbar3778@yahoo.com>
2023-12-11 13:03:19 +00:00
Marko
bed952022b
fix(math): preventative ciel call (#18519) 2023-11-20 10:28:15 +00:00
Đông Liều
393eaef817
feat(math): add mutative api for LegacyDec.BigInt() (#18421) 2023-11-12 09:04:37 +00:00
Roman
267cd15b07
fix(math): revert to correct version of ApproxRoot from a former state breaking change (#17725) 2023-09-18 13:55:51 +00:00
Roman
0288d423b9
feat: LegacyDec MulRoundUp (#17427)
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
2023-08-18 09:58:20 +00:00
Jacob Gadikian
f0aec3f30d
style: use thelper (#16777) 2023-07-03 13:33:05 +00:00
Roman
a2e3711ce0
fix: legacy dec power mut zero exponent precision (#16266) 2023-05-24 00:05:59 +00:00
Dev Ojha
fb8ff071ca
perf: Speedup Dec.Sqrt() (#16141) 2023-05-15 10:34:13 +00:00
Jacob Gadikian
8c182e7d77
style: lints for core, math, simapp, and tests (#15638) 2023-03-31 09:30:29 +02:00
Marko
1f2875d445
style: gofumpt linting (#15605) 2023-03-30 06:27:38 +00:00
Matt Kocubinski
4db99fc1a5
fix(math): Dec marshal shouldn't have side effects (#15506)
## Description

Ref: https://github.com/cosmos/cosmos-sdk/issues/15170
Included in: #15515 

Required to resolve a discrepancy between the sign mode being implemented in #15170 and the existing legacy one.

When calling tx builder [SetMsgs](4a6a1e3cb8/x/auth/tx/builder.go (L208)) messages are coerced to an any type in [NewAnyWithValue](4a6a1e3cb8/codec/types/any.go (L61)). This marshals a message as proto bytes. If a message has cosmos.Dec typed fields, and they are set to nil, the will be set to 0 during seriazliation in the [Dec.Marshal](88909d6f2b/math/dec.go (L801)) implementation.

This side effect *changes* the output of a JSON marshal before and after the call to Dec.Marshal, as shown below.

```go
rates := &stakingtypes.CommissionRates{}
MarshalJson(rates)
// {"rate":"0","max_rate":"0","max_change_rate":"0"}

MarshalProto(rates)

MarshalJson(rates)
//{"rate":"0.000000000000000000","max_rate":"0.000000000000000000","max_change_rate":"0.000000000000000000"}
```

An integration is test is also committed asserting the (now fixed) behavior above.  Its asserts should be changed once a release of math is made and `/tests/go.mod` is updated.



---

### 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/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...

* [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
* [ ] confirmed `!` in the type prefix if API or client breaking change
* [ ] confirmed all author checklist items have been addressed 
* [ ] reviewed state machine logic
* [ ] reviewed API design and naming
* [ ] reviewed documentation is accurate
* [ ] reviewed tests and test coverage
* [ ] manually tested (if applicable)
2023-03-22 19:48:36 +00:00
Julien Robert
88909d6f2b
fix(math): check for negative precision (#14922)
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
2023-02-06 17:55:10 +01:00
Emmanuel T Odeke
d247e7a3b0
fix: math: add LegacyNewDecFromStr fuzzers + remove unnecessary error wrapping (#14252) 2022-12-11 09:02:51 +00:00
Emmanuel T Odeke
3e85182baa
perf: math: optimize and test FormatInt + simplify LegacyNewDecFromStr (#14010)
Optimizes and tests FormatInt by removing inefficient string
concatenation but also making it so much clearer with how one would
express adding thousand separators in natural language. It uses
a combination of strings.Builder whose values can be grown

The performance improvement is stark in every dimension:

```shell
$ benchstat before.txt after3.txt
name                          old time/op    new time/op    delta
DecimalValueRendererFormat-8    4.48µs ± 1%    2.11µs ± 2%  -52.90%  (p=0.000 n=10+10)

name                          old alloc/op   new alloc/op   delta
DecimalValueRendererFormat-8    3.62kB ± 0%    0.78kB ± 0%  -78.59%  (p=0.000 n=10+10)

name                          old allocs/op  new allocs/op  delta
DecimalValueRendererFormat-8      83.0 ± 0%      28.0 ± 0%  -66.27%  (p=0.000 n=10+10)
```

While here, also simplified zero padding for LegacyNewDecFromStr
simply by using strings.Repeat instead of a convoluted
fmt.Sprintf+strconv.Itoa.

Fixes #14008
Fixes #14003

Co-authored-by: Marko <marbar3778@yahoo.com>
2022-11-29 21:00:47 +00:00
Amaury
10ac33edb8
refactor: Move FormatCoins to core (#13306)
* refactor: Move FormatCoins to `core`

* Rename to shorter names

* Add chaneglog

* Don't panic

* add comments

* go mod tidy

* fix changelog

* move structs to top

* Fix test

* go mod tidy

* Refactor tests
2022-10-19 11:21:24 +00:00
Jacob Gadikian
0943a70215
chore: fix linting issues exposed by fixing golangci-lint (#12895)
Co-authored-by: Marko <marbar3778@yahoo.com>
Co-authored-by: Julien Robert <julien@rbrt.fr>
2022-08-11 22:00:24 +02:00
Emmanuel T Odeke
f002e54d26
perf: math: precompute & use square of precisionReuse instead of 2 repeated computations (#12794) 2022-08-02 10:00:08 -04:00
Amaury
eee23d9531
refactor: Move sdk.Dec to math package (#12634)
## Description





---

### 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...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed 
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
2022-07-20 15:13:45 +00:00