-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Type of change <!--Delete points that do not apply--> - Bug fix ## Changes The following changes have been made: - The `TwosComplement` trait was not correctly implemented. To stay in line with Rust's practices, the `WrappingNeg` trait now replaces it with the original desired functionality of the `TwosComplement` trait. - Bits for `I128` and `I256` are now correct - The indent for `I128` and `I256` are now correct ## Notes - This PR changes the folder names in the tests from `iX_twos_complement_test` to `iX_wrapping_neg_test`. ## Breaking Changes The following demonstrates the breaking change. While this example code uses the `I8` type, the same logic may be applied to the `I16`, `I32`, `I64`, `I128`, and `I256` types. Before: ```sway let my_i8 = i8::zero(); let twos_complement = my_i8.twos_complement(); ``` After: ```sway let my_i8 = i8::zero(); let wrapping_neg = my_i8.wrapping_neg(); ``` ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers. - [x] I have updated the changelog to reflect the changes on this PR. --------- Co-authored-by: K1-R1 <[email protected]>
- Loading branch information
Showing
55 changed files
with
693 additions
and
518 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
library; | ||
|
||
/// Trait for the Two's Complement of a value. | ||
pub trait TwosComplement { | ||
/// Returns the two's complement of a value. | ||
/// Wrapping (modular) negation. Computes -self, wrapping around at the boundary of the type. | ||
pub trait WrappingNeg { | ||
/// Negates a signed number. | ||
/// | ||
/// # Additional Information | ||
/// | ||
/// * The only case where such wrapping can occur is when one negates self::min(). In such a case, this function returns self::min() itself. | ||
/// | ||
/// # Returns | ||
/// | ||
/// * [Self] - The value as two's complement. | ||
fn twos_complement(self) -> Self; | ||
fn wrapping_neg(self) -> Self; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.