Struct starknet_crypto::FieldElement
source · pub struct FieldElement { /* private fields */ }
Implementations§
source§impl FieldElement
impl FieldElement
sourcepub const ZERO: FieldElement = _
pub const ZERO: FieldElement = _
FieldElement constant that’s equal to 0
sourcepub const ONE: FieldElement = _
pub const ONE: FieldElement = _
FieldElement constant that’s equal to 1
sourcepub const TWO: FieldElement = _
pub const TWO: FieldElement = _
FieldElement constant that’s equal to 2
sourcepub const THREE: FieldElement = _
pub const THREE: FieldElement = _
FieldElement constant that’s equal to 3
sourcepub const MAX: FieldElement = _
pub const MAX: FieldElement = _
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>
pub fn double(&self) -> 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 for FieldElement
impl Add for FieldElement
§type Output = FieldElement
type Output = FieldElement
+
operator.source§fn add(self, rhs: FieldElement) -> <FieldElement as Add>::Output
fn add(self, rhs: FieldElement) -> <FieldElement as Add>::Output
+
operation. Read moresource§impl AddAssign for FieldElement
impl AddAssign for FieldElement
source§fn add_assign(&mut self, rhs: FieldElement)
fn add_assign(&mut self, rhs: FieldElement)
+=
operation. Read moresource§impl AsRef<FieldElement> for FieldElement
impl AsRef<FieldElement> for FieldElement
source§fn as_ref(&self) -> &FieldElement
fn as_ref(&self) -> &FieldElement
source§impl BitAnd for FieldElement
impl BitAnd for FieldElement
§type Output = FieldElement
type Output = FieldElement
&
operator.source§fn bitand(self, rhs: FieldElement) -> <FieldElement as BitAnd>::Output
fn bitand(self, rhs: FieldElement) -> <FieldElement as BitAnd>::Output
&
operation. Read moresource§impl BitOr for FieldElement
impl BitOr for FieldElement
§type Output = FieldElement
type Output = FieldElement
|
operator.source§fn bitor(self, rhs: FieldElement) -> <FieldElement as BitOr>::Output
fn bitor(self, rhs: FieldElement) -> <FieldElement as BitOr>::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<u128> for FieldElement
impl From<u128> for FieldElement
source§fn from(value: u128) -> FieldElement
fn from(value: u128) -> 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 for FieldElement
impl Mul for FieldElement
§type Output = FieldElement
type Output = FieldElement
*
operator.source§fn mul(self, rhs: FieldElement) -> <FieldElement as Mul>::Output
fn mul(self, rhs: FieldElement) -> <FieldElement as Mul>::Output
*
operation. Read moresource§impl MulAssign for FieldElement
impl MulAssign 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 for FieldElement
impl PartialEq 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 for FieldElement
impl PartialOrd 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 for FieldElement
impl Rem for FieldElement
§type Output = FieldElement
type Output = FieldElement
%
operator.source§fn rem(self, rhs: FieldElement) -> <FieldElement as Rem>::Output
fn rem(self, rhs: FieldElement) -> <FieldElement as Rem>::Output
%
operation. Read moresource§impl Sub for FieldElement
impl Sub for FieldElement
§type Output = FieldElement
type Output = FieldElement
-
operator.source§fn sub(self, rhs: FieldElement) -> <FieldElement as Sub>::Output
fn sub(self, rhs: FieldElement) -> <FieldElement as Sub>::Output
-
operation. Read moresource§impl SubAssign for FieldElement
impl SubAssign for FieldElement
source§fn sub_assign(&mut self, rhs: FieldElement)
fn sub_assign(&mut self, rhs: FieldElement)
-=
operation. Read moresource§impl<'a> Sum<&'a FieldElement> for FieldElement
impl<'a> Sum<&'a FieldElement> for FieldElement
source§fn sum<I>(iter: I) -> FieldElementwhere
I: Iterator<Item = &'a FieldElement>,
fn sum<I>(iter: I) -> FieldElementwhere
I: Iterator<Item = &'a FieldElement>,
Self
from the elements by
“summing up” the items.source§impl Sum for FieldElement
impl Sum for FieldElement
source§fn sum<I>(iter: I) -> FieldElementwhere
I: Iterator<Item = FieldElement>,
fn sum<I>(iter: I) -> FieldElementwhere
I: Iterator<Item = FieldElement>,
Self
from the elements by
“summing up” the items.