forked from FuelLabs/sway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add math & bitwise ops to U256 type 2 (FuelLabs#2445)
* most changes * tests * visibility changes * visibility changes 2 * requested changes * fixes * formatter Co-authored-by: tyshkor <[email protected]> Co-authored-by: Alex Hansen <[email protected]>
- Loading branch information
1 parent
75be099
commit 22a4cc6
Showing
14 changed files
with
476 additions
and
2 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
2 changes: 2 additions & 0 deletions
2
test/src/e2e_vm_tests/test_programs/should_pass/stdlib/u256_div_test/.gitignore
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
out | ||
target |
14 changes: 14 additions & 0 deletions
14
test/src/e2e_vm_tests/test_programs/should_pass/stdlib/u256_div_test/Forc.lock
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[[package]] | ||
name = 'core' | ||
source = 'path+from-root-9D3054CE9B0DD894' | ||
dependencies = [] | ||
|
||
[[package]] | ||
name = 'std' | ||
source = 'path+from-root-9D3054CE9B0DD894' | ||
dependencies = ['core'] | ||
|
||
[[package]] | ||
name = 'u256_div_test' | ||
source = 'root' | ||
dependencies = ['std'] |
8 changes: 8 additions & 0 deletions
8
test/src/e2e_vm_tests/test_programs/should_pass/stdlib/u256_div_test/Forc.toml
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[project] | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
name = "u256_div_test" | ||
|
||
[dependencies] | ||
std = { path = "../../../../../../../sway-lib-std" } |
27 changes: 27 additions & 0 deletions
27
test/src/e2e_vm_tests/test_programs/should_pass/stdlib/u256_div_test/src/main.sw
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
script; | ||
|
||
use std::assert::assert; | ||
use std::u256::U256; | ||
use core::num::*; | ||
|
||
fn main() -> bool { | ||
let zero = ~U256::from(0, 0, 0, 0); | ||
let one = ~U256::from(0, 0, 0, 1); | ||
let two = ~U256::from(0, 0, 0, 2); | ||
let max_u64 = ~U256::from(0, 0, 0, ~u64::max()); | ||
|
||
let div_max_two = max_u64 / two; | ||
assert(div_max_two.c == 0); | ||
assert(div_max_two.d == ~u64::max() >> 1); | ||
|
||
// Product of u64::MAX and u64::MAX. | ||
let mut dividend = ~U256::from(0, 0, ~u64::max(), 1); | ||
let mut res = dividend / max_u64; | ||
assert(res == ~U256::from(0, 0, 1, 0)); | ||
|
||
dividend = ~U256::from(~u64::max(), 0, 0, 0); | ||
let mut res = dividend / max_u64; | ||
assert(res == ~U256::from(1, 0, 0, 0)); | ||
|
||
true | ||
} |
2 changes: 2 additions & 0 deletions
2
test/src/e2e_vm_tests/test_programs/should_pass/stdlib/u256_mul_test/.gitignore
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
out | ||
target |
14 changes: 14 additions & 0 deletions
14
test/src/e2e_vm_tests/test_programs/should_pass/stdlib/u256_mul_test/Forc.lock
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[[package]] | ||
name = 'core' | ||
source = 'path+from-root-333FD703A60081C3' | ||
dependencies = [] | ||
|
||
[[package]] | ||
name = 'std' | ||
source = 'path+from-root-333FD703A60081C3' | ||
dependencies = ['core'] | ||
|
||
[[package]] | ||
name = 'u256_mul_test' | ||
source = 'root' | ||
dependencies = ['std'] |
8 changes: 8 additions & 0 deletions
8
test/src/e2e_vm_tests/test_programs/should_pass/stdlib/u256_mul_test/Forc.toml
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[project] | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
name = "u256_mul_test" | ||
|
||
[dependencies] | ||
std = { path = "../../../../../../../sway-lib-std" } |
Oops, something went wrong.