-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
36 additions
and
36 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
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,44 +1,44 @@ | ||
use dep::std; | ||
|
||
fn main(mut x: u32, y: u32, z: u32, big_int: u128, hexa: str<7>) { | ||
let a = u128::new(x as u64, x as u64); | ||
let b = u128::new(y as u64, x as u64); | ||
fn main(mut x: u32, y: u32, z: u32, big_int: U128, hexa: str<7>) { | ||
let a = U128::from_u64s_le(x as u64, x as u64); | ||
let b = U128::from_u64s_le(y as u64, x as u64); | ||
let c = a + b; | ||
assert(c.lo == z as Field); | ||
assert(c.hi == 2 * x as Field); | ||
assert(u128::from_hex(hexa).lo == 0x1f03a); | ||
let t1 = u128::from_hex("0x9d9c7a87771f03a23783f9d9c7a8777"); | ||
let t2 = u128::from_hex("0x45a26c708BFCF39041"); | ||
assert(U128::from_hex(hexa).lo == 0x1f03a); | ||
let t1 = U128::from_hex("0x9d9c7a87771f03a23783f9d9c7a8777"); | ||
let t2 = U128::from_hex("0x45a26c708BFCF39041"); | ||
let t = t1 + t2; | ||
assert(t.lo == 0xc5e4b029996e17b8); | ||
assert(t.hi == 0x09d9c7a87771f07f); | ||
let t3 = u128::from_le_bytes(t.to_le_bytes()); | ||
let t3 = U128::from_le_bytes(t.to_le_bytes()); | ||
assert(t == t3); | ||
|
||
let t4 = t - t2; | ||
assert(t4 == t1); | ||
|
||
let t5 = u128::new(0, 1); | ||
let t6 = u128::new(1, 0); | ||
let t5 = U128::from_u64s_le(0, 1); | ||
let t6 = U128::from_u64s_le(1, 0); | ||
assert((t5 - t6).hi == 0); | ||
|
||
assert( | ||
(u128::from_hex("0x71f03a23783f9d9c7a8777") * u128::from_hex("0x8BFCF39041")).hi | ||
== u128::from_hex("0x3e4e0471b873470e247c824e61445537").hi | ||
(U128::from_hex("0x71f03a23783f9d9c7a8777") * U128::from_hex("0x8BFCF39041")).hi | ||
== U128::from_hex("0x3e4e0471b873470e247c824e61445537").hi | ||
); | ||
let q = u128::from_hex("0x3e4e0471b873470e247c824e61445537") / u128::from_hex("0x8BFCF39041"); | ||
assert(q == u128::from_hex("0x71f03a23783f9d9c7a8777")); | ||
let q = U128::from_hex("0x3e4e0471b873470e247c824e61445537") / U128::from_hex("0x8BFCF39041"); | ||
assert(q == U128::from_hex("0x71f03a23783f9d9c7a8777")); | ||
|
||
assert(big_int.hi == 2); | ||
|
||
let mut small_int = u128::from_integer(x); | ||
let mut small_int = U128::from_integer(x); | ||
assert(small_int.lo == x as Field); | ||
assert(x == small_int.to_integer()); | ||
let shift = small_int << small_int; | ||
assert(shift == u128::from_integer(x << x)); | ||
assert(shift == U128::from_integer(x << x)); | ||
assert(shift >> small_int == small_int); | ||
assert(shift >> u128::from_integer(127) == u128::from_integer(0)); | ||
assert(shift << u128::from_integer(127) == u128::from_integer(0)); | ||
assert(shift >> U128::from_integer(127) == U128::from_integer(0)); | ||
assert(shift << U128::from_integer(127) == U128::from_integer(0)); | ||
|
||
} | ||
|