pub struct Int<const LIMBS: usize>(/* private fields */);
Expand description
Implementations§
Source§impl<const LIMBS: usize> Int<LIMBS>
impl<const LIMBS: usize> Int<LIMBS>
Sourcepub const fn checked_add(&self, rhs: &Self) -> ConstCtOption<Self>
pub const fn checked_add(&self, rhs: &Self) -> ConstCtOption<Self>
Perform checked addition. Returns none
when the addition overflowed.
Sourcepub const fn overflowing_add(&self, rhs: &Self) -> (Self, ConstChoice)
pub const fn overflowing_add(&self, rhs: &Self) -> (Self, ConstChoice)
Perform addition, raising the overflow
flag on overflow.
Sourcepub const fn wrapping_add(&self, rhs: &Self) -> Self
pub const fn wrapping_add(&self, rhs: &Self) -> Self
Perform wrapping addition, discarding overflow.
Source§impl<const LIMBS: usize> Int<LIMBS>
impl<const LIMBS: usize> Int<LIMBS>
Sourcepub const fn bitand_limb(&self, rhs: Limb) -> Self
pub const fn bitand_limb(&self, rhs: Limb) -> Self
Perform bitwise AND
between self
and the given Limb
, performing the AND
operation
on every limb of self
.
Sourcepub const fn wrapping_and(&self, rhs: &Self) -> Self
pub const fn wrapping_and(&self, rhs: &Self) -> Self
Perform wrapping bitwise AND
.
There’s no way wrapping could ever happen. This function exists so that all operations are accounted for in the wrapping operations
Sourcepub const fn checked_and(&self, rhs: &Self) -> ConstCtOption<Self>
pub const fn checked_and(&self, rhs: &Self) -> ConstCtOption<Self>
Perform checked bitwise AND
, returning a ConstCtOption
which is_some
always
Source§impl<const LIMBS: usize> Int<LIMBS>
impl<const LIMBS: usize> Int<LIMBS>
Sourcepub const fn wrapping_or(&self, rhs: &Self) -> Self
pub const fn wrapping_or(&self, rhs: &Self) -> Self
Perform wrapping bitwise OR
.
There’s no way wrapping could ever happen. This function exists so that all operations are accounted for in the wrapping operations
Sourcepub const fn checked_or(&self, rhs: &Self) -> ConstCtOption<Self>
pub const fn checked_or(&self, rhs: &Self) -> ConstCtOption<Self>
Perform checked bitwise OR
, returning a ConstCtOption
which is_some
always
Source§impl<const LIMBS: usize> Int<LIMBS>
impl<const LIMBS: usize> Int<LIMBS>
Sourcepub const fn wrapping_xor(&self, rhs: &Self) -> Self
pub const fn wrapping_xor(&self, rhs: &Self) -> Self
Perform wrapping bitwise XOR
.
There’s no way wrapping could ever happen. This function exists so that all operations are accounted for in the wrapping operations
Sourcepub fn checked_xor(&self, rhs: &Self) -> ConstCtOption<Self>
pub fn checked_xor(&self, rhs: &Self) -> ConstCtOption<Self>
Perform checked bitwise XOR
, returning a ConstCtOption
which is_some
always
Source§impl<const LIMBS: usize> Int<LIMBS>
impl<const LIMBS: usize> Int<LIMBS>
Sourcepub const fn cmp_vartime(&self, rhs: &Self) -> Ordering
pub const fn cmp_vartime(&self, rhs: &Self) -> Ordering
Returns the Ordering between self
and rhs
in variable time.
Source§impl<const LIMBS: usize> Int<LIMBS>
Checked division operations.
impl<const LIMBS: usize> Int<LIMBS>
Checked division operations.
Sourcepub const fn checked_div_rem(
&self,
rhs: &NonZero<Self>,
) -> (ConstCtOption<Self>, Self)
pub const fn checked_div_rem( &self, rhs: &NonZero<Self>, ) -> (ConstCtOption<Self>, Self)
Compute the quotient and remainder of self / rhs
.
Returns none
for the quotient when Int::MIN / Int::MINUS_ONE
; that quotient cannot
be captured in an Int
.
Example:
use crypto_bigint::{I128, NonZero};
let (quotient, remainder) = I128::from(8).checked_div_rem(&I128::from(3).to_nz().unwrap());
assert_eq!(quotient.unwrap(), I128::from(2));
assert_eq!(remainder, I128::from(2));
let (quotient, remainder) = I128::from(-8).checked_div_rem(&I128::from(3).to_nz().unwrap());
assert_eq!(quotient.unwrap(), I128::from(-2));
assert_eq!(remainder, I128::from(-2));
let (quotient, remainder) = I128::from(8).checked_div_rem(&I128::from(-3).to_nz().unwrap());
assert_eq!(quotient.unwrap(), I128::from(-2));
assert_eq!(remainder, I128::from(2));
let (quotient, remainder) = I128::from(-8).checked_div_rem(&I128::from(-3).to_nz().unwrap());
assert_eq!(quotient.unwrap(), I128::from(2));
assert_eq!(remainder, I128::from(-2));
Sourcepub fn checked_div(&self, rhs: &Self) -> CtOption<Self>
pub fn checked_div(&self, rhs: &Self) -> CtOption<Self>
Perform checked division, returning a CtOption
which is_some
if
- the
rhs != 0
, and self != MIN
orrhs != MINUS_ONE
.
Note: this operation rounds towards zero, truncating any fractional part of the exact result.
Source§impl<const LIMBS: usize> Int<LIMBS>
Vartime checked division operations.
impl<const LIMBS: usize> Int<LIMBS>
Vartime checked division operations.
Sourcepub const fn checked_div_rem_vartime<const RHS_LIMBS: usize>(
&self,
rhs: &NonZero<Int<RHS_LIMBS>>,
) -> (ConstCtOption<Self>, Int<RHS_LIMBS>)
pub const fn checked_div_rem_vartime<const RHS_LIMBS: usize>( &self, rhs: &NonZero<Int<RHS_LIMBS>>, ) -> (ConstCtOption<Self>, Int<RHS_LIMBS>)
Variable time equivalent of Self::checked_div_rem
This is variable only with respect to rhs
.
When used with a fixed rhs
, this function is constant-time with respect
to self
.
Sourcepub fn checked_div_vartime<const RHS_LIMBS: usize>(
&self,
rhs: &Int<RHS_LIMBS>,
) -> CtOption<Self>
pub fn checked_div_vartime<const RHS_LIMBS: usize>( &self, rhs: &Int<RHS_LIMBS>, ) -> CtOption<Self>
Variable time equivalent of Self::checked_div
This is variable only with respect to rhs
.
When used with a fixed rhs
, this function is constant-time with respect
to self
.
Source§impl<const LIMBS: usize> Int<LIMBS>
Vartime checked div-floor operations.
impl<const LIMBS: usize> Int<LIMBS>
Vartime checked div-floor operations.
Sourcepub const fn checked_div_rem_floor_vartime<const RHS_LIMBS: usize>(
&self,
rhs: &NonZero<Int<RHS_LIMBS>>,
) -> (ConstCtOption<Self>, Int<RHS_LIMBS>)
pub const fn checked_div_rem_floor_vartime<const RHS_LIMBS: usize>( &self, rhs: &NonZero<Int<RHS_LIMBS>>, ) -> (ConstCtOption<Self>, Int<RHS_LIMBS>)
Variable time equivalent of Self::checked_div_rem_floor
This is variable only with respect to rhs
.
When used with a fixed rhs
, this function is constant-time with respect
to self
.
Sourcepub fn checked_div_floor_vartime<const RHS_LIMBS: usize>(
&self,
rhs: &Int<RHS_LIMBS>,
) -> CtOption<Self>
pub fn checked_div_floor_vartime<const RHS_LIMBS: usize>( &self, rhs: &Int<RHS_LIMBS>, ) -> CtOption<Self>
Variable time equivalent of Self::checked_div_floor
This is variable only with respect to rhs
.
When used with a fixed rhs
, this function is constant-time with respect
to self
.
Source§impl<const LIMBS: usize> Int<LIMBS>
Checked div-floor operations.
impl<const LIMBS: usize> Int<LIMBS>
Checked div-floor operations.
Sourcepub fn checked_div_floor(&self, rhs: &Self) -> CtOption<Self>
pub fn checked_div_floor(&self, rhs: &Self) -> CtOption<Self>
Perform checked floored division, returning a ConstCtOption
which is_some
only if
- the
rhs != 0
, and self != MIN
orrhs != MINUS_ONE
.
Note: this operation rounds down.
Example:
use crypto_bigint::I128;
assert_eq!(
I128::from(8).checked_div_floor(&I128::from(3)).unwrap(),
I128::from(2)
);
assert_eq!(
I128::from(-8).checked_div_floor(&I128::from(3)).unwrap(),
I128::from(-3)
);
assert_eq!(
I128::from(8).checked_div_floor(&I128::from(-3)).unwrap(),
I128::from(-3)
);
assert_eq!(
I128::from(-8).checked_div_floor(&I128::from(-3)).unwrap(),
I128::from(2)
)
Sourcepub const fn checked_div_rem_floor(
&self,
rhs: &NonZero<Self>,
) -> (ConstCtOption<Self>, Self)
pub const fn checked_div_rem_floor( &self, rhs: &NonZero<Self>, ) -> (ConstCtOption<Self>, Self)
Perform checked division and mod, returning the quotient and remainder.
The quotient is a ConstCtOption
which is_some
only if
- the
rhs != 0
, and self != MIN
orrhs != MINUS_ONE
.
Note: this operation rounds down.
Example:
use crypto_bigint::I128;
let three = I128::from(3).to_nz().unwrap();
let (quotient, remainder) = I128::from(8).checked_div_rem_floor(&three);
assert_eq!(quotient.unwrap(), I128::from(2));
assert_eq!(remainder, I128::from(2));
let (quotient, remainder) = I128::from(-8).checked_div_rem_floor(&three);
assert_eq!(quotient.unwrap(), I128::from(-3));
assert_eq!(remainder, I128::from(-1));
let minus_three = I128::from(-3).to_nz().unwrap();
let (quotient, remainder) = I128::from(8).checked_div_rem_floor(&minus_three);
assert_eq!(quotient.unwrap(), I128::from(-3));
assert_eq!(remainder, I128::from(-1));
let (quotient, remainder) = I128::from(-8).checked_div_rem_floor(&minus_three);
assert_eq!(quotient.unwrap(), I128::from(2));
assert_eq!(remainder, I128::from(2));
Source§impl<const LIMBS: usize> Int<LIMBS>
Checked division operations.
impl<const LIMBS: usize> Int<LIMBS>
Checked division operations.
Sourcepub const fn div_rem_uint(&self, rhs: &NonZero<Uint<LIMBS>>) -> (Self, Self)
pub const fn div_rem_uint(&self, rhs: &NonZero<Uint<LIMBS>>) -> (Self, Self)
Compute the quotient and remainder of self / rhs
.
Example:
use crypto_bigint::{I128, NonZero, U128};
let (quotient, remainder) = I128::from(8).div_rem_uint(&U128::from(3u32).to_nz().unwrap());
assert_eq!(quotient, I128::from(2));
assert_eq!(remainder, I128::from(2));
let (quotient, remainder) = I128::from(-8).div_rem_uint(&U128::from(3u32).to_nz().unwrap());
assert_eq!(quotient, I128::from(-2));
assert_eq!(remainder, I128::from(-2));
Source§impl<const LIMBS: usize> Int<LIMBS>
Vartime checked division operations.
impl<const LIMBS: usize> Int<LIMBS>
Vartime checked division operations.
Sourcepub const fn div_rem_uint_vartime<const RHS_LIMBS: usize>(
&self,
rhs: &NonZero<Uint<RHS_LIMBS>>,
) -> (Self, Int<RHS_LIMBS>)
pub const fn div_rem_uint_vartime<const RHS_LIMBS: usize>( &self, rhs: &NonZero<Uint<RHS_LIMBS>>, ) -> (Self, Int<RHS_LIMBS>)
Variable time equivalent of Self::div_rem_uint`.
This is variable only with respect to rhs
.
When used with a fixed rhs
, this function is constant-time with respect
to self
.
Sourcepub const fn div_uint_vartime<const RHS_LIMBS: usize>(
&self,
rhs: &NonZero<Uint<RHS_LIMBS>>,
) -> Self
pub const fn div_uint_vartime<const RHS_LIMBS: usize>( &self, rhs: &NonZero<Uint<RHS_LIMBS>>, ) -> Self
Variable time equivalent of Self::div_uint`.
This is variable only with respect to rhs
.
When used with a fixed rhs
, this function is constant-time with respect
to self
.
Sourcepub const fn rem_uint_vartime<const RHS_LIMBS: usize>(
&self,
rhs: &NonZero<Uint<RHS_LIMBS>>,
) -> Int<RHS_LIMBS>
pub const fn rem_uint_vartime<const RHS_LIMBS: usize>( &self, rhs: &NonZero<Uint<RHS_LIMBS>>, ) -> Int<RHS_LIMBS>
Variable time equivalent of Self::rem_uint`.
This is variable only with respect to rhs
.
When used with a fixed rhs
, this function is constant-time with respect
to self
.
Source§impl<const LIMBS: usize> Int<LIMBS>
Checked div-floor operations
impl<const LIMBS: usize> Int<LIMBS>
Checked div-floor operations
Sourcepub fn div_rem_floor_uint(
&self,
rhs: &NonZero<Uint<LIMBS>>,
) -> (Self, Uint<LIMBS>)
pub fn div_rem_floor_uint( &self, rhs: &NonZero<Uint<LIMBS>>, ) -> (Self, Uint<LIMBS>)
Perform floored division and mod:
given n
and d
, computes q
and r
s.t. n = qd + r
and q = ⌊n/d⌋
.
Note: this operation rounds down, not towards zero.
Example:
use crypto_bigint::{I128, U128};
let three = U128::from(3u32).to_nz().unwrap();
assert_eq!(
I128::from(8).div_rem_floor_uint(&three),
(I128::from(2), U128::from(2u32))
);
assert_eq!(
I128::from(-8).div_rem_floor_uint(&three),
(I128::from(-3), U128::ONE)
);
Sourcepub fn div_floor_uint(&self, rhs: &NonZero<Uint<LIMBS>>) -> Self
pub fn div_floor_uint(&self, rhs: &NonZero<Uint<LIMBS>>) -> Self
Perform checked division. Note: this operation rounds down.
Example:
use crypto_bigint::{I128, U128};
assert_eq!(
I128::from(8).div_floor_uint(&U128::from(3u32).to_nz().unwrap()),
I128::from(2)
);
assert_eq!(
I128::from(-8).div_floor_uint(&U128::from(3u32).to_nz().unwrap()),
I128::from(-3)
);
Sourcepub fn normalized_rem(&self, rhs: &NonZero<Uint<LIMBS>>) -> Uint<LIMBS>
pub fn normalized_rem(&self, rhs: &NonZero<Uint<LIMBS>>) -> Uint<LIMBS>
Compute self % rhs
and return the result contained in the interval [0, rhs)
.
Example:
use crypto_bigint::{I128, U128};
assert_eq!(
I128::from(8).normalized_rem(&U128::from(3u32).to_nz().unwrap()),
U128::from(2u32)
);
assert_eq!(
I128::from(-8).normalized_rem(&U128::from(3u32).to_nz().unwrap()),
U128::ONE
);
Source§impl<const LIMBS: usize> Int<LIMBS>
Vartime checked div-floor operations
impl<const LIMBS: usize> Int<LIMBS>
Vartime checked div-floor operations
Sourcepub fn div_rem_floor_uint_vartime<const RHS_LIMBS: usize>(
&self,
rhs: &NonZero<Uint<RHS_LIMBS>>,
) -> (Self, Uint<RHS_LIMBS>)
pub fn div_rem_floor_uint_vartime<const RHS_LIMBS: usize>( &self, rhs: &NonZero<Uint<RHS_LIMBS>>, ) -> (Self, Uint<RHS_LIMBS>)
Variable time equivalent of Self::div_rem_floor_uint`.
This is variable only with respect to rhs
.
When used with a fixed rhs
, this function is constant-time with respect
to self
.
Sourcepub fn div_floor_uint_vartime<const RHS_LIMBS: usize>(
&self,
rhs: &NonZero<Uint<RHS_LIMBS>>,
) -> Self
pub fn div_floor_uint_vartime<const RHS_LIMBS: usize>( &self, rhs: &NonZero<Uint<RHS_LIMBS>>, ) -> Self
Variable time equivalent of Self::div_floor_uint`.
This is variable only with respect to rhs
.
When used with a fixed rhs
, this function is constant-time with respect
to self
.
Sourcepub fn normalized_rem_vartime<const RHS_LIMBS: usize>(
&self,
rhs: &NonZero<Uint<RHS_LIMBS>>,
) -> Uint<RHS_LIMBS>
pub fn normalized_rem_vartime<const RHS_LIMBS: usize>( &self, rhs: &NonZero<Uint<RHS_LIMBS>>, ) -> Uint<RHS_LIMBS>
Variable time equivalent of Self::normalized_rem`.
This is variable only with respect to rhs
.
When used with a fixed rhs
, this function is constant-time with respect
to self
.
Source§impl<const LIMBS: usize> Int<LIMBS>
impl<const LIMBS: usize> Int<LIMBS>
Sourcepub const fn from_be_hex(hex: &str) -> Self
pub const fn from_be_hex(hex: &str) -> Self
Create a new Int
from the provided big endian hex string.
Panics if the hex is malformed or not zero-padded accordingly for the size.
See Uint::from_be_hex
for more details.
Source§impl<const LIMBS: usize> Int<LIMBS>
impl<const LIMBS: usize> Int<LIMBS>
Source§impl<const LIMBS: usize> Int<LIMBS>
impl<const LIMBS: usize> Int<LIMBS>
Sourcepub const fn split_mul<const RHS_LIMBS: usize>(
&self,
rhs: &Int<RHS_LIMBS>,
) -> (Uint<LIMBS>, Uint<RHS_LIMBS>, ConstChoice)
pub const fn split_mul<const RHS_LIMBS: usize>( &self, rhs: &Int<RHS_LIMBS>, ) -> (Uint<LIMBS>, Uint<RHS_LIMBS>, ConstChoice)
Compute “wide” multiplication as a 3-tuple (lo, hi, negate)
.
The (lo, hi)
components contain the magnitude of the product, with sizes
corresponding to the sizes of the operands; negate
indicates whether the result should be
negated when converted from Uint
to Int
.
Note: even if negate
is truthy, the magnitude might be zero!
Source§impl<const LIMBS: usize> Int<LIMBS>
Squaring operations.
impl<const LIMBS: usize> Int<LIMBS>
Squaring operations.
Sourcepub fn widening_square<const WIDE_LIMBS: usize>(&self) -> Uint<WIDE_LIMBS>
pub fn widening_square<const WIDE_LIMBS: usize>(&self) -> Uint<WIDE_LIMBS>
Square self, returning a concatenated “wide” result.
Sourcepub fn checked_square(&self) -> ConstCtOption<Uint<LIMBS>>
pub fn checked_square(&self) -> ConstCtOption<Uint<LIMBS>>
Square self, checking that the result fits in the original Uint
size.
Sourcepub const fn wrapping_square(&self) -> Uint<LIMBS>
pub const fn wrapping_square(&self) -> Uint<LIMBS>
Perform wrapping square, discarding overflow.
Sourcepub const fn saturating_square(&self) -> Uint<LIMBS>
pub const fn saturating_square(&self) -> Uint<LIMBS>
Perform saturating squaring, returning MAX
on overflow.
Source§impl<const LIMBS: usize> Int<LIMBS>
impl<const LIMBS: usize> Int<LIMBS>
Sourcepub const fn split_mul_uint<const RHS_LIMBS: usize>(
&self,
rhs: &Uint<RHS_LIMBS>,
) -> (Uint<LIMBS>, Uint<RHS_LIMBS>, ConstChoice)
pub const fn split_mul_uint<const RHS_LIMBS: usize>( &self, rhs: &Uint<RHS_LIMBS>, ) -> (Uint<LIMBS>, Uint<RHS_LIMBS>, ConstChoice)
Compute “wide” multiplication between an Int
and Uint
as 3-tuple (lo, hi, negate)
.
The (lo, hi)
components contain the magnitude of the product, with sizes
corresponding to the sizes of the operands; negate
indicates whether the result should be
negated when converted from Uint
to Int
.
Note: even if negate
is truthy, the magnitude might be zero!
Sourcepub const fn split_mul_uint_right<const RHS_LIMBS: usize>(
&self,
rhs: &Uint<RHS_LIMBS>,
) -> (Uint<RHS_LIMBS>, Uint<LIMBS>, ConstChoice)
pub const fn split_mul_uint_right<const RHS_LIMBS: usize>( &self, rhs: &Uint<RHS_LIMBS>, ) -> (Uint<RHS_LIMBS>, Uint<LIMBS>, ConstChoice)
Compute “wide” multiplication between an Int
and Uint
as 3-tuple (lo, hi, negate)
.
The (lo, hi)
components contain the magnitude of the product, with sizes
corresponding to the sizes of the operands, in reversed order; negate
indicates whether
the result should be negated when converted from Uint
to Int
.
Note: even if negate
is truthy, the magnitude might be zero!
Source§impl<const LIMBS: usize> Int<LIMBS>
impl<const LIMBS: usize> Int<LIMBS>
Sourcepub const fn overflowing_neg(&self) -> (Self, ConstChoice)
pub const fn overflowing_neg(&self) -> (Self, ConstChoice)
Sourcepub const fn wrapping_neg(&self) -> Self
pub const fn wrapping_neg(&self) -> Self
Sourcepub const fn wrapping_neg_if(&self, negate: ConstChoice) -> Int<LIMBS>
pub const fn wrapping_neg_if(&self, negate: ConstChoice) -> Int<LIMBS>
Sourcepub const fn checked_neg(&self) -> ConstCtOption<Self>
pub const fn checked_neg(&self) -> ConstCtOption<Self>
Negate this Int
.
Yields None
when self == Self::MIN
, since the positive counterpart of this value cannot
be represented.
Source§impl<const LIMBS: usize> Int<LIMBS>
impl<const LIMBS: usize> Int<LIMBS>
Sourcepub const fn shl(&self, shift: u32) -> Self
pub const fn shl(&self, shift: u32) -> Self
Computes self << shift
.
Panics if shift >= Self::BITS
.
Sourcepub const fn shl_vartime(&self, shift: u32) -> Self
pub const fn shl_vartime(&self, shift: u32) -> Self
Computes self << shift
in variable time.
Panics if shift >= Self::BITS
.
Sourcepub const fn overflowing_shl(&self, shift: u32) -> ConstCtOption<Self>
pub const fn overflowing_shl(&self, shift: u32) -> ConstCtOption<Self>
Computes self << shift
.
Returns None
if shift >= Self::BITS
.
Sourcepub const fn overflowing_shl_vartime(&self, shift: u32) -> ConstCtOption<Self>
pub const fn overflowing_shl_vartime(&self, shift: u32) -> ConstCtOption<Self>
Computes self << shift
.
Returns None
if shift >= Self::BITS
.
NOTE: this operation is variable time with respect to shift
ONLY.
When used with a fixed shift
, this function is constant-time with respect
to self
.
Sourcepub const fn wrapping_shl(&self, shift: u32) -> Self
pub const fn wrapping_shl(&self, shift: u32) -> Self
Computes self << shift
in a panic-free manner, returning zero if the shift exceeds the
precision.
Sourcepub const fn wrapping_shl_vartime(&self, shift: u32) -> Self
pub const fn wrapping_shl_vartime(&self, shift: u32) -> Self
Computes self << shift
in variable-time in a panic-free manner, returning zero if the
shift exceeds the precision.
Source§impl<const LIMBS: usize> Int<LIMBS>
impl<const LIMBS: usize> Int<LIMBS>
Sourcepub const fn shr(&self, shift: u32) -> Self
pub const fn shr(&self, shift: u32) -> Self
Computes self >> shift
.
Note, this is signed shift right, i.e., the value shifted in on the left is equal to the most significant bit.
Panics if shift >= Self::BITS
.
Sourcepub const fn shr_vartime(&self, shift: u32) -> Self
pub const fn shr_vartime(&self, shift: u32) -> Self
Computes self >> shift
in variable time.
Note, this is signed shift right, i.e., the value shifted in on the left is equal to the most significant bit.
Panics if shift >= Self::BITS
.
Sourcepub const fn overflowing_shr(&self, shift: u32) -> ConstCtOption<Self>
pub const fn overflowing_shr(&self, shift: u32) -> ConstCtOption<Self>
Computes self >> shift
.
Note, this is signed shift right, i.e., the value shifted in on the left is equal to the most significant bit.
Returns None
if shift >= Self::BITS
.
Sourcepub const fn overflowing_shr_vartime(&self, shift: u32) -> ConstCtOption<Self>
pub const fn overflowing_shr_vartime(&self, shift: u32) -> ConstCtOption<Self>
Computes self >> shift
.
NOTE: this is signed shift right, i.e., the value shifted in on the left is equal to the most significant bit.
Returns None
if shift >= Self::BITS
.
NOTE: this operation is variable time with respect to shift
ONLY.
When used with a fixed shift
, this function is constant-time with respect
to self
.
Sourcepub const fn wrapping_shr(&self, shift: u32) -> Self
pub const fn wrapping_shr(&self, shift: u32) -> Self
Computes self >> shift
in a panic-free manner.
If the shift exceeds the precision, returns
0
whenself
is non-negative, and-1
whenself
is negative.
Sourcepub const fn wrapping_shr_vartime(&self, shift: u32) -> Self
pub const fn wrapping_shr_vartime(&self, shift: u32) -> Self
Computes self >> shift
in variable-time in a panic-free manner.
If the shift exceeds the precision, returns
0
whenself
is non-negative, and-1
whenself
is negative.
Source§impl<const LIMBS: usize> Int<LIMBS>
impl<const LIMBS: usize> Int<LIMBS>
Sourcepub const fn new_from_abs_sign(
abs: Uint<LIMBS>,
is_negative: ConstChoice,
) -> ConstCtOption<Self>
pub const fn new_from_abs_sign( abs: Uint<LIMBS>, is_negative: ConstChoice, ) -> ConstCtOption<Self>
Construct new Int
from an absolute value and sign.
Returns None
when the absolute value does not fit in an Int<LIMBS>
.
Sourcepub const fn is_negative(&self) -> ConstChoice
pub const fn is_negative(&self) -> ConstChoice
Whether this Int
is negative, as a ConstChoice
.
Sourcepub const fn is_positive(&self) -> ConstChoice
pub const fn is_positive(&self) -> ConstChoice
Whether this Int
is positive, as a ConstChoice
.
Sourcepub const fn abs_sign(&self) -> (Uint<LIMBS>, ConstChoice)
pub const fn abs_sign(&self) -> (Uint<LIMBS>, ConstChoice)
The sign and magnitude of this Int
.
Source§impl<const LIMBS: usize> Int<LIMBS>
impl<const LIMBS: usize> Int<LIMBS>
Sourcepub const fn from_words(arr: [Word; LIMBS]) -> Self
pub const fn from_words(arr: [Word; LIMBS]) -> Self
Sourcepub fn as_words_mut(&mut self) -> &mut [Word; LIMBS]
pub fn as_words_mut(&mut self) -> &mut [Word; LIMBS]
Borrow the inner limbs as a mutable array of Word
s.
Sourcepub const fn as_limbs_mut(&mut self) -> &mut [Limb; LIMBS]
pub const fn as_limbs_mut(&mut self) -> &mut [Limb; LIMBS]
Borrow the limbs of this Int
mutably.
Sourcepub const fn to_nz(self) -> ConstCtOption<NonZero<Self>>
pub const fn to_nz(self) -> ConstCtOption<NonZero<Self>>
Convert to a NonZero<Int<LIMBS>>
.
Returns some if the original value is non-zero, and false otherwise.
Sourcepub const fn to_odd(self) -> ConstCtOption<Odd<Self>>
pub const fn to_odd(self) -> ConstCtOption<Odd<Self>>
Convert to a Odd<Int<LIMBS>>
.
Returns some if the original value is odd, and false otherwise.
Sourcepub const fn is_min(&self) -> ConstChoice
pub const fn is_min(&self) -> ConstChoice
Whether this Int
is equal to Self::MIN
.
Sourcepub fn is_max(&self) -> ConstChoice
pub fn is_max(&self) -> ConstChoice
Whether this Int
is equal to Self::MAX
.
Trait Implementations§
Source§impl<const LIMBS: usize> AddAssign<&Int<LIMBS>> for Int<LIMBS>
impl<const LIMBS: usize> AddAssign<&Int<LIMBS>> for Int<LIMBS>
Source§fn add_assign(&mut self, other: &Self)
fn add_assign(&mut self, other: &Self)
+=
operation. Read moreSource§impl<const LIMBS: usize> AddAssign for Int<LIMBS>
impl<const LIMBS: usize> AddAssign for Int<LIMBS>
Source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
+=
operation. Read moreSource§impl<const LIMBS: usize> BitAndAssign<&Int<LIMBS>> for Int<LIMBS>
impl<const LIMBS: usize> BitAndAssign<&Int<LIMBS>> for Int<LIMBS>
Source§fn bitand_assign(&mut self, other: &Self)
fn bitand_assign(&mut self, other: &Self)
&=
operation. Read moreSource§impl<const LIMBS: usize> BitAndAssign for Int<LIMBS>
impl<const LIMBS: usize> BitAndAssign for Int<LIMBS>
Source§fn bitand_assign(&mut self, other: Self)
fn bitand_assign(&mut self, other: Self)
&=
operation. Read moreSource§impl<const LIMBS: usize> BitOrAssign<&Int<LIMBS>> for Int<LIMBS>
impl<const LIMBS: usize> BitOrAssign<&Int<LIMBS>> for Int<LIMBS>
Source§fn bitor_assign(&mut self, other: &Self)
fn bitor_assign(&mut self, other: &Self)
|=
operation. Read moreSource§impl<const LIMBS: usize> BitOrAssign for Int<LIMBS>
impl<const LIMBS: usize> BitOrAssign for Int<LIMBS>
Source§fn bitor_assign(&mut self, other: Self)
fn bitor_assign(&mut self, other: Self)
|=
operation. Read moreSource§impl<const LIMBS: usize> BitXorAssign<&Int<LIMBS>> for Int<LIMBS>
impl<const LIMBS: usize> BitXorAssign<&Int<LIMBS>> for Int<LIMBS>
Source§fn bitxor_assign(&mut self, other: &Self)
fn bitxor_assign(&mut self, other: &Self)
^=
operation. Read moreSource§impl<const LIMBS: usize> BitXorAssign for Int<LIMBS>
impl<const LIMBS: usize> BitXorAssign for Int<LIMBS>
Source§fn bitxor_assign(&mut self, other: Self)
fn bitxor_assign(&mut self, other: Self)
^=
operation. Read moreSource§impl<const LIMBS: usize> CheckedAdd for Int<LIMBS>
impl<const LIMBS: usize> CheckedAdd for Int<LIMBS>
Source§fn checked_add(&self, rhs: &Self) -> CtOption<Self>
fn checked_add(&self, rhs: &Self) -> CtOption<Self>
CtOption
which is_some
only if the operation
did not overflow.Source§impl<const LIMBS: usize> CheckedDiv for Int<LIMBS>
impl<const LIMBS: usize> CheckedDiv for Int<LIMBS>
Source§impl<const LIMBS: usize> CheckedSub for Int<LIMBS>
impl<const LIMBS: usize> CheckedSub for Int<LIMBS>
Source§fn checked_sub(&self, rhs: &Self) -> CtOption<Self>
fn checked_sub(&self, rhs: &Self) -> CtOption<Self>
CtOption
which is_some
only if the operation did not underflow.Source§impl<const LIMBS: usize> ConditionallySelectable for Int<LIMBS>
impl<const LIMBS: usize> ConditionallySelectable for Int<LIMBS>
Source§fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self
Source§fn conditional_assign(&mut self, other: &Self, choice: Choice)
fn conditional_assign(&mut self, other: &Self, choice: Choice)
Source§fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)
fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)
self
and other
if choice == 1
; otherwise,
reassign both unto themselves. Read moreSource§impl<const LIMBS: usize> ConstantTimeEq for Int<LIMBS>
impl<const LIMBS: usize> ConstantTimeEq for Int<LIMBS>
Source§impl<const LIMBS: usize> ConstantTimeGreater for Int<LIMBS>
impl<const LIMBS: usize> ConstantTimeGreater for Int<LIMBS>
Source§impl<const LIMBS: usize> ConstantTimeLess for Int<LIMBS>
impl<const LIMBS: usize> ConstantTimeLess for Int<LIMBS>
Source§impl<'de, const LIMBS: usize> Deserialize<'de> for Int<LIMBS>
Available on crate feature serde
only.
impl<'de, const LIMBS: usize> Deserialize<'de> for Int<LIMBS>
serde
only.Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<const SAT_LIMBS: usize, const UNSAT_LIMBS: usize> Gcd<Int<SAT_LIMBS>> for Uint<SAT_LIMBS>
impl<const SAT_LIMBS: usize, const UNSAT_LIMBS: usize> Gcd<Int<SAT_LIMBS>> for Uint<SAT_LIMBS>
Source§impl<const SAT_LIMBS: usize, const UNSAT_LIMBS: usize> Gcd<Uint<SAT_LIMBS>> for Int<SAT_LIMBS>
impl<const SAT_LIMBS: usize, const UNSAT_LIMBS: usize> Gcd<Uint<SAT_LIMBS>> for Int<SAT_LIMBS>
Source§impl<const LIMBS: usize> Ord for Int<LIMBS>
impl<const LIMBS: usize> Ord for Int<LIMBS>
Source§impl<const LIMBS: usize> PartialOrd for Int<LIMBS>
impl<const LIMBS: usize> PartialOrd for Int<LIMBS>
Source§impl<const LIMBS: usize> RandomBits for Int<LIMBS>
Available on crate feature rand_core
only.
impl<const LIMBS: usize> RandomBits for Int<LIMBS>
rand_core
only.Source§fn try_random_bits(
rng: &mut (impl RngCore + ?Sized),
bit_length: u32,
) -> Result<Self, RandomBitsError>
fn try_random_bits( rng: &mut (impl RngCore + ?Sized), bit_length: u32, ) -> Result<Self, RandomBitsError>
[0, 2^bit_length)
. Read moreSource§fn try_random_bits_with_precision(
rng: &mut (impl RngCore + ?Sized),
bit_length: u32,
bits_precision: u32,
) -> Result<Self, RandomBitsError>
fn try_random_bits_with_precision( rng: &mut (impl RngCore + ?Sized), bit_length: u32, bits_precision: u32, ) -> Result<Self, RandomBitsError>
[0, 2^bit_length)
,
returning an integer with the closest available size to bits_precision
(if the implementing type supports runtime sizing). Read moreSource§fn random_bits(rng: &mut (impl RngCore + ?Sized), bit_length: u32) -> Self
fn random_bits(rng: &mut (impl RngCore + ?Sized), bit_length: u32) -> Self
[0, 2^bit_length)
. Read moreSource§fn random_bits_with_precision(
rng: &mut (impl RngCore + ?Sized),
bit_length: u32,
bits_precision: u32,
) -> Self
fn random_bits_with_precision( rng: &mut (impl RngCore + ?Sized), bit_length: u32, bits_precision: u32, ) -> Self
[0, 2^bit_length)
,
returning an integer with the closest available size to bits_precision
(if the implementing type supports runtime sizing). Read moreSource§impl<const LIMBS: usize> ShlAssign<i32> for Int<LIMBS>
impl<const LIMBS: usize> ShlAssign<i32> for Int<LIMBS>
Source§fn shl_assign(&mut self, shift: i32)
fn shl_assign(&mut self, shift: i32)
<<=
operation. Read moreSource§impl<const LIMBS: usize> ShlAssign<u32> for Int<LIMBS>
impl<const LIMBS: usize> ShlAssign<u32> for Int<LIMBS>
Source§fn shl_assign(&mut self, shift: u32)
fn shl_assign(&mut self, shift: u32)
<<=
operation. Read moreSource§impl<const LIMBS: usize> ShlAssign<usize> for Int<LIMBS>
impl<const LIMBS: usize> ShlAssign<usize> for Int<LIMBS>
Source§fn shl_assign(&mut self, shift: usize)
fn shl_assign(&mut self, shift: usize)
<<=
operation. Read moreSource§impl<const LIMBS: usize> ShlVartime for Int<LIMBS>
impl<const LIMBS: usize> ShlVartime for Int<LIMBS>
Source§fn overflowing_shl_vartime(&self, shift: u32) -> CtOption<Self>
fn overflowing_shl_vartime(&self, shift: u32) -> CtOption<Self>
self << shift
. Read moreSource§fn wrapping_shl_vartime(&self, shift: u32) -> Self
fn wrapping_shl_vartime(&self, shift: u32) -> Self
self << shift
in a panic-free manner, masking off bits of shift
which would cause the shift to exceed the type’s width.Source§impl<const LIMBS: usize> ShrAssign<i32> for Int<LIMBS>
impl<const LIMBS: usize> ShrAssign<i32> for Int<LIMBS>
Source§fn shr_assign(&mut self, shift: i32)
fn shr_assign(&mut self, shift: i32)
>>=
operation. Read moreSource§impl<const LIMBS: usize> ShrAssign<u32> for Int<LIMBS>
impl<const LIMBS: usize> ShrAssign<u32> for Int<LIMBS>
Source§fn shr_assign(&mut self, shift: u32)
fn shr_assign(&mut self, shift: u32)
>>=
operation. Read moreSource§impl<const LIMBS: usize> ShrAssign<usize> for Int<LIMBS>
impl<const LIMBS: usize> ShrAssign<usize> for Int<LIMBS>
Source§fn shr_assign(&mut self, shift: usize)
fn shr_assign(&mut self, shift: usize)
>>=
operation. Read moreSource§impl<const LIMBS: usize> ShrVartime for Int<LIMBS>
impl<const LIMBS: usize> ShrVartime for Int<LIMBS>
Source§fn overflowing_shr_vartime(&self, shift: u32) -> CtOption<Self>
fn overflowing_shr_vartime(&self, shift: u32) -> CtOption<Self>
self >> shift
. Read moreSource§fn wrapping_shr_vartime(&self, shift: u32) -> Self
fn wrapping_shr_vartime(&self, shift: u32) -> Self
self >> shift
in a panic-free manner, masking off bits of shift
which would cause the shift to exceed the type’s width.Source§impl<const LIMBS: usize> WrappingAdd for Int<LIMBS>
impl<const LIMBS: usize> WrappingAdd for Int<LIMBS>
Source§fn wrapping_add(&self, v: &Self) -> Self
fn wrapping_add(&self, v: &Self) -> Self
self + other
, wrapping around at the boundary of
the type.Source§impl<const LIMBS: usize> WrappingShl for Int<LIMBS>
impl<const LIMBS: usize> WrappingShl for Int<LIMBS>
Source§impl<const LIMBS: usize> WrappingShr for Int<LIMBS>
impl<const LIMBS: usize> WrappingShr for Int<LIMBS>
Source§impl<const LIMBS: usize> WrappingSub for Int<LIMBS>
impl<const LIMBS: usize> WrappingSub for Int<LIMBS>
Source§fn wrapping_sub(&self, v: &Self) -> Self
fn wrapping_sub(&self, v: &Self) -> Self
self - other
, wrapping around at the boundary
of the type.