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

Add Abs() method to sdk.Int #8962

Closed
4 tasks
hallazzang opened this issue Mar 23, 2021 · 1 comment · Fixed by #8963
Closed
4 tasks

Add Abs() method to sdk.Int #8962

hallazzang opened this issue Mar 23, 2021 · 1 comment · Fixed by #8963

Comments

@hallazzang
Copy link
Contributor

Summary

Add Abs() method to sdk.Int, just like sdk.Dec.

Problem Definition

Getting an absolute value from an integer type is very basic feature, but is missing.
Without this simple Abs() method, one should write:

abs := val
if abs.IsNegative() {
        abs = abs.Neg()
}

Proposal

Just add Abs() method to sdk.Int like this(following conventions in types/int.go):

func abs(i *big.Int) *big.Int { return new(big.Int).Abs(i) }

...

// Abs returns the absolute value of Int.
func (i Int) Abs() Int {
        return Int{abs(i.i)}
}

For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@hallazzang
Copy link
Contributor Author

I'll work on this feature and submit PR.

@mergify mergify bot closed this as completed in #8963 Mar 24, 2021
mergify bot pushed a commit that referenced this issue Mar 24, 2021
Fixes #8962

Co-authored-by: Alessio Treglia <alessio@tendermint.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants