Struct starknet_crypto::FieldElement
source · pub struct FieldElement { /* private fields */ }
Implementations§
source§impl FieldElement
impl FieldElement
sourcepub const ZERO: FieldElement = FieldElement::from_mont([0, 0, 0, 0])
pub const ZERO: FieldElement = FieldElement::from_mont([0, 0, 0, 0])
FieldElement constant that’s equal to 0
sourcepub const ONE: FieldElement = FieldElement::from_mont([18446744073709551585, 18446744073709551615,
18446744073709551615, 576460752303422960])
pub const ONE: FieldElement = FieldElement::from_mont([18446744073709551585, 18446744073709551615, 18446744073709551615, 576460752303422960])
FieldElement constant that’s equal to 1
sourcepub const TWO: FieldElement = FieldElement::from_mont([18446744073709551553, 18446744073709551615,
18446744073709551615, 576460752303422416])
pub const TWO: FieldElement = FieldElement::from_mont([18446744073709551553, 18446744073709551615, 18446744073709551615, 576460752303422416])
FieldElement constant that’s equal to 2
sourcepub const THREE: FieldElement = FieldElement::from_mont([18446744073709551521, 18446744073709551615,
18446744073709551615, 576460752303421872])
pub const THREE: FieldElement = FieldElement::from_mont([18446744073709551521, 18446744073709551615, 18446744073709551615, 576460752303421872])
FieldElement constant that’s equal to 3
sourcepub const MAX: FieldElement = FieldElement::from_mont([32, 0, 0, 544])
pub const MAX: FieldElement = FieldElement::from_mont([32, 0, 0, 544])
Maximum value of FieldElement. Equals to 2^251 + 17 * 2^192.
sourcepub const fn from_mont(data: [u64; 4]) -> FieldElement
pub const fn from_mont(data: [u64; 4]) -> FieldElement
Create a new FieldElement from its Montgomery representation
pub fn from_dec_str(value: &str) -> Result<FieldElement, FromStrError>
pub fn from_hex_be(value: &str) -> Result<FieldElement, FromStrError>
sourcepub fn from_bytes_be(
bytes: &[u8; 32]
) -> Result<FieldElement, FromByteArrayError>
pub fn from_bytes_be( bytes: &[u8; 32] ) -> Result<FieldElement, FromByteArrayError>
Attempts to convert a big-endian byte representation of a field element into an element of this prime field. Returns error if the input is not canonical (is not smaller than the field’s modulus).
Arguments
bytes
: The byte array in big endian format
sourcepub fn from_byte_slice_be(
bytes: &[u8]
) -> Result<FieldElement, FromByteSliceError>
pub fn from_byte_slice_be( bytes: &[u8] ) -> Result<FieldElement, FromByteSliceError>
Same as from_bytes_be
except this function takes a slice.
sourcepub fn to_bits_le(self) -> [bool; 256]
pub fn to_bits_le(self) -> [bool; 256]
Transforms FieldElement into little endian bit representation.
sourcepub fn to_bytes_be(&self) -> [u8; 32]
pub fn to_bytes_be(&self) -> [u8; 32]
Convert the field element into a big-endian byte representation
sourcepub const fn into_mont(self) -> [u64; 4]
pub const fn into_mont(self) -> [u64; 4]
Transforms FieldElement into its Montgomery representation
pub fn invert(&self) -> Option<FieldElement>
pub fn sqrt(&self) -> Option<FieldElement>
sourcepub fn floor_div(&self, rhs: FieldElement) -> FieldElement
pub fn floor_div(&self, rhs: FieldElement) -> FieldElement
Performs a floor division. It’s not implemented as the Div
trait on purpose to
distinguish from the “felt division”.
Trait Implementations§
source§impl Add<FieldElement> for FieldElement
impl Add<FieldElement> for FieldElement
§type Output = FieldElement
type Output = FieldElement
+
operator.source§fn add(self, rhs: FieldElement) -> <FieldElement as Add<FieldElement>>::Output
fn add(self, rhs: FieldElement) -> <FieldElement as Add<FieldElement>>::Output
+
operation. Read moresource§impl AddAssign<FieldElement> for FieldElement
impl AddAssign<FieldElement> for FieldElement
source§fn add_assign(&mut self, rhs: FieldElement)
fn add_assign(&mut self, rhs: FieldElement)
+=
operation. Read moresource§impl BitAnd<FieldElement> for FieldElement
impl BitAnd<FieldElement> for FieldElement
§type Output = FieldElement
type Output = FieldElement
&
operator.source§fn bitand(
self,
rhs: FieldElement
) -> <FieldElement as BitAnd<FieldElement>>::Output
fn bitand( self, rhs: FieldElement ) -> <FieldElement as BitAnd<FieldElement>>::Output
&
operation. Read moresource§impl BitOr<FieldElement> for FieldElement
impl BitOr<FieldElement> for FieldElement
§type Output = FieldElement
type Output = FieldElement
|
operator.source§fn bitor(
self,
rhs: FieldElement
) -> <FieldElement as BitOr<FieldElement>>::Output
fn bitor( self, rhs: FieldElement ) -> <FieldElement as BitOr<FieldElement>>::Output
|
operation. Read moresource§impl Clone for FieldElement
impl Clone for FieldElement
source§fn clone(&self) -> FieldElement
fn clone(&self) -> FieldElement
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for FieldElement
impl Debug for FieldElement
source§impl Default for FieldElement
impl Default for FieldElement
source§fn default() -> FieldElement
fn default() -> FieldElement
source§impl Display for FieldElement
impl Display for FieldElement
source§impl From<u16> for FieldElement
impl From<u16> for FieldElement
source§fn from(value: u16) -> FieldElement
fn from(value: u16) -> FieldElement
source§impl From<u32> for FieldElement
impl From<u32> for FieldElement
source§fn from(value: u32) -> FieldElement
fn from(value: u32) -> FieldElement
source§impl From<u64> for FieldElement
impl From<u64> for FieldElement
source§fn from(value: u64) -> FieldElement
fn from(value: u64) -> FieldElement
source§impl From<u8> for FieldElement
impl From<u8> for FieldElement
source§fn from(value: u8) -> FieldElement
fn from(value: u8) -> FieldElement
source§impl From<usize> for FieldElement
impl From<usize> for FieldElement
source§fn from(value: usize) -> FieldElement
fn from(value: usize) -> FieldElement
source§impl FromStr for FieldElement
impl FromStr for FieldElement
§type Err = FromStrError
type Err = FromStrError
source§fn from_str(s: &str) -> Result<FieldElement, <FieldElement as FromStr>::Err>
fn from_str(s: &str) -> Result<FieldElement, <FieldElement as FromStr>::Err>
s
to return a value of this type. Read moresource§impl Hash for FieldElement
impl Hash for FieldElement
source§impl LowerHex for FieldElement
impl LowerHex for FieldElement
source§impl Mul<FieldElement> for FieldElement
impl Mul<FieldElement> for FieldElement
§type Output = FieldElement
type Output = FieldElement
*
operator.source§fn mul(self, rhs: FieldElement) -> <FieldElement as Mul<FieldElement>>::Output
fn mul(self, rhs: FieldElement) -> <FieldElement as Mul<FieldElement>>::Output
*
operation. Read moresource§impl MulAssign<FieldElement> for FieldElement
impl MulAssign<FieldElement> for FieldElement
source§fn mul_assign(&mut self, rhs: FieldElement)
fn mul_assign(&mut self, rhs: FieldElement)
*=
operation. Read moresource§impl Neg for FieldElement
impl Neg for FieldElement
§type Output = FieldElement
type Output = FieldElement
-
operator.source§impl Ord for FieldElement
impl Ord for FieldElement
source§fn cmp(&self, other: &FieldElement) -> Ordering
fn cmp(&self, other: &FieldElement) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere Self: Sized,
source§impl PartialEq<FieldElement> for FieldElement
impl PartialEq<FieldElement> for FieldElement
source§fn eq(&self, other: &FieldElement) -> bool
fn eq(&self, other: &FieldElement) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd<FieldElement> for FieldElement
impl PartialOrd<FieldElement> for FieldElement
source§fn partial_cmp(&self, other: &FieldElement) -> Option<Ordering>
fn partial_cmp(&self, other: &FieldElement) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl Rem<FieldElement> for FieldElement
impl Rem<FieldElement> for FieldElement
§type Output = FieldElement
type Output = FieldElement
%
operator.source§fn rem(self, rhs: FieldElement) -> <FieldElement as Rem<FieldElement>>::Output
fn rem(self, rhs: FieldElement) -> <FieldElement as Rem<FieldElement>>::Output
%
operation. Read moresource§impl Sub<FieldElement> for FieldElement
impl Sub<FieldElement> for FieldElement
§type Output = FieldElement
type Output = FieldElement
-
operator.source§fn sub(self, rhs: FieldElement) -> <FieldElement as Sub<FieldElement>>::Output
fn sub(self, rhs: FieldElement) -> <FieldElement as Sub<FieldElement>>::Output
-
operation. Read moresource§impl SubAssign<FieldElement> for FieldElement
impl SubAssign<FieldElement> for FieldElement
source§fn sub_assign(&mut self, rhs: FieldElement)
fn sub_assign(&mut self, rhs: FieldElement)
-=
operation. Read more