Skip to content

Commit

Permalink
Allow defining const negative NonZero. (#6425)
Browse files Browse the repository at this point in the history
  • Loading branch information
orizi authored Sep 29, 2024
1 parent 1c651aa commit 30b0475
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions corelib/src/zeroable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ pub(crate) impl Felt252Zeroable = zero_based::ZeroableImpl<felt252>;
/// This type guarantees that the wrapped value is never zero.
#[derive(Copy, Drop)]
pub extern type NonZero<T>;
impl NonZeroNeg<T, +Neg<T>, +TryInto<T, NonZero<T>>> of Neg<NonZero<T>> {
fn neg(a: NonZero<T>) -> NonZero<T> {
// TODO(orizi): Optimize using bounded integers.
let value: T = a.into();
let negated: T = -value;
negated.try_into().unwrap()
}
}

/// Represents the result of checking whether a value is zero.
pub(crate) enum IsZeroResult<T> {
Expand Down

0 comments on commit 30b0475

Please sign in to comment.