Skip to content

Commit

Permalink
Review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
delaaxe committed Feb 13, 2024
1 parent 4c1c064 commit a59189b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
2 changes: 1 addition & 1 deletion corelib/src/integer.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -1373,7 +1373,7 @@ extern fn u512_safe_divmod_by_u256(
U128MulGuarantee
) implicits(RangeCheck) nopanic;

pub(crate) impl U512TryIntoU256 of TryInto<u512, u256> {
impl U512TryIntoU256 of TryInto<u512, u256> {
fn try_into(self: u512) -> Option<u256> {
if self.limb2 != 0 || self.limb3 != 0 {
Option::None
Expand Down
16 changes: 4 additions & 12 deletions corelib/src/test/integer_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -797,18 +797,10 @@ fn test_u512_safe_div_rem_by_u256() {

#[test]
fn test_u512_try_into_u256() {
let num = u512 { limb0: 0xdeadbeef, limb1: 0, limb2: 0, limb3: 0 };
let num_u256: u256 = num.try_into().unwrap();
assert_eq(@num_u256, @0xdeadbeef_u256, 'u512 -> u256');

let num = u512 {
limb0: 0x33233223222222122112111111011001,
limb1: 0x54455445544554454444443443343333,
limb2: 0x21222222322332333333433443444444,
limb3: 0x1001101111112112,
};
let option: Option<u256> = num.try_into();
assert(option.is_none(), 'u512 -/-> u256');
assert!(u512 { limb0: 1, limb1: 2, limb2: 0, limb3: 0 }.try_into() == Option::Some(0x200000000000000000000000000000001_u256));
assert!(u512 { limb0: 1, limb1: 2, limb2: 3, limb3: 0 }.try_into() == Option::<u256>::None);
assert!(u512 { limb0: 1, limb1: 2, limb2: 0, limb3: 4 }.try_into() == Option::<u256>::None);
assert!(u512 { limb0: 1, limb1: 2, limb2: 3, limb3: 4 }.try_into() == Option::<u256>::None);
}

#[test]
Expand Down

0 comments on commit a59189b

Please sign in to comment.