[−][src]Struct script::Num
Script numeric
Numeric opcodes (OP_1ADD
, etc) are restricted to operating on 4-byte integers.
The semantics are subtle, though: operands must be in the range [-2^31 +1...2^31 -1],
but results may overflow (and are valid as long as they are not used in a subsequent
numeric operation). CScriptNum
enforces those semantics by storing results as
an int64 and allowing out-of-range values to be returned as a vector of bytes but
throwing an exception if arithmetic is done or the result is interpreted as an integer.
Methods
impl Num
[src]
impl Num
pub fn minimally_encode(data: &[u8], max_size: usize) -> Result<Self, Error>
[src]
pub fn minimally_encode(data: &[u8], max_size: usize) -> Result<Self, Error>
Reduce the data size to its minimal, and then try to convert it to a num.
pub fn from_slice(
data: &[u8],
require_minimal: bool,
max_size: usize
) -> Result<Self, Error>
[src]
pub fn from_slice(
data: &[u8],
require_minimal: bool,
max_size: usize
) -> Result<Self, Error>
ⓘImportant traits for Bytespub fn to_bytes(&self) -> Bytes
[src]
pub fn to_bytes(&self) -> Bytes
pub fn is_negative(&self) -> bool
[src]
pub fn is_negative(&self) -> bool
pub fn is_zero(&self) -> bool
[src]
pub fn is_zero(&self) -> bool
pub fn abs(&self) -> Num
[src]
pub fn abs(&self) -> Num
Trait Implementations
impl Debug for Num
[src]
impl Debug for Num
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl PartialEq for Num
[src]
impl PartialEq for Num
fn eq(&self, other: &Num) -> bool
[src]
fn eq(&self, other: &Num) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Num) -> bool
[src]
fn ne(&self, other: &Num) -> bool
This method tests for !=
.
impl Eq for Num
[src]
impl Eq for Num
impl PartialOrd for Num
[src]
impl PartialOrd for Num
fn partial_cmp(&self, other: &Num) -> Option<Ordering>
[src]
fn partial_cmp(&self, other: &Num) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Num) -> bool
[src]
fn lt(&self, other: &Num) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Num) -> bool
[src]
fn le(&self, other: &Num) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Num) -> bool
[src]
fn gt(&self, other: &Num) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Num) -> bool
[src]
fn ge(&self, other: &Num) -> bool
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl Ord for Num
[src]
impl Ord for Num
fn cmp(&self, other: &Num) -> Ordering
[src]
fn cmp(&self, other: &Num) -> Ordering
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.21.0[src]
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
impl Clone for Num
[src]
impl Clone for Num
fn clone(&self) -> Num
[src]
fn clone(&self) -> Num
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl Copy for Num
[src]
impl Copy for Num
impl From<bool> for Num
[src]
impl From<bool> for Num
impl From<u8> for Num
[src]
impl From<u8> for Num
impl From<u32> for Num
[src]
impl From<u32> for Num
impl From<usize> for Num
[src]
impl From<usize> for Num
impl From<i32> for Num
[src]
impl From<i32> for Num
impl From<i64> for Num
[src]
impl From<i64> for Num
impl From<Num> for i64
[src]
impl From<Num> for i64
impl From<Num> for u32
[src]
impl From<Num> for u32
impl From<Num> for usize
[src]
impl From<Num> for usize
impl BitAnd for Num
[src]
impl BitAnd for Num
type Output = Self
The resulting type after applying the &
operator.
fn bitand(self, rhs: Self) -> Self::Output
[src]
fn bitand(self, rhs: Self) -> Self::Output
Performs the &
operation.
impl Add for Num
[src]
impl Add for Num
type Output = Self
The resulting type after applying the +
operator.
fn add(self, rhs: Self) -> Self::Output
[src]
fn add(self, rhs: Self) -> Self::Output
Performs the +
operation.
impl Sub for Num
[src]
impl Sub for Num
type Output = Self
The resulting type after applying the -
operator.
fn sub(self, rhs: Self) -> Self::Output
[src]
fn sub(self, rhs: Self) -> Self::Output
Performs the -
operation.
impl Neg for Num
[src]
impl Neg for Num
type Output = Self
The resulting type after applying the -
operator.
fn neg(self) -> Self::Output
[src]
fn neg(self) -> Self::Output
Performs the unary -
operation.
impl Div for Num
[src]
impl Div for Num
type Output = Self
The resulting type after applying the /
operator.
fn div(self, rhs: Self) -> Self::Output
[src]
fn div(self, rhs: Self) -> Self::Output
Performs the /
operation.
impl Rem for Num
[src]
impl Rem for Num
Auto Trait Implementations
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
type Owned = T
fn to_owned(&self) -> T
[src]
fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
fn clone_into(&self, target: &mut T)
[src]
fn clone_into(&self, target: &mut T)
🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
try_from
)Performs the conversion.
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
ⓘImportant traits for &'a mut Rfn borrow(&self) -> &T
[src]
fn borrow(&self) -> &T
Immutably borrows from an owned value. Read more
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
try_from
)Performs the conversion.
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
ⓘImportant traits for &'a mut Rfn borrow_mut(&mut self) -> &mut T
[src]
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId
[src]
fn get_type_id(&self) -> TypeId
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Gets the TypeId
of self
. Read more