-
Notifications
You must be signed in to change notification settings - Fork 490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add TryInto<u512, u256>
#5031
Add TryInto<u512, u256>
#5031
Conversation
93afade
to
561e36e
Compare
11e8978
to
4c1c064
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 2 files reviewed, 1 unresolved discussion (waiting on @delaaxe)
a discussion (no related file):
any particular usecase for this?
in general we only use u512 for modular operation back into u256.
Our use case is using the first return value of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 2 of 2 files at r1, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @delaaxe)
corelib/src/integer.cairo
line 1384 at r2 (raw file):
} } }
no need (it was required in some specific other instances)
Suggestion:
impl U512TryIntoU256 of TryInto<u512, u256> {
fn try_into(self: u512) -> Option<u256> {
if self.limb2 != 0 || self.limb3 != 0 {
Option::None
} else {
Option::Some(u256 { low: self.limb0, high: self.limb1 })
}
}
}
corelib/src/test/integer_test.cairo
line 811 at r2 (raw file):
}; let option: Option<u256> = num.try_into(); assert(option.is_none(), 'u512 -/-> u256');
Suggestion:
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);
9dcdc49
to
a59189b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 10 files reviewed, 2 unresolved discussions (waiting on @orizi)
corelib/src/integer.cairo
line 1384 at r2 (raw file):
Previously, orizi wrote…
no need (it was required in some specific other instances)
Done.
corelib/src/test/integer_test.cairo
line 811 at r2 (raw file):
}; let option: Option<u256> = num.try_into(); assert(option.is_none(), 'u512 -/-> u256');
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 2 files at r4, 8 of 8 files at r5, 1 of 1 files at r6, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @delaaxe)
a discussion (no related file):
@gilbens-starkware for 2nd eye.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @delaaxe)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @delaaxe)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @delaaxe)
This change is