Skip to content

Commit

Permalink
Impl Zero
Browse files Browse the repository at this point in the history
  • Loading branch information
Oppen committed Oct 5, 2023
1 parent 8d70387 commit af3320c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions crates/stark-felt/src/arbitrary_proptest.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use lambdaworks_math::{field::element::FieldElement, unsigned_integer::element::UnsignedInteger};
use num_traits::Zero;
use proptest::prelude::*;

use crate::Felt;
Expand Down
21 changes: 12 additions & 9 deletions crates/stark-felt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use core::ops::{Add, Neg};

use bitvec::array::BitArray;
use num_traits::{FromPrimitive, ToPrimitive};
use num_traits::{FromPrimitive, ToPrimitive, Zero};

#[cfg(test)]
mod arbitrary_proptest;
Expand Down Expand Up @@ -130,10 +130,6 @@ impl Felt {
BitArray::new(limbs)
}

/// Checks if `self` is equal to [Felt::ZERO].
pub fn is_zero(&self) -> bool {
*self == Felt::ZERO
}
/// Finite field division.
pub fn field_div(&self, rhs: &NonZeroFelt) -> Self {
Self(self.0 / rhs.0)
Expand Down Expand Up @@ -381,6 +377,16 @@ impl ToPrimitive for Felt {
}
}

impl Zero for Felt {
fn is_zero(&self) -> bool {
*self == Felt::ZERO
}

fn zero() -> Felt {
Felt::ZERO
}
}

impl Add<&Felt> for u64 {
type Output = Option<u64>;

Expand Down Expand Up @@ -822,10 +828,7 @@ mod errors {

#[cfg(test)]
mod test {
use super::{
alloc::{format, string::String, vec::Vec},
Felt, FieldElement, NonZeroFelt,
};
use super::*;
use crate::arbitrary_proptest::nonzero_felt;
use core::ops::Shl;
use proptest::prelude::*;
Expand Down

0 comments on commit af3320c

Please sign in to comment.