Struct snarkvm_console_types_scalar::Scalar
source · pub struct Scalar<E: Environment> { /* private fields */ }
Implementations§
source§impl<E: Environment> Scalar<E>
impl<E: Environment> Scalar<E>
sourcepub fn from_field_lossy(field: &Field<E>) -> Result<Self>
pub fn from_field_lossy(field: &Field<E>) -> Result<Self>
Casts a scalar from a base field, with lossy truncation.
This method is commonly-used by hash-to-scalar algorithms, where the hash output does not need to preserve the full base field.
source§impl<E: Environment> Scalar<E>
impl<E: Environment> Scalar<E>
sourcepub const SIZE_IN_BITS: usize = <E::Scalar>::SIZE_IN_BITS
pub const SIZE_IN_BITS: usize = <E::Scalar>::SIZE_IN_BITS
The scalar size in bits.
sourcepub const SIZE_IN_BYTES: usize = _
pub const SIZE_IN_BYTES: usize = _
The scalar size in bytes.
sourcepub const SIZE_IN_DATA_BITS: usize = <E::Scalar>::SIZE_IN_DATA_BITS
pub const SIZE_IN_DATA_BITS: usize = <E::Scalar>::SIZE_IN_DATA_BITS
The scalar capacity for data bits.
Trait Implementations§
source§impl<E: Environment> AddAssign<&Scalar<E>> for Scalar<E>
impl<E: Environment> AddAssign<&Scalar<E>> for Scalar<E>
source§fn add_assign(&mut self, other: &Scalar<E>)
fn add_assign(&mut self, other: &Scalar<E>)
Adds other
to self
.
source§impl<E: Environment> AddAssign<Scalar<E>> for Scalar<E>
impl<E: Environment> AddAssign<Scalar<E>> for Scalar<E>
source§fn add_assign(&mut self, other: Scalar<E>)
fn add_assign(&mut self, other: Scalar<E>)
Adds other
to self
.
source§impl<E: Environment> Compare<Scalar<E>> for Scalar<E>
impl<E: Environment> Compare<Scalar<E>> for Scalar<E>
source§fn is_less_than(&self, other: &Self) -> Self::Output
fn is_less_than(&self, other: &Self) -> Self::Output
Returns true
if self
is less than other
.
source§fn is_greater_than(&self, other: &Self) -> Self::Output
fn is_greater_than(&self, other: &Self) -> Self::Output
Returns true
if self
is greater than other
.
source§fn is_less_than_or_equal(&self, other: &Self) -> Self::Output
fn is_less_than_or_equal(&self, other: &Self) -> Self::Output
Returns true
if self
is less than or equal to other
.
source§fn is_greater_than_or_equal(&self, other: &Self) -> Self::Output
fn is_greater_than_or_equal(&self, other: &Self) -> Self::Output
Returns true
if self
is greater than or equal to other
.
type Output = Boolean<E>
source§impl<E: Environment> Debug for Scalar<E>
impl<E: Environment> Debug for Scalar<E>
source§impl<E: Environment> Deref for Scalar<E>
impl<E: Environment> Deref for Scalar<E>
source§impl<'de, E: Environment> Deserialize<'de> for Scalar<E>
impl<'de, E: Environment> Deserialize<'de> for Scalar<E>
source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserializes the scalar from a string or bytes.
source§impl<E: Environment> Display for Scalar<E>
impl<E: Environment> Display for Scalar<E>
source§impl<E: Environment> Distribution<Scalar<E>> for Standard
impl<E: Environment> Distribution<Scalar<E>> for Standard
source§fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Scalar<E>
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Scalar<E>
T
, using rng
as the source of randomness.source§impl<E: Environment> DivAssign<&Scalar<E>> for Scalar<E>
impl<E: Environment> DivAssign<&Scalar<E>> for Scalar<E>
source§fn div_assign(&mut self, other: &Scalar<E>)
fn div_assign(&mut self, other: &Scalar<E>)
Divides self
by other
.
source§impl<E: Environment> DivAssign<Scalar<E>> for Scalar<E>
impl<E: Environment> DivAssign<Scalar<E>> for Scalar<E>
source§fn div_assign(&mut self, other: Scalar<E>)
fn div_assign(&mut self, other: Scalar<E>)
Divides self
by other
.
source§impl<E: Environment> Double for Scalar<E>
impl<E: Environment> Double for Scalar<E>
source§impl<E: Environment> FromBits for Scalar<E>
impl<E: Environment> FromBits for Scalar<E>
source§fn from_bits_le(bits_le: &[bool]) -> Result<Self>
fn from_bits_le(bits_le: &[bool]) -> Result<Self>
Initializes a new scalar from a list of little-endian bits.
- If
bits_le
is longer thanE::Scalar::size_in_bits()
, the excess bits are enforced to be0
s. - If
bits_le
is shorter thanE::Scalar::size_in_bits()
, it is padded with0
s up to scalar size.
source§fn from_bits_be(bits_be: &[bool]) -> Result<Self>
fn from_bits_be(bits_be: &[bool]) -> Result<Self>
Initializes a new scalar from a list of big-endian bits without leading zeros.
source§impl<E: Environment> FromBytes for Scalar<E>
impl<E: Environment> FromBytes for Scalar<E>
source§impl<E: Environment> FromField for Scalar<E>
impl<E: Environment> FromField for Scalar<E>
source§fn from_field(field: &Self::Field) -> Result<Self>
fn from_field(field: &Self::Field) -> Result<Self>
Casts a scalar from a base field element.
This method guarantees the following:
- If the field element is larger than the scalar field modulus, then the operation will fail.
- If the field element is smaller than the scalar field modulus, then the operation will succeed.
- This is particularly useful for the case where a user called,
Scalar::from_field(scalar.to_field())
, and the scalar bit representation is betweensize_in_data_bits < bits.len() < size_in_bits
.
type Field = Field<E>
source§impl<E: Environment> FromStr for Scalar<E>
impl<E: Environment> FromStr for Scalar<E>
source§impl<E: Environment> Inverse for Scalar<E>
impl<E: Environment> Inverse for Scalar<E>
source§impl<E: Environment> MulAssign<&Scalar<E>> for Scalar<E>
impl<E: Environment> MulAssign<&Scalar<E>> for Scalar<E>
source§fn mul_assign(&mut self, other: &Scalar<E>)
fn mul_assign(&mut self, other: &Scalar<E>)
Multiplies self
by other
.
source§impl<E: Environment> MulAssign<Scalar<E>> for Scalar<E>
impl<E: Environment> MulAssign<Scalar<E>> for Scalar<E>
source§fn mul_assign(&mut self, other: Scalar<E>)
fn mul_assign(&mut self, other: Scalar<E>)
Multiplies self
by other
.
source§impl<E: Environment> Neg for Scalar<E>
impl<E: Environment> Neg for Scalar<E>
source§impl<E: Environment> One for Scalar<E>
impl<E: Environment> One for Scalar<E>
source§impl<E: Environment> Ord for Scalar<E>
impl<E: Environment> Ord for Scalar<E>
source§impl<E: Environment> Parser for Scalar<E>
impl<E: Environment> Parser for Scalar<E>
source§fn parse(string: &str) -> ParserResult<'_, Self>
fn parse(string: &str) -> ParserResult<'_, Self>
Parses a string into a scalar circuit.
source§impl<E: PartialEq + Environment> PartialEq<Scalar<E>> for Scalar<E>where
E::Scalar: PartialEq,
impl<E: PartialEq + Environment> PartialEq<Scalar<E>> for Scalar<E>where E::Scalar: PartialEq,
source§impl<E: Environment> PartialOrd<Scalar<E>> for Scalar<E>
impl<E: Environment> PartialOrd<Scalar<E>> for Scalar<E>
source§fn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
Returns the lexicographic ordering of self
and other
.
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<E: Environment> Serialize for Scalar<E>
impl<E: Environment> Serialize for Scalar<E>
source§impl<E: Environment> SizeInBits for Scalar<E>
impl<E: Environment> SizeInBits for Scalar<E>
source§fn size_in_bits() -> usize
fn size_in_bits() -> usize
Returns the scalar size in bits.
source§impl<E: Environment> SizeInBytes for Scalar<E>
impl<E: Environment> SizeInBytes for Scalar<E>
source§fn size_in_bytes() -> usize
fn size_in_bytes() -> usize
Returns the scalar size in bytes.
source§impl<E: Environment> SizeInDataBits for Scalar<E>
impl<E: Environment> SizeInDataBits for Scalar<E>
source§fn size_in_data_bits() -> usize
fn size_in_data_bits() -> usize
Returns the scalar capacity for data bits.
source§impl<E: Environment> Square for Scalar<E>
impl<E: Environment> Square for Scalar<E>
source§impl<E: Environment> SubAssign<&Scalar<E>> for Scalar<E>
impl<E: Environment> SubAssign<&Scalar<E>> for Scalar<E>
source§fn sub_assign(&mut self, other: &Scalar<E>)
fn sub_assign(&mut self, other: &Scalar<E>)
Subtracts other
from self
.
source§impl<E: Environment> SubAssign<Scalar<E>> for Scalar<E>
impl<E: Environment> SubAssign<Scalar<E>> for Scalar<E>
source§fn sub_assign(&mut self, other: Scalar<E>)
fn sub_assign(&mut self, other: Scalar<E>)
Subtracts other
from self
.
source§impl<E: Environment> Ternary for Scalar<E>
impl<E: Environment> Ternary for Scalar<E>
source§impl<E: Environment> ToBits for Scalar<E>
impl<E: Environment> ToBits for Scalar<E>
source§fn to_bits_le(&self) -> Vec<bool>
fn to_bits_le(&self) -> Vec<bool>
Outputs the little-endian bit representation of self
without trailing zeros.
source§fn to_bits_be(&self) -> Vec<bool>
fn to_bits_be(&self) -> Vec<bool>
Outputs the big-endian bit representation of self
without leading zeros.