Skip to content

Commit

Permalink
Add mod to U128 (#6771)
Browse files Browse the repository at this point in the history
## Description

The `mod` trait implementation was missing for `U128`. This has been
added.

## 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).
- [x] 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.

Co-authored-by: K1-R1 <[email protected]>
Co-authored-by: IGI-111 <[email protected]>
  • Loading branch information
3 people authored Dec 7, 2024
1 parent bda4d44 commit ff8291a
Show file tree
Hide file tree
Showing 3 changed files with 339 additions and 222 deletions.
11 changes: 11 additions & 0 deletions sway-lib-std/src/u128.sw
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,17 @@ impl core::ops::Divide for U128 {
}
}

impl core::ops::Mod for U128 {
fn modulo(self, other: Self) -> Self {
assert(other != Self::zero());

// a mod b = a - b * (a / b)
let quotient = self / other;
let product = quotient * other;
self - product
}
}

fn u64_checked_add(a: u64, b: u64) -> Option<u64> {
let of = asm(a: a, b: b, res) {
add res a b;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ fn pass_revert_require() {
#[test(should_revert)]
fn revert_revert_with_log() {
revert_with_log("error")
}
}
Loading

0 comments on commit ff8291a

Please sign in to comment.