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 signed to unsigned conversion to SafeCast #2111

Closed
frangio opened this issue Mar 9, 2020 · 0 comments · Fixed by #2123
Closed

Add signed to unsigned conversion to SafeCast #2111

frangio opened this issue Mar 9, 2020 · 0 comments · Fixed by #2123
Labels
good first issue Low hanging fruit for new contributors to get involved!

Comments

@frangio
Copy link
Contributor

frangio commented Mar 9, 2020

We should include a function SafeCast.toUint256(int256) returns (uint256). It should check that the value isn't negative.

We may also want to consider the inverse, unsigned to signed: SafeCast.toInt256(uint256) returns (int256).

@nventuro nventuro added the good first issue Low hanging fruit for new contributors to get involved! label Mar 9, 2020
nventuro added a commit that referenced this issue Mar 27, 2020
* Add signed to unsigned conversion to SafeCast

* Update SafeCast exception message

* Add test for SafeCast int to uint conversion

- Update SafeCastMock
- Add tests for SafeCast int256 to uint256

* Update SafeCast int to uint definition

Apply suggestions from code review.

Co-Authored-By: Nicolás Venturo <nicolas.venturo@gmail.com>

* Update test for SafeCast int to uint conversion

* Update SafeCast test after code review

- Change "downcasts" to "casts"
- Move test closer to its function

* Fix error in SafeCast toUint256 description

* Fix breaking error in SafeCast

* Add uint256 to int256 conversion to SafeCast

- Add function
- Add mock
- Add test

* Update SafeCast unsigned to signed conversion

- Update error in conversion to be more clear
- Update constants in test to be powers of 2 instead of shifts

* Add changelog entry

* Update SafeCast tests

- Add minus in INT256_MIN for clarity

Co-Authored-By: Nicolás Venturo <nicolas.venturo@gmail.com>

Co-authored-by: Nicolás Venturo <nicolas.venturo@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Low hanging fruit for new contributors to get involved!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants