-
Notifications
You must be signed in to change notification settings - Fork 388
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(p/int256): "-0" Output When Calculating Basic Arithmetics #2750
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #2750 +/- ##
==========================================
+ Coverage 60.21% 60.79% +0.57%
==========================================
Files 562 563 +1
Lines 75038 75985 +947
==========================================
+ Hits 45185 46192 +1007
+ Misses 26476 26398 -78
- Partials 3377 3395 +18
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
ToString
methodThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one comment. Looks good to me other than that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's a problem at the root of this package; which is why is this not using two's complement?
The correct name for this package would actually be int257, because each Int is actually storing 257 bits of information, seeing as we separate the sign from the actual number.
If you were using two's complement, you wouldn't have problems like -0 to begin with, and addition/subtraction would Just Work without using any conditionals. So, if you're looking for improvements on this package, that's one place to look.
Aside from that, approach looks good. I made a suggestion to organize/optimize the result of Cmp.
If my recall correctly, this topic came up during the implementation, but we decided to follow another implementation that we were referencing, so that we eneded up setting the I definitely agree that we can eliminate a bunch of codes in current implementation. I'm currently preparing for a improvement of the 256-types, and I'll add this change as part of those modifications. |
#2846) # Description This PR optimizes the implementation of `int256` type. Key changes include: - Changed from storing sign and value separately in the Int256 struct to an implementation using two's complement method. - This reduces unnecessary operations and improves overall performance. ## Performance Result - Basic arithmetic operations (addition, subtraction, etc.): About 3x performance improvement (based on Go benchmarks, may differ slightly in gno) - Division operations: Up to 5x performance decrease compared to the previous implementation (can be improved by directly manipulating array fields, but not applied to avoid duplication with p/demo/uint256) ## Additional improvements: - Increased test coverage to 95%. **This change is expected to improve performance for most int256 operations. However, please note the performance degradation in division operations.** ## See Also #2750 (review) <details><summary>Contributors' checklist...</summary> - [X] Added new tests, or not needed, or not feasible - [ ] Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory - [ ] Updated the official documentation or not needed - [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message was included in the description - [ ] Added references to related issues and PRs - [ ] Provided any useful hints for running manual tests - [ ] Added new benchmarks to [generated graphs](https://gnoland.github.io/benchmarks), if any. More info [here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md). </details> --------- Co-authored-by: Morgan <[email protected]>
gnolang#2846) # Description This PR optimizes the implementation of `int256` type. Key changes include: - Changed from storing sign and value separately in the Int256 struct to an implementation using two's complement method. - This reduces unnecessary operations and improves overall performance. ## Performance Result - Basic arithmetic operations (addition, subtraction, etc.): About 3x performance improvement (based on Go benchmarks, may differ slightly in gno) - Division operations: Up to 5x performance decrease compared to the previous implementation (can be improved by directly manipulating array fields, but not applied to avoid duplication with p/demo/uint256) ## Additional improvements: - Increased test coverage to 95%. **This change is expected to improve performance for most int256 operations. However, please note the performance degradation in division operations.** ## See Also gnolang#2750 (review) <details><summary>Contributors' checklist...</summary> - [X] Added new tests, or not needed, or not feasible - [ ] Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory - [ ] Updated the official documentation or not needed - [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message was included in the description - [ ] Added references to related issues and PRs - [ ] Provided any useful hints for running manual tests - [ ] Added new benchmarks to [generated graphs](https://gnoland.github.io/benchmarks), if any. More info [here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md). </details> --------- Co-authored-by: Morgan <[email protected]>
#2846) # Description This PR optimizes the implementation of `int256` type. Key changes include: - Changed from storing sign and value separately in the Int256 struct to an implementation using two's complement method. - This reduces unnecessary operations and improves overall performance. ## Performance Result - Basic arithmetic operations (addition, subtraction, etc.): About 3x performance improvement (based on Go benchmarks, may differ slightly in gno) - Division operations: Up to 5x performance decrease compared to the previous implementation (can be improved by directly manipulating array fields, but not applied to avoid duplication with p/demo/uint256) ## Additional improvements: - Increased test coverage to 95%. **This change is expected to improve performance for most int256 operations. However, please note the performance degradation in division operations.** ## See Also #2750 (review) <details><summary>Contributors' checklist...</summary> - [X] Added new tests, or not needed, or not feasible - [ ] Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory - [ ] Updated the official documentation or not needed - [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message was included in the description - [ ] Added references to related issues and PRs - [ ] Provided any useful hints for running manual tests - [ ] Added new benchmarks to [generated graphs](https://gnoland.github.io/benchmarks), if any. More info [here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md). </details> --------- Co-authored-by: Morgan <[email protected]>
Description
Div
functionContributors' checklist...
BREAKING CHANGE: xxx
message was included in the description