Struct malachite_nz::natural::Natural
source · pub struct Natural(/* private fields */);
Expand description
A natural (non-negative) integer.
Any Natural
small enough to fit into a Limb
is represented inline. Only
Natural
s outside this range incur the costs of heap-allocation. Here’s a diagram of a slice of
Natural
s (using 32-bit limbs) containing the first 8 values of Sylvester’s
sequence:
Implementations§
source§impl Natural
impl Natural
sourcepub fn approx_log(&self) -> f64
pub fn approx_log(&self) -> f64
Calculates the approximate natural logarithm of a nonzero Natural
.
$f(x) = (1+\epsilon)(\log x)$, where $|\epsilon| < 2^{-52}.$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::float::NiceFloat;
use malachite_nz::natural::Natural;
assert_eq!(NiceFloat(Natural::from(10u32).approx_log()), NiceFloat(2.3025850929940455));
assert_eq!(
NiceFloat(Natural::from(10u32).pow(10000).approx_log()),
NiceFloat(23025.850929940454)
);
This is equivalent to fmpz_dlog
from fmpz/dlog.c
, FLINT 2.7.1.
source§impl Natural
impl Natural
sourcepub fn cmp_normalized(&self, other: &Natural) -> Ordering
pub fn cmp_normalized(&self, other: &Natural) -> Ordering
Returns a result of a comparison between two Natural
s as if each had been multiplied by
some power of 2 to bring it into the interval $[1, 2)$.
That is, the comparison is equivalent to a comparison between $f(x)$ and $f(y)$, where $$ f(n) = n2^{\lfloor\log_2 n \rfloor}. $$
The multiplication is not actually performed.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits())
.
§Panics
Panics if either argument is zero.
§Examples
use malachite_nz::natural::Natural;
use core::cmp::Ordering;
// 1 == 1.0 * 2^0, 4 == 1.0 * 2^2
// 1.0 == 1.0
assert_eq!(Natural::from(1u32).cmp_normalized(&Natural::from(4u32)), Ordering::Equal);
// 5 == 1.25 * 2^2, 6 == 1.5 * 2^2
// 1.25 < 1.5
assert_eq!(Natural::from(5u32).cmp_normalized(&Natural::from(6u32)), Ordering::Less);
// 3 == 1.5 * 2^1, 17 == 1.0625 * 2^4
// 1.5 > 1.0625
assert_eq!(Natural::from(3u32).cmp_normalized(&Natural::from(17u32)), Ordering::Greater);
// 9 == 1.125 * 2^3, 36 == 1.125 * 2^5
// 1.125 == 1.125
assert_eq!(Natural::from(9u32).cmp_normalized(&Natural::from(36u32)), Ordering::Equal);
source§impl Natural
impl Natural
sourcepub fn from_limbs_asc(xs: &[Limb]) -> Natural
pub fn from_limbs_asc(xs: &[Limb]) -> Natural
Converts a slice of limbs to a Natural
.
The limbs are in ascending order, so that less-significant limbs have lower indices in the input slice.
This function borrows the limbs. If taking ownership of limbs is possible,
from_owned_limbs_asc
is more efficient.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is xs.len()
.
This function is more efficient than from_limbs_desc
.
§Examples
use malachite_base::num::basic::integers::PrimitiveInt;
use malachite_nz::natural::Natural;
use malachite_nz::platform::Limb;
if Limb::WIDTH == u32::WIDTH {
assert_eq!(Natural::from_limbs_asc(&[]), 0);
assert_eq!(Natural::from_limbs_asc(&[123]), 123);
// 10^12 = 232 * 2^32 + 3567587328
assert_eq!(Natural::from_limbs_asc(&[3567587328, 232]), 1000000000000u64);
}
sourcepub fn from_limbs_desc(xs: &[Limb]) -> Natural
pub fn from_limbs_desc(xs: &[Limb]) -> Natural
Converts a slice of limbs to a Natural
.
The limbs in descending order, so that less-significant limbs have higher indices in the input slice.
This function borrows the limbs. If taking ownership of the limbs is possible,
from_owned_limbs_desc
is more efficient.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is xs.len()
.
This function is less efficient than from_limbs_asc
.
§Examples
use malachite_base::num::basic::integers::PrimitiveInt;
use malachite_nz::natural::Natural;
use malachite_nz::platform::Limb;
if Limb::WIDTH == u32::WIDTH {
assert_eq!(Natural::from_limbs_desc(&[]), 0);
assert_eq!(Natural::from_limbs_desc(&[123]), 123);
// 10^12 = 232 * 2^32 + 3567587328
assert_eq!(Natural::from_limbs_desc(&[232, 3567587328]), 1000000000000u64);
}
sourcepub fn from_owned_limbs_asc(xs: Vec<Limb>) -> Natural
pub fn from_owned_limbs_asc(xs: Vec<Limb>) -> Natural
Converts a Vec
of limbs to a Natural
.
The limbs are in ascending order, so that less-significant limbs have lower indices in the
input Vec
.
This function takes ownership of the limbs. If it’s necessary to borrow the limbs instead,
use from_limbs_asc
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is xs.len()
.
This function is more efficient than from_limbs_desc
.
§Examples
use malachite_base::num::basic::integers::PrimitiveInt;
use malachite_nz::natural::Natural;
use malachite_nz::platform::Limb;
if Limb::WIDTH == u32::WIDTH {
assert_eq!(Natural::from_owned_limbs_asc(vec![]), 0);
assert_eq!(Natural::from_owned_limbs_asc(vec![123]), 123);
// 10^12 = 232 * 2^32 + 3567587328
assert_eq!(Natural::from_owned_limbs_asc(vec![3567587328, 232]), 1000000000000u64);
}
sourcepub fn from_owned_limbs_desc(xs: Vec<Limb>) -> Natural
pub fn from_owned_limbs_desc(xs: Vec<Limb>) -> Natural
Converts a Vec
of limbs to a Natural
.
The limbs are in descending order, so that less-significant limbs have higher indices in the
input Vec
.
This function takes ownership of the limbs. If it’s necessary to borrow the limbs instead,
use from_limbs_desc
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is xs.len()
.
This function is less efficient than from_limbs_asc
.
§Examples
use malachite_base::num::basic::integers::PrimitiveInt;
use malachite_nz::natural::Natural;
use malachite_nz::platform::Limb;
if Limb::WIDTH == u32::WIDTH {
assert_eq!(Natural::from_owned_limbs_desc(vec![]), 0);
assert_eq!(Natural::from_owned_limbs_desc(vec![123]), 123);
// 10^12 = 232 * 2^32 + 3567587328
assert_eq!(Natural::from_owned_limbs_desc(vec![232, 3567587328]), 1000000000000u64);
}
source§impl Natural
impl Natural
sourcepub fn limb_count(&self) -> u64
pub fn limb_count(&self) -> u64
Returns the number of limbs of a Natural
.
Zero has 0 limbs.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::integers::PrimitiveInt;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
use malachite_nz::platform::Limb;
if Limb::WIDTH == u32::WIDTH {
assert_eq!(Natural::ZERO.limb_count(), 0);
assert_eq!(Natural::from(123u32).limb_count(), 1);
assert_eq!(Natural::from(10u32).pow(12).limb_count(), 2);
}
source§impl Natural
impl Natural
sourcepub fn sci_mantissa_and_exponent_round<T: PrimitiveFloat>(
&self,
rm: RoundingMode
) -> Option<(T, u64, Ordering)>
pub fn sci_mantissa_and_exponent_round<T: PrimitiveFloat>( &self, rm: RoundingMode ) -> Option<(T, u64, Ordering)>
Returns a Natural
’s scientific mantissa and exponent, rounding according to the
specified rounding mode. An Ordering
is also returned, indicating whether the mantissa
and exponent represent a value that is less than, equal to, or greater than the original
value.
When $x$ is positive, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is
a rational number with $1 \leq m_s < 2$. We represent the rational mantissa as a float. The
conversion might not be exact, so we round to the nearest float using the provided rounding
mode. If the rounding mode is Exact
but the conversion is not exact, None
is returned.
$$
f(x, r) \approx \left (\frac{x}{2^{\lfloor \log_2 x \rfloor}},
\lfloor \log_2 x \rfloor\right ).
$$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::conversion::traits::SciMantissaAndExponent;
use malachite_base::num::float::NiceFloat;
use malachite_base::rounding_modes::RoundingMode;
use malachite_nz::natural::Natural;
use core::cmp::Ordering;
let test = |n: Natural, rm: RoundingMode, out: Option<(f32, u64, Ordering)>| {
assert_eq!(
n.sci_mantissa_and_exponent_round(rm)
.map(|(m, e, o)| (NiceFloat(m), e, o)),
out.map(|(m, e, o)| (NiceFloat(m), e, o))
);
};
test(Natural::from(3u32), RoundingMode::Floor, Some((1.5, 1, Ordering::Equal)));
test(Natural::from(3u32), RoundingMode::Down, Some((1.5, 1, Ordering::Equal)));
test(Natural::from(3u32), RoundingMode::Ceiling, Some((1.5, 1, Ordering::Equal)));
test(Natural::from(3u32), RoundingMode::Up, Some((1.5, 1, Ordering::Equal)));
test(Natural::from(3u32), RoundingMode::Nearest, Some((1.5, 1, Ordering::Equal)));
test(Natural::from(3u32), RoundingMode::Exact, Some((1.5, 1, Ordering::Equal)));
test(
Natural::from(123u32),
RoundingMode::Floor,
Some((1.921875, 6, Ordering::Equal)),
);
test(
Natural::from(123u32),
RoundingMode::Down,
Some((1.921875, 6, Ordering::Equal)),
);
test(
Natural::from(123u32),
RoundingMode::Ceiling,
Some((1.921875, 6, Ordering::Equal)),
);
test(Natural::from(123u32), RoundingMode::Up, Some((1.921875, 6, Ordering::Equal)));
test(
Natural::from(123u32),
RoundingMode::Nearest,
Some((1.921875, 6, Ordering::Equal)),
);
test(
Natural::from(123u32),
RoundingMode::Exact,
Some((1.921875, 6, Ordering::Equal)),
);
test(
Natural::from(1000000000u32),
RoundingMode::Nearest,
Some((1.8626451, 29, Ordering::Equal)),
);
test(
Natural::from(10u32).pow(52),
RoundingMode::Nearest,
Some((1.670478, 172, Ordering::Greater)),
);
test(Natural::from(10u32).pow(52), RoundingMode::Exact, None);
sourcepub fn from_sci_mantissa_and_exponent_round<T: PrimitiveFloat>(
sci_mantissa: T,
sci_exponent: u64,
rm: RoundingMode
) -> Option<(Natural, Ordering)>
pub fn from_sci_mantissa_and_exponent_round<T: PrimitiveFloat>( sci_mantissa: T, sci_exponent: u64, rm: RoundingMode ) -> Option<(Natural, Ordering)>
Constructs a Natural
from its scientific mantissa and exponent, rounding according to
the specified rounding mode. An Ordering
is also returned, indicating whether the
returned value is less than, equal to, or greater than the exact value represented by the
mantissa and exponent.
When $x$ is positive, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and $m_s$ is
a rational number with $1 \leq m_s < 2$. Here, the rational mantissa is provided as a float.
If the mantissa is outside the range $[1, 2)$, None
is returned.
Some combinations of mantissas and exponents do not specify a Natural
, in which case the
resulting value is rounded to a Natural
using the specified rounding mode. If the
rounding mode is Exact
but the input does not exactly specify a Natural
, None
is
returned.
$$ f(x, r) \approx 2^{e_s}m_s. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is sci_exponent
.
§Panics
Panics if sci_mantissa
is zero.
§Examples
use malachite_base::num::conversion::traits::SciMantissaAndExponent;
use malachite_base::rounding_modes::RoundingMode;
use malachite_nz::natural::Natural;
use core::cmp::Ordering;
use core::str::FromStr;
let test = |
mantissa: f32,
exponent: u64,
rm: RoundingMode,
out: Option<(Natural, Ordering)>
| {
assert_eq!(
Natural::from_sci_mantissa_and_exponent_round(mantissa, exponent, rm),
out
);
};
test(1.5, 1, RoundingMode::Floor, Some((Natural::from(3u32), Ordering::Equal)));
test(1.5, 1, RoundingMode::Down, Some((Natural::from(3u32), Ordering::Equal)));
test(1.5, 1, RoundingMode::Ceiling, Some((Natural::from(3u32), Ordering::Equal)));
test(1.5, 1, RoundingMode::Up, Some((Natural::from(3u32), Ordering::Equal)));
test(1.5, 1, RoundingMode::Nearest, Some((Natural::from(3u32), Ordering::Equal)));
test(1.5, 1, RoundingMode::Exact, Some((Natural::from(3u32), Ordering::Equal)));
test(1.51, 1, RoundingMode::Floor, Some((Natural::from(3u32), Ordering::Less)));
test(1.51, 1, RoundingMode::Down, Some((Natural::from(3u32), Ordering::Less)));
test(1.51, 1, RoundingMode::Ceiling, Some((Natural::from(4u32), Ordering::Greater)));
test(1.51, 1, RoundingMode::Up, Some((Natural::from(4u32), Ordering::Greater)));
test(1.51, 1, RoundingMode::Nearest, Some((Natural::from(3u32), Ordering::Less)));
test(1.51, 1, RoundingMode::Exact, None);
test(
1.670478,
172,
RoundingMode::Nearest,
Some(
(
Natural::from_str("10000000254586612611935772707803116801852191350456320")
.unwrap(),
Ordering::Equal
)
),
);
test(2.0, 1, RoundingMode::Floor, None);
test(10.0, 1, RoundingMode::Floor, None);
test(0.5, 1, RoundingMode::Floor, None);
source§impl Natural
impl Natural
sourcepub fn to_limbs_asc(&self) -> Vec<Limb>
pub fn to_limbs_asc(&self) -> Vec<Limb>
Returns the limbs of a Natural
, in ascending order, so that
less-significant limbs have lower indices in the output vector.
There are no trailing zero limbs.
This function borrows the Natural
. If taking ownership is possible instead,
into_limbs_asc
is more efficient.
This function is more efficient than to_limbs_desc
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::integers::PrimitiveInt;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
use malachite_nz::platform::Limb;
if Limb::WIDTH == u32::WIDTH {
assert!(Natural::ZERO.to_limbs_asc().is_empty());
assert_eq!(Natural::from(123u32).to_limbs_asc(), &[123]);
// 10^12 = 232 * 2^32 + 3567587328
assert_eq!(Natural::from(10u32).pow(12).to_limbs_asc(), &[3567587328, 232]);
}
sourcepub fn to_limbs_desc(&self) -> Vec<Limb>
pub fn to_limbs_desc(&self) -> Vec<Limb>
Returns the limbs of a Natural
in descending order, so that
less-significant limbs have higher indices in the output vector.
There are no leading zero limbs.
This function borrows the Natural
. If taking ownership is possible instead,
into_limbs_desc
is more efficient.
This function is less efficient than to_limbs_asc
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::integers::PrimitiveInt;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
use malachite_nz::platform::Limb;
if Limb::WIDTH == u32::WIDTH {
assert!(Natural::ZERO.to_limbs_desc().is_empty());
assert_eq!(Natural::from(123u32).to_limbs_desc(), &[123]);
// 10^12 = 232 * 2^32 + 3567587328
assert_eq!(Natural::from(10u32).pow(12).to_limbs_desc(), &[232, 3567587328]);
}
sourcepub fn into_limbs_asc(self) -> Vec<Limb>
pub fn into_limbs_asc(self) -> Vec<Limb>
Returns the limbs of a Natural
, in ascending order, so that
less-significant limbs have lower indices in the output vector.
There are no trailing zero limbs.
This function takes ownership of the Natural
. If it’s necessary to borrow instead, use
to_limbs_asc
.
This function is more efficient than into_limbs_desc
.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::integers::PrimitiveInt;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
use malachite_nz::platform::Limb;
if Limb::WIDTH == u32::WIDTH {
assert!(Natural::ZERO.into_limbs_asc().is_empty());
assert_eq!(Natural::from(123u32).into_limbs_asc(), &[123]);
// 10^12 = 232 * 2^32 + 3567587328
assert_eq!(Natural::from(10u32).pow(12).into_limbs_asc(), &[3567587328, 232]);
}
sourcepub fn into_limbs_desc(self) -> Vec<Limb>
pub fn into_limbs_desc(self) -> Vec<Limb>
Returns the limbs of a Natural
, in descending order, so that
less-significant limbs have higher indices in the output vector.
There are no leading zero limbs.
This function takes ownership of the Natural
. If it’s necessary to borrow instead, use
to_limbs_desc
.
This function is less efficient than into_limbs_asc
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::integers::PrimitiveInt;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
use malachite_nz::platform::Limb;
if Limb::WIDTH == u32::WIDTH {
assert!(Natural::ZERO.into_limbs_desc().is_empty());
assert_eq!(Natural::from(123u32).into_limbs_desc(), &[123]);
// 10^12 = 232 * 2^32 + 3567587328
assert_eq!(Natural::from(10u32).pow(12).into_limbs_desc(), &[232, 3567587328]);
}
sourcepub fn limbs(&self) -> LimbIterator<'_> ⓘ
pub fn limbs(&self) -> LimbIterator<'_> ⓘ
Returns a double-ended iterator over the limbs of a Natural
.
The forward order is ascending, so that less-significant limbs appear first. There are no trailing zero limbs going forward, or leading zeros going backward.
If it’s necessary to get a Vec
of all the limbs, consider using
to_limbs_asc
, to_limbs_desc
,
into_limbs_asc
, or into_limbs_desc
instead.
§Worst-case complexity
Constant time and additional memory.
§Examples
use itertools::Itertools;
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::integers::PrimitiveInt;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
use malachite_nz::platform::Limb;
if Limb::WIDTH == u32::WIDTH {
assert!(Natural::ZERO.limbs().next().is_none());
assert_eq!(Natural::from(123u32).limbs().collect_vec(), &[123]);
// 10^12 = 232 * 2^32 + 3567587328
assert_eq!(Natural::from(10u32).pow(12).limbs().collect_vec(), &[3567587328, 232]);
assert!(Natural::ZERO.limbs().rev().next().is_none());
assert_eq!(Natural::from(123u32).limbs().rev().collect_vec(), &[123]);
// 10^12 = 232 * 2^32 + 3567587328
assert_eq!(
Natural::from(10u32).pow(12).limbs().rev().collect_vec(),
&[232, 3567587328]
);
}
source§impl Natural
impl Natural
sourcepub fn trailing_zeros(&self) -> Option<u64>
pub fn trailing_zeros(&self) -> Option<u64>
Returns the number of trailing zeros in the binary expansion of a Natural
(equivalently,
the multiplicity of 2 in its prime factorization), or None
is the Natural
is 0.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!(Natural::ZERO.trailing_zeros(), None);
assert_eq!(Natural::from(3u32).trailing_zeros(), Some(0));
assert_eq!(Natural::from(72u32).trailing_zeros(), Some(3));
assert_eq!(Natural::from(100u32).trailing_zeros(), Some(2));
assert_eq!(Natural::from(10u32).pow(12).trailing_zeros(), Some(12));
Trait Implementations§
source§impl<'a, 'b> Add<&'a Natural> for &'b Natural
impl<'a, 'b> Add<&'a Natural> for &'b Natural
source§fn add(self, other: &'a Natural) -> Natural
fn add(self, other: &'a Natural) -> Natural
Adds two Natural
s, taking both by reference.
$$ f(x, y) = x + y. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!(&Natural::ZERO + &Natural::from(123u32), 123);
assert_eq!(&Natural::from(123u32) + &Natural::ZERO, 123);
assert_eq!(&Natural::from(123u32) + &Natural::from(456u32), 579);
assert_eq!(
&Natural::from(10u32).pow(12) + &(Natural::from(10u32).pow(12) << 1),
3000000000000u64
);
source§impl<'a> Add<&'a Natural> for Natural
impl<'a> Add<&'a Natural> for Natural
source§fn add(self, other: &'a Natural) -> Natural
fn add(self, other: &'a Natural) -> Natural
Adds two Natural
s, taking the first by reference and the second by value.
$$ f(x, y) = x + y. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!(Natural::ZERO + &Natural::from(123u32), 123);
assert_eq!(Natural::from(123u32) + &Natural::ZERO, 123);
assert_eq!(Natural::from(123u32) + &Natural::from(456u32), 579);
assert_eq!(
Natural::from(10u32).pow(12) + &(Natural::from(10u32).pow(12) << 1),
3000000000000u64
);
source§impl<'a> Add<Natural> for &'a Natural
impl<'a> Add<Natural> for &'a Natural
source§fn add(self, other: Natural) -> Natural
fn add(self, other: Natural) -> Natural
Adds two Natural
s, taking the first by value and the second by reference.
$$ f(x, y) = x + y. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!(&Natural::ZERO + Natural::from(123u32), 123);
assert_eq!(&Natural::from(123u32) + Natural::ZERO, 123);
assert_eq!(&Natural::from(123u32) + Natural::from(456u32), 579);
assert_eq!(
&Natural::from(10u32).pow(12) + (Natural::from(10u32).pow(12) << 1),
3000000000000u64
);
source§impl Add for Natural
impl Add for Natural
source§fn add(self, other: Natural) -> Natural
fn add(self, other: Natural) -> Natural
Adds two Natural
s, taking both by value.
$$ f(x, y) = x + y. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$ (only if the underlying Vec
needs to reallocate)
where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!(Natural::ZERO + Natural::from(123u32), 123);
assert_eq!(Natural::from(123u32) + Natural::ZERO, 123);
assert_eq!(Natural::from(123u32) + Natural::from(456u32), 579);
assert_eq!(
Natural::from(10u32).pow(12) + (Natural::from(10u32).pow(12) << 1),
3000000000000u64
);
source§impl<'a> AddAssign<&'a Natural> for Natural
impl<'a> AddAssign<&'a Natural> for Natural
source§fn add_assign(&mut self, other: &'a Natural)
fn add_assign(&mut self, other: &'a Natural)
Adds a Natural
to a Natural
in place, taking the Natural
on the right-hand side
by reference.
$$ x \gets x + y. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
let mut x = Natural::ZERO;
x += &Natural::from(10u32).pow(12);
x += &(Natural::from(10u32).pow(12) * Natural::from(2u32));
x += &(Natural::from(10u32).pow(12) * Natural::from(3u32));
x += &(Natural::from(10u32).pow(12) * Natural::from(4u32));
assert_eq!(x, 10000000000000u64);
source§impl AddAssign for Natural
impl AddAssign for Natural
source§fn add_assign(&mut self, other: Natural)
fn add_assign(&mut self, other: Natural)
Adds a Natural
to a Natural
in place, taking the Natural
on the right-hand side
by value.
$$ x \gets x + y. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$ (only if the underlying Vec
needs to reallocate)
where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
let mut x = Natural::ZERO;
x += Natural::from(10u32).pow(12);
x += Natural::from(10u32).pow(12) * Natural::from(2u32);
x += Natural::from(10u32).pow(12) * Natural::from(3u32);
x += Natural::from(10u32).pow(12) * Natural::from(4u32);
assert_eq!(x, 10000000000000u64);
source§impl<'a> AddMul<&'a Natural> for Natural
impl<'a> AddMul<&'a Natural> for Natural
source§fn add_mul(self, y: &'a Natural, z: Natural) -> Natural
fn add_mul(self, y: &'a Natural, z: Natural) -> Natural
Adds a Natural
and the product of two other Natural
s, taking the first and third by
value and the second by reference.
$f(x, y, z) = x + yz$.
§Worst-case complexity
$T(n, m) = O(m + n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is max(y.significant_bits(), z.significant_bits())
, and $m$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::{AddMul, Pow};
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(10u32).add_mul(&Natural::from(3u32), Natural::from(4u32)), 22);
assert_eq!(
Natural::from(10u32).pow(12)
.add_mul(&Natural::from(0x10000u32), Natural::from(10u32).pow(12)),
65537000000000000u64
);
type Output = Natural
source§impl<'a, 'b, 'c> AddMul<&'a Natural, &'b Natural> for &'c Natural
impl<'a, 'b, 'c> AddMul<&'a Natural, &'b Natural> for &'c Natural
source§fn add_mul(self, y: &'a Natural, z: &'b Natural) -> Natural
fn add_mul(self, y: &'a Natural, z: &'b Natural) -> Natural
Adds a Natural
and the product of two other Natural
s, taking all three by reference.
$f(x, y, z) = x + yz$.
§Worst-case complexity
$T(n, m) = O(m + n \log n \log\log n)$
$M(n, m) = O(m + n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is max(y.significant_bits(), z.significant_bits())
, and $m$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::{AddMul, Pow};
use malachite_nz::natural::Natural;
assert_eq!((&Natural::from(10u32)).add_mul(&Natural::from(3u32), &Natural::from(4u32)), 22);
assert_eq!(
(&Natural::from(10u32).pow(12))
.add_mul(&Natural::from(0x10000u32), &Natural::from(10u32).pow(12)),
65537000000000000u64
);
type Output = Natural
source§impl<'a, 'b> AddMul<&'a Natural, &'b Natural> for Natural
impl<'a, 'b> AddMul<&'a Natural, &'b Natural> for Natural
source§fn add_mul(self, y: &'a Natural, z: &'b Natural) -> Natural
fn add_mul(self, y: &'a Natural, z: &'b Natural) -> Natural
Adds a Natural
and the product of two other Natural
s, taking the first by value and
the second and third by reference.
$f(x, y, z) = x + yz$.
§Worst-case complexity
$T(n, m) = O(m + n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is max(y.significant_bits(), z.significant_bits())
, and $m$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::{AddMul, Pow};
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(10u32).add_mul(&Natural::from(3u32), &Natural::from(4u32)), 22);
assert_eq!(
Natural::from(10u32).pow(12)
.add_mul(&Natural::from(0x10000u32), &Natural::from(10u32).pow(12)),
65537000000000000u64
);
type Output = Natural
source§impl<'a> AddMul<Natural, &'a Natural> for Natural
impl<'a> AddMul<Natural, &'a Natural> for Natural
source§fn add_mul(self, y: Natural, z: &'a Natural) -> Natural
fn add_mul(self, y: Natural, z: &'a Natural) -> Natural
Adds a Natural
and the product of two other Natural
s, taking the first two by value
and the third by reference.
$f(x, y, z) = x + yz$.
§Worst-case complexity
$T(n, m) = O(m + n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is max(y.significant_bits(), z.significant_bits())
, and $m$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::{AddMul, Pow};
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(10u32).add_mul(Natural::from(3u32), &Natural::from(4u32)), 22);
assert_eq!(
Natural::from(10u32).pow(12)
.add_mul(Natural::from(0x10000u32), &Natural::from(10u32).pow(12)),
65537000000000000u64
);
type Output = Natural
source§impl AddMul for Natural
impl AddMul for Natural
source§fn add_mul(self, y: Natural, z: Natural) -> Natural
fn add_mul(self, y: Natural, z: Natural) -> Natural
Adds a Natural
and the product of two other Natural
s, taking all three by value.
$f(x, y, z) = x + yz$.
§Worst-case complexity
$T(n, m) = O(m + n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is max(y.significant_bits(), z.significant_bits())
, and $m$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::{AddMul, Pow};
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(10u32).add_mul(Natural::from(3u32), Natural::from(4u32)), 22);
assert_eq!(
Natural::from(10u32).pow(12)
.add_mul(Natural::from(0x10000u32), Natural::from(10u32).pow(12)),
65537000000000000u64
);
type Output = Natural
source§impl<'a> AddMulAssign<&'a Natural> for Natural
impl<'a> AddMulAssign<&'a Natural> for Natural
source§fn add_mul_assign(&mut self, y: &'a Natural, z: Natural)
fn add_mul_assign(&mut self, y: &'a Natural, z: Natural)
Adds the product of two other Natural
s to a Natural
in place, taking the first
Natural
on the right-hand side by reference and the second by value.
$x \gets x + yz$.
§Worst-case complexity
$T(n, m) = O(m + n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is max(y.significant_bits(), z.significant_bits())
, and $m$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::{AddMulAssign, Pow};
use malachite_nz::natural::Natural;
let mut x = Natural::from(10u32);
x.add_mul_assign(&Natural::from(3u32), Natural::from(4u32));
assert_eq!(x, 22);
let mut x = Natural::from(10u32).pow(12);
x.add_mul_assign(&Natural::from(0x10000u32), Natural::from(10u32).pow(12));
assert_eq!(x, 65537000000000000u64);
source§impl<'a, 'b> AddMulAssign<&'a Natural, &'b Natural> for Natural
impl<'a, 'b> AddMulAssign<&'a Natural, &'b Natural> for Natural
source§fn add_mul_assign(&mut self, y: &'a Natural, z: &'b Natural)
fn add_mul_assign(&mut self, y: &'a Natural, z: &'b Natural)
Adds the product of two other Natural
s to a Natural
in place, taking both
Natural
s on the right-hand side by reference.
$x \gets x + yz$.
§Worst-case complexity
$T(n, m) = O(m + n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is max(y.significant_bits(), z.significant_bits())
, and $m$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::{AddMulAssign, Pow};
use malachite_nz::natural::Natural;
let mut x = Natural::from(10u32);
x.add_mul_assign(&Natural::from(3u32), &Natural::from(4u32));
assert_eq!(x, 22);
let mut x = Natural::from(10u32).pow(12);
x.add_mul_assign(&Natural::from(0x10000u32), &Natural::from(10u32).pow(12));
assert_eq!(x, 65537000000000000u64);
source§impl<'a> AddMulAssign<Natural, &'a Natural> for Natural
impl<'a> AddMulAssign<Natural, &'a Natural> for Natural
source§fn add_mul_assign(&mut self, y: Natural, z: &'a Natural)
fn add_mul_assign(&mut self, y: Natural, z: &'a Natural)
Adds the product of two other Natural
s to a Natural
in place, taking the first
Natural
on the right-hand side by value and the second by reference.
$x \gets x + yz$.
§Worst-case complexity
$T(n, m) = O(m + n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is max(y.significant_bits(), z.significant_bits())
, and $m$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::{AddMulAssign, Pow};
use malachite_nz::natural::Natural;
let mut x = Natural::from(10u32);
x.add_mul_assign(Natural::from(3u32), &Natural::from(4u32));
assert_eq!(x, 22);
let mut x = Natural::from(10u32).pow(12);
x.add_mul_assign(Natural::from(0x10000u32), &Natural::from(10u32).pow(12));
assert_eq!(x, 65537000000000000u64);
source§impl AddMulAssign for Natural
impl AddMulAssign for Natural
source§fn add_mul_assign(&mut self, y: Natural, z: Natural)
fn add_mul_assign(&mut self, y: Natural, z: Natural)
Adds the product of two other Natural
s to a Natural
in place, taking both
Natural
s on the right-hand side by value.
$x \gets x + yz$.
§Worst-case complexity
$T(n, m) = O(m + n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is max(y.significant_bits(), z.significant_bits())
, and $m$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::{AddMulAssign, Pow};
use malachite_nz::natural::Natural;
let mut x = Natural::from(10u32);
x.add_mul_assign(Natural::from(3u32), Natural::from(4u32));
assert_eq!(x, 22);
let mut x = Natural::from(10u32).pow(12);
x.add_mul_assign(Natural::from(0x10000u32), Natural::from(10u32).pow(12));
assert_eq!(x, 65537000000000000u64);
source§impl Binary for Natural
impl Binary for Natural
source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Converts a Natural
to a binary String
.
Using the #
format flag prepends "0b"
to the string.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_base::strings::ToBinaryString;
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!(Natural::ZERO.to_binary_string(), "0");
assert_eq!(Natural::from(123u32).to_binary_string(), "1111011");
assert_eq!(
Natural::from_str("1000000000000").unwrap().to_binary_string(),
"1110100011010100101001010001000000000000"
);
assert_eq!(format!("{:011b}", Natural::from(123u32)), "00001111011");
assert_eq!(format!("{:#b}", Natural::ZERO), "0b0");
assert_eq!(format!("{:#b}", Natural::from(123u32)), "0b1111011");
assert_eq!(
format!("{:#b}", Natural::from_str("1000000000000").unwrap()),
"0b1110100011010100101001010001000000000000"
);
assert_eq!(format!("{:#011b}", Natural::from(123u32)), "0b001111011");
source§impl<'a> BinomialCoefficient<&'a Natural> for Natural
impl<'a> BinomialCoefficient<&'a Natural> for Natural
source§fn binomial_coefficient(n: &'a Natural, k: &'a Natural) -> Natural
fn binomial_coefficient(n: &'a Natural, k: &'a Natural) -> Natural
Computes the binomial coefficient of two Natural
s, taking both by reference.
$$ f(n, k) =binom{n}{k} =frac{n!}{k!(n-k)!}. $$
§Worst-case complexity
TODO
§Examples
use malachite_base::num::arithmetic::traits::BinomialCoefficient;
use malachite_nz::natural::Natural;
assert_eq!(Natural::binomial_coefficient(&Natural::from(4u32), &Natural::from(0u32)), 1);
assert_eq!(Natural::binomial_coefficient(&Natural::from(4u32), &Natural::from(1u32)), 4);
assert_eq!(Natural::binomial_coefficient(&Natural::from(4u32), &Natural::from(2u32)), 6);
assert_eq!(Natural::binomial_coefficient(&Natural::from(4u32), &Natural::from(3u32)), 4);
assert_eq!(Natural::binomial_coefficient(&Natural::from(4u32), &Natural::from(4u32)), 1);
assert_eq!(
Natural::binomial_coefficient(&Natural::from(10u32), &Natural::from(5u32)),
252
);
assert_eq!(
Natural::binomial_coefficient(&Natural::from(100u32), &Natural::from(50u32))
.to_string(),
"100891344545564193334812497256"
);
source§impl BinomialCoefficient for Natural
impl BinomialCoefficient for Natural
source§fn binomial_coefficient(n: Natural, k: Natural) -> Natural
fn binomial_coefficient(n: Natural, k: Natural) -> Natural
Computes the binomial coefficient of two Natural
s, taking both by value.
$$ f(n, k) =binom{n}{k} =frac{n!}{k!(n-k)!}. $$
§Worst-case complexity
TODO
§Examples
use malachite_base::num::arithmetic::traits::BinomialCoefficient;
use malachite_nz::natural::Natural;
assert_eq!(Natural::binomial_coefficient(Natural::from(4u32), Natural::from(0u32)), 1);
assert_eq!(Natural::binomial_coefficient(Natural::from(4u32), Natural::from(1u32)), 4);
assert_eq!(Natural::binomial_coefficient(Natural::from(4u32), Natural::from(2u32)), 6);
assert_eq!(Natural::binomial_coefficient(Natural::from(4u32), Natural::from(3u32)), 4);
assert_eq!(Natural::binomial_coefficient(Natural::from(4u32), Natural::from(4u32)), 1);
assert_eq!(Natural::binomial_coefficient(Natural::from(10u32), Natural::from(5u32)), 252);
assert_eq!(
Natural::binomial_coefficient(Natural::from(100u32), Natural::from(50u32)).to_string(),
"100891344545564193334812497256"
);
source§impl BitAccess for Natural
impl BitAccess for Natural
Provides functions for accessing and modifying the $i$th bit of a Natural
, or the
coefficient of $2^i$ in its binary expansion.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_base::num::logic::traits::BitAccess;
use malachite_nz::natural::Natural;
let mut x = Natural::ZERO;
x.assign_bit(2, true);
x.assign_bit(5, true);
x.assign_bit(6, true);
assert_eq!(x, 100);
x.assign_bit(2, false);
x.assign_bit(5, false);
x.assign_bit(6, false);
assert_eq!(x, 0);
let mut x = Natural::ZERO;
x.flip_bit(10);
assert_eq!(x, 1024);
x.flip_bit(10);
assert_eq!(x, 0);
source§fn get_bit(&self, index: u64) -> bool
fn get_bit(&self, index: u64) -> bool
Determines whether the $i$th bit of a Natural
, or the coefficient of $2^i$ in its binary
expansion, is 0 or 1.
false
means 0 and true
means 1. Getting bits beyond the Natural
’s width is allowed;
those bits are false
.
Let $$ n = \sum_{i=0}^\infty 2^{b_i}, $$ where for all $i$, $b_i\in \{0, 1\}$; so finitely many of the bits are 1, and the rest are 0. Then $f(n, j) = (b_j = 1)$.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::logic::traits::BitAccess;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(123u32).get_bit(2), false);
assert_eq!(Natural::from(123u32).get_bit(3), true);
assert_eq!(Natural::from(123u32).get_bit(100), false);
assert_eq!(Natural::from(10u32).pow(12).get_bit(12), true);
assert_eq!(Natural::from(10u32).pow(12).get_bit(100), false);
source§fn set_bit(&mut self, index: u64)
fn set_bit(&mut self, index: u64)
Sets the $i$th bit of a Natural
, or the coefficient of $2^i$ in its binary expansion, to
1.
Let $$ n = \sum_{i=0}^\infty 2^{b_i}, $$ where for all $i$, $b_i\in \{0, 1\}$; so finitely many of the bits are 1, and the rest are 0. Then $$ n \gets \begin{cases} n + 2^j & \text{if} \quad b_j = 0, \\ n & \text{otherwise}. \end{cases} $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is index
.
§Examples
use malachite_base::num::logic::traits::BitAccess;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
let mut x = Natural::ZERO;
x.set_bit(2);
x.set_bit(5);
x.set_bit(6);
assert_eq!(x, 100);
source§fn clear_bit(&mut self, index: u64)
fn clear_bit(&mut self, index: u64)
Sets the $i$th bit of a Natural
, or the coefficient of $2^i$ in its binary expansion, to
0.
Clearing bits beyond the Natural
’s width is allowed; since those bits are already
false
, clearing them does nothing.
Let $$ n = \sum_{i=0}^\infty 2^{b_i}, $$ where for all $i$, $b_i\in \{0, 1\}$; so finitely many of the bits are 1, and the rest are 0. Then $$ n \gets \begin{cases} n - 2^j & \text{if} \quad b_j = 1, \\ n & \text{otherwise}. \end{cases} $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is index
.
§Examples
use malachite_base::num::logic::traits::BitAccess;
use malachite_nz::natural::Natural;
let mut x = Natural::from(0x7fu32);
x.clear_bit(0);
x.clear_bit(1);
x.clear_bit(3);
x.clear_bit(4);
assert_eq!(x, 100);
source§fn assign_bit(&mut self, index: u64, bit: bool)
fn assign_bit(&mut self, index: u64, bit: bool)
source§impl<'a, 'b> BitAnd<&'a Natural> for &'b Natural
impl<'a, 'b> BitAnd<&'a Natural> for &'b Natural
source§fn bitand(self, other: &'a Natural) -> Natural
fn bitand(self, other: &'a Natural) -> Natural
Takes the bitwise and of two Natural
s, taking both by reference.
$$ f(x, y) = x \wedge y. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_nz::natural::Natural;
assert_eq!(&Natural::from(123u32) & &Natural::from(456u32), 72);
assert_eq!(
&Natural::from(10u32).pow(12) & &(Natural::from(10u32).pow(12) - Natural::ONE),
999999995904u64
);
source§impl<'a> BitAnd<&'a Natural> for Natural
impl<'a> BitAnd<&'a Natural> for Natural
source§fn bitand(self, other: &'a Natural) -> Natural
fn bitand(self, other: &'a Natural) -> Natural
Takes the bitwise and of two Natural
s, taking the first by value and the second by
reference.
$$ f(x, y) = x \wedge y. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(123u32) & &Natural::from(456u32), 72);
assert_eq!(
Natural::from(10u32).pow(12) & &(Natural::from(10u32).pow(12) - Natural::ONE),
999999995904u64
);
source§impl<'a> BitAnd<Natural> for &'a Natural
impl<'a> BitAnd<Natural> for &'a Natural
source§fn bitand(self, other: Natural) -> Natural
fn bitand(self, other: Natural) -> Natural
Takes the bitwise and of two Natural
s, taking the first by reference and the seocnd by
value.
$$ f(x, y) = x \wedge y. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_nz::natural::Natural;
assert_eq!(&Natural::from(123u32) & Natural::from(456u32), 72);
assert_eq!(
&Natural::from(10u32).pow(12) & (Natural::from(10u32).pow(12) - Natural::ONE),
999999995904u64
);
source§impl BitAnd for Natural
impl BitAnd for Natural
source§fn bitand(self, other: Natural) -> Natural
fn bitand(self, other: Natural) -> Natural
Takes the bitwise and of two Natural
s, taking both by value.
$$ f(x, y) = x \wedge y. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(123u32) & Natural::from(456u32), 72);
assert_eq!(
Natural::from(10u32).pow(12) & (Natural::from(10u32).pow(12) - Natural::ONE),
999999995904u64
);
source§impl<'a> BitAndAssign<&'a Natural> for Natural
impl<'a> BitAndAssign<&'a Natural> for Natural
source§fn bitand_assign(&mut self, other: &'a Natural)
fn bitand_assign(&mut self, other: &'a Natural)
Bitwise-ands a Natural
with another Natural
in place, taking the Natural
on the
right-hand side by reference.
$$ x \gets x \wedge y. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
§Examples
use malachite_nz::natural::Natural;
let mut x = Natural::from(u32::MAX);
x &= &Natural::from(0xf0ffffffu32);
x &= &Natural::from(0xfff0_ffffu32);
x &= &Natural::from(0xfffff0ffu32);
x &= &Natural::from(0xfffffff0u32);
assert_eq!(x, 0xf0f0_f0f0u32);
source§impl BitAndAssign for Natural
impl BitAndAssign for Natural
source§fn bitand_assign(&mut self, other: Natural)
fn bitand_assign(&mut self, other: Natural)
Bitwise-ands a Natural
with another Natural
in place, taking the Natural
on the
right-hand side by value.
$$ x \gets x \wedge y. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_nz::natural::Natural;
let mut x = Natural::from(u32::MAX);
x &= Natural::from(0xf0ffffffu32);
x &= Natural::from(0xfff0_ffffu32);
x &= Natural::from(0xfffff0ffu32);
x &= Natural::from(0xfffffff0u32);
assert_eq!(x, 0xf0f0_f0f0u32);
source§impl BitBlockAccess for Natural
impl BitBlockAccess for Natural
source§fn get_bits(&self, start: u64, end: u64) -> Natural
fn get_bits(&self, start: u64, end: u64) -> Natural
Extracts a block of adjacent bits from a Natural
, taking the Natural
by reference.
The first index is start
and last index is end - 1
.
Let $n$ be self
, and let $p$ and $q$ be start
and end
, respectively.
Let $$ n = \sum_{i=0}^\infty 2^{b_i}, $$ where for all $i$, $b_i\in \{0, 1\}$; so finitely many of the bits are 1, and the rest are 0. Then $$ f(n, p, q) = \sum_{i=p}^{q-1} 2^{b_{i-p}}. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if start > end
.
§Examples
use malachite_base::num::logic::traits::BitBlockAccess;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(0xabcdef0112345678u64).get_bits(16, 48), 0xef011234u32);
assert_eq!(Natural::from(0xabcdef0112345678u64).get_bits(4, 16), 0x567u32);
assert_eq!(Natural::from(0xabcdef0112345678u64).get_bits(0, 100), 0xabcdef0112345678u64);
assert_eq!(Natural::from(0xabcdef0112345678u64).get_bits(10, 10), 0);
source§fn get_bits_owned(self, start: u64, end: u64) -> Natural
fn get_bits_owned(self, start: u64, end: u64) -> Natural
Extracts a block of adjacent bits from a Natural
, taking the Natural
by value.
The first index is start
and last index is end - 1
.
Let $n$ be self
, and let $p$ and $q$ be start
and end
, respectively.
Let $$ n = \sum_{i=0}^\infty 2^{b_i}, $$ where for all $i$, $b_i\in \{0, 1\}$; so finitely many of the bits are 1, and the rest are 0. Then $$ f(n, p, q) = \sum_{i=p}^{q-1} 2^{b_{i-p}}. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if start > end
.
§Examples
use malachite_base::num::logic::traits::BitBlockAccess;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(0xabcdef0112345678u64).get_bits_owned(16, 48), 0xef011234u32);
assert_eq!(Natural::from(0xabcdef0112345678u64).get_bits_owned(4, 16), 0x567u32);
assert_eq!(
Natural::from(0xabcdef0112345678u64).get_bits_owned(0, 100),
0xabcdef0112345678u64
);
assert_eq!(Natural::from(0xabcdef0112345678u64).get_bits_owned(10, 10), 0);
source§fn assign_bits(&mut self, start: u64, end: u64, bits: &Natural)
fn assign_bits(&mut self, start: u64, end: u64, bits: &Natural)
Replaces a block of adjacent bits in a Natural
with other bits.
The least-significant end - start
bits of bits
are assigned to bits start
through `end
- 1
, inclusive, of
self`.
Let $n$ be self
and let $m$ be bits
, and let $p$ and $q$ be start
and end
,
respectively.
If bits
has fewer bits than end - start
, the high bits are interpreted as 0. Let
$$
n = \sum_{i=0}^\infty 2^{b_i},
$$
where for all $i$, $b_i\in \{0, 1\}$; so finitely many of the bits are 1, and the rest are
0. Let
$$
m = \sum_{i=0}^k 2^{d_i},
$$
where for all $i$, $d_i\in \{0, 1\}$. Also, let $p, q \in \mathbb{N}$, and let $W$ be
max(self.significant_bits(), end + 1)
.
Then $$ n \gets \sum_{i=0}^{W-1} 2^{c_i}, $$ where $$ \{c_0, c_1, c_2, \ldots, c_ {W-1}\} = \{b_0, b_1, b_2, \ldots, b_{p-1}, d_0, d_1, \ldots, d_{p-q-1}, b_q, \ldots, b_ {W-1}\}. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is end
.
§Panics
Panics if start > end
.
§Examples
use malachite_base::num::logic::traits::BitBlockAccess;
use malachite_nz::natural::Natural;
let mut n = Natural::from(123u32);
n.assign_bits(5, 7, &Natural::from(456u32));
assert_eq!(n, 27);
let mut n = Natural::from(123u32);
n.assign_bits(64, 128, &Natural::from(456u32));
assert_eq!(n.to_string(), "8411715297611555537019");
let mut n = Natural::from(123u32);
n.assign_bits(80, 100, &Natural::from(456u32));
assert_eq!(n.to_string(), "551270173744270903666016379");
type Bits = Natural
source§impl BitConvertible for Natural
impl BitConvertible for Natural
source§fn to_bits_asc(&self) -> Vec<bool>
fn to_bits_asc(&self) -> Vec<bool>
Returns a Vec
containing the bits of a Natural
in ascending order: least- to
most-significant.
If the number is 0, the Vec
is empty; otherwise, it ends with true
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::logic::traits::BitConvertible;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert!(Natural::ZERO.to_bits_asc().is_empty());
// 105 = 1101001b
assert_eq!(
Natural::from(105u32).to_bits_asc(),
&[true, false, false, true, false, true, true]
);
source§fn to_bits_desc(&self) -> Vec<bool>
fn to_bits_desc(&self) -> Vec<bool>
Returns a Vec
containing the bits of a Natural
in descending order: most- to
least-significant.
If the number is 0, the Vec
is empty; otherwise, it begins with true
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::logic::traits::BitConvertible;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert!(Natural::ZERO.to_bits_desc().is_empty());
// 105 = 1101001b
assert_eq!(
Natural::from(105u32).to_bits_desc(),
&[true, true, false, true, false, false, true]
);
source§fn from_bits_asc<I: Iterator<Item = bool>>(xs: I) -> Natural
fn from_bits_asc<I: Iterator<Item = bool>>(xs: I) -> Natural
Converts an iterator of bits into a Natural
. The bits should be in ascending order
(least- to most-significant).
$$ f((b_i)_ {i=0}^{k-1}) = \sum_{i=0}^{k-1}2^i [b_i], $$ where braces denote the Iverson bracket, which converts a bit to 0 or 1.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is xs.count()
.
§Examples
use malachite_base::num::logic::traits::BitConvertible;
use malachite_nz::natural::Natural;
use core::iter::empty;
assert_eq!(Natural::from_bits_asc(empty()), 0);
// 105 = 1101001b
assert_eq!(
Natural::from_bits_asc([true, false, false, true, false, true, true].iter().cloned()),
105
);
source§fn from_bits_desc<I: Iterator<Item = bool>>(xs: I) -> Natural
fn from_bits_desc<I: Iterator<Item = bool>>(xs: I) -> Natural
Converts an iterator of bits into a Natural
. The bits should be in descending order
(most- to least-significant).
$$ f((b_i)_ {i=0}^{k-1}) = \sum_{i=0}^{k-1}2^{k-i-1} [b_i], $$ where braces denote the Iverson bracket, which converts a bit to 0 or 1.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is xs.count()
.
§Examples
use malachite_base::num::logic::traits::BitConvertible;
use malachite_nz::natural::Natural;
use core::iter::empty;
assert_eq!(Natural::from_bits_desc(empty()), 0);
// 105 = 1101001b
assert_eq!(
Natural::from_bits_desc([true, true, false, true, false, false, true].iter().cloned()),
105
);
source§impl<'a> BitIterable for &'a Natural
impl<'a> BitIterable for &'a Natural
source§fn bits(self) -> NaturalBitIterator<'a> ⓘ
fn bits(self) -> NaturalBitIterator<'a> ⓘ
Returns a double-ended iterator over the bits of a Natural
.
The forward order is ascending, so that less significant bits appear first. There are no trailing false bits going forward, or leading falses going backward.
If it’s necessary to get a [Vec
] of all the bits, consider using
to_bits_asc
or
to_bits_desc
instead.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_base::num::logic::traits::BitIterable;
use malachite_nz::natural::Natural;
assert!(Natural::ZERO.bits().next().is_none());
// 105 = 1101001b
assert_eq!(
Natural::from(105u32).bits().collect::<Vec<bool>>(),
&[true, false, false, true, false, true, true]
);
assert!(Natural::ZERO.bits().next_back().is_none());
// 105 = 1101001b
assert_eq!(
Natural::from(105u32).bits().rev().collect::<Vec<bool>>(),
&[true, true, false, true, false, false, true]
);
type BitIterator = NaturalBitIterator<'a>
source§impl<'a, 'b> BitOr<&'a Natural> for &'b Natural
impl<'a, 'b> BitOr<&'a Natural> for &'b Natural
source§fn bitor(self, other: &'a Natural) -> Natural
fn bitor(self, other: &'a Natural) -> Natural
Takes the bitwise or of two Natural
s, taking both by reference.
$$ f(x, y) = x \vee y. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_nz::natural::Natural;
assert_eq!(&Natural::from(123u32) | &Natural::from(456u32), 507);
assert_eq!(
&Natural::from(10u32).pow(12) | &(Natural::from(10u32).pow(12) - Natural::ONE),
1000000004095u64
);
source§impl<'a> BitOr<&'a Natural> for Natural
impl<'a> BitOr<&'a Natural> for Natural
source§fn bitor(self, other: &'a Natural) -> Natural
fn bitor(self, other: &'a Natural) -> Natural
Takes the bitwise or of two Natural
s, taking the first by value and the second by
reference.
$$ f(x, y) = x \vee y. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(123u32) | &Natural::from(456u32), 507);
assert_eq!(
Natural::from(10u32).pow(12) | &(Natural::from(10u32).pow(12) - Natural::ONE),
1000000004095u64
);
source§impl<'a> BitOr<Natural> for &'a Natural
impl<'a> BitOr<Natural> for &'a Natural
source§fn bitor(self, other: Natural) -> Natural
fn bitor(self, other: Natural) -> Natural
Takes the bitwise or of two Natural
s, taking the first by reference and the second by
value.
$$ f(x, y) = x \vee y. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_nz::natural::Natural;
assert_eq!(&Natural::from(123u32) | Natural::from(456u32), 507);
assert_eq!(
&Natural::from(10u32).pow(12) | (Natural::from(10u32).pow(12) - Natural::ONE),
1000000004095u64
);
source§impl BitOr for Natural
impl BitOr for Natural
source§fn bitor(self, other: Natural) -> Natural
fn bitor(self, other: Natural) -> Natural
Takes the bitwise or of two Natural
s, taking both by value.
$$ f(x, y) = x \vee y. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(123u32) | Natural::from(456u32), 507);
assert_eq!(
Natural::from(10u32).pow(12) | (Natural::from(10u32).pow(12) - Natural::ONE),
1000000004095u64
);
source§impl<'a> BitOrAssign<&'a Natural> for Natural
impl<'a> BitOrAssign<&'a Natural> for Natural
source§fn bitor_assign(&mut self, other: &'a Natural)
fn bitor_assign(&mut self, other: &'a Natural)
Bitwise-ors a Natural
with another Natural
in place, taking the Natural
on the
right-hand side by reference.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
let mut x = Natural::ZERO;
x |= &Natural::from(0x0000000fu32);
x |= &Natural::from(0x00000f00u32);
x |= &Natural::from(0x000f_0000u32);
x |= &Natural::from(0x0f000000u32);
assert_eq!(x, 0x0f0f_0f0f);
source§impl BitOrAssign for Natural
impl BitOrAssign for Natural
source§fn bitor_assign(&mut self, other: Natural)
fn bitor_assign(&mut self, other: Natural)
Bitwise-ors a Natural
with another Natural
in place, taking the Natural
on the
right-hand side by value.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
let mut x = Natural::ZERO;
x |= Natural::from(0x0000000fu32);
x |= Natural::from(0x00000f00u32);
x |= Natural::from(0x000f_0000u32);
x |= Natural::from(0x0f000000u32);
assert_eq!(x, 0x0f0f_0f0f);
source§impl<'a> BitScan for &'a Natural
impl<'a> BitScan for &'a Natural
source§fn index_of_next_false_bit(self, start: u64) -> Option<u64>
fn index_of_next_false_bit(self, start: u64) -> Option<u64>
Given a Natural
and a starting index, searches the Natural
for the smallest index of
a false
bit that is greater than or equal to the starting index.
Since every Natural
has an implicit prefix of infinitely-many zeros, this function
always returns a value.
Starting beyond the Natural
’s width is allowed; the result is the starting index.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::logic::traits::BitScan;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(0xb00000000u64).index_of_next_false_bit(0), Some(0));
assert_eq!(Natural::from(0xb00000000u64).index_of_next_false_bit(20), Some(20));
assert_eq!(Natural::from(0xb00000000u64).index_of_next_false_bit(31), Some(31));
assert_eq!(Natural::from(0xb00000000u64).index_of_next_false_bit(32), Some(34));
assert_eq!(Natural::from(0xb00000000u64).index_of_next_false_bit(33), Some(34));
assert_eq!(Natural::from(0xb00000000u64).index_of_next_false_bit(34), Some(34));
assert_eq!(Natural::from(0xb00000000u64).index_of_next_false_bit(35), Some(36));
assert_eq!(Natural::from(0xb00000000u64).index_of_next_false_bit(100), Some(100));
source§fn index_of_next_true_bit(self, start: u64) -> Option<u64>
fn index_of_next_true_bit(self, start: u64) -> Option<u64>
Given a Natural
and a starting index, searches the Natural
for the smallest index of
a true
bit that is greater than or equal to the starting index.
If the starting index is greater than or equal to the Natural
’s width, the result is
None
since there are no true
bits past that point.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::logic::traits::BitScan;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(0xb00000000u64).index_of_next_true_bit(0), Some(32));
assert_eq!(Natural::from(0xb00000000u64).index_of_next_true_bit(20), Some(32));
assert_eq!(Natural::from(0xb00000000u64).index_of_next_true_bit(31), Some(32));
assert_eq!(Natural::from(0xb00000000u64).index_of_next_true_bit(32), Some(32));
assert_eq!(Natural::from(0xb00000000u64).index_of_next_true_bit(33), Some(33));
assert_eq!(Natural::from(0xb00000000u64).index_of_next_true_bit(34), Some(35));
assert_eq!(Natural::from(0xb00000000u64).index_of_next_true_bit(35), Some(35));
assert_eq!(Natural::from(0xb00000000u64).index_of_next_true_bit(36), None);
assert_eq!(Natural::from(0xb00000000u64).index_of_next_true_bit(100), None);
source§impl<'a, 'b> BitXor<&'a Natural> for &'b Natural
impl<'a, 'b> BitXor<&'a Natural> for &'b Natural
source§fn bitxor(self, other: &'a Natural) -> Natural
fn bitxor(self, other: &'a Natural) -> Natural
Takes the bitwise xor of two Natural
s, taking both by reference.
$$ f(x, y) = x \oplus y. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_nz::natural::Natural;
assert_eq!(&Natural::from(123u32) ^ &Natural::from(456u32), 435);
assert_eq!(
&Natural::from(10u32).pow(12) ^ &(Natural::from(10u32).pow(12) - Natural::ONE),
8191
);
source§impl<'a> BitXor<&'a Natural> for Natural
impl<'a> BitXor<&'a Natural> for Natural
source§fn bitxor(self, other: &'a Natural) -> Natural
fn bitxor(self, other: &'a Natural) -> Natural
Takes the bitwise xor of two Natural
s, taking the first by value and the second by
reference.
$$ f(x, y) = x \oplus y. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(123u32) ^ &Natural::from(456u32), 435);
assert_eq!(
Natural::from(10u32).pow(12) ^ &(Natural::from(10u32).pow(12) - Natural::ONE),
8191
);
source§impl<'a> BitXor<Natural> for &'a Natural
impl<'a> BitXor<Natural> for &'a Natural
source§fn bitxor(self, other: Natural) -> Natural
fn bitxor(self, other: Natural) -> Natural
Takes the bitwise xor of two Natural
s, taking the first by reference and the second by
value.
$$ f(x, y) = x \oplus y. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_nz::natural::Natural;
assert_eq!(&Natural::from(123u32) ^ Natural::from(456u32), 435);
assert_eq!(
&Natural::from(10u32).pow(12) ^ (Natural::from(10u32).pow(12) - Natural::ONE),
8191
);
source§impl BitXor for Natural
impl BitXor for Natural
source§fn bitxor(self, other: Natural) -> Natural
fn bitxor(self, other: Natural) -> Natural
Takes the bitwise xor of two Natural
s, taking both by value.
$$ f(x, y) = x \oplus y. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(123u32) ^ Natural::from(456u32), 435);
assert_eq!(
Natural::from(10u32).pow(12) ^ (Natural::from(10u32).pow(12) - Natural::ONE),
8191
);
source§impl<'a> BitXorAssign<&'a Natural> for Natural
impl<'a> BitXorAssign<&'a Natural> for Natural
source§fn bitxor_assign(&mut self, other: &'a Natural)
fn bitxor_assign(&mut self, other: &'a Natural)
Bitwise-xors a Natural
with another Natural
in place, taking the Natural
on the
right-hand side by reference.
$$ x \gets x \oplus y. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
let mut x = Natural::ZERO;
x |= Natural::from(0x0000000fu32);
x |= Natural::from(0x00000f00u32);
x |= Natural::from(0x000f_0000u32);
x |= Natural::from(0x0f000000u32);
assert_eq!(x, 0x0f0f_0f0f);
source§impl BitXorAssign for Natural
impl BitXorAssign for Natural
source§fn bitxor_assign(&mut self, other: Natural)
fn bitxor_assign(&mut self, other: Natural)
Bitwise-xors a Natural
with another Natural
in place, taking the Natural
on the
right-hand side by value.
$$ x \gets x \oplus y. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
let mut x = Natural::ZERO;
x ^= Natural::from(0x0000000fu32);
x ^= Natural::from(0x00000f00u32);
x ^= Natural::from(0x000f_0000u32);
x ^= Natural::from(0x0f000000u32);
assert_eq!(x, 0x0f0f_0f0f);
source§impl<'a> CeilingDivAssignNegMod<&'a Natural> for Natural
impl<'a> CeilingDivAssignNegMod<&'a Natural> for Natural
source§fn ceiling_div_assign_neg_mod(&mut self, other: &'a Natural) -> Natural
fn ceiling_div_assign_neg_mod(&mut self, other: &'a Natural) -> Natural
Divides a Natural
by another Natural
in place, taking the Natural
on the
right-hand side by reference and returning the remainder of the negative of the first number
divided by the second.
The quotient and remainder satisfy $x = qy - r$ and $0 \leq r < y$.
$$ f(x, y) = y\left \lceil \frac{x}{y} \right \rceil - x, $$ $$ x \gets \left \lceil \frac{x}{y} \right \rceil. $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_base::num::arithmetic::traits::CeilingDivAssignNegMod;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 3 * 10 - 7 = 23
let mut x = Natural::from(23u32);
assert_eq!(x.ceiling_div_assign_neg_mod(&Natural::from(10u32)), 7);
assert_eq!(x, 3);
// 810000006724 * 1234567890987 - 704498996588 = 1000000000000000000000000
let mut x = Natural::from_str("1000000000000000000000000").unwrap();
assert_eq!(
x.ceiling_div_assign_neg_mod(&Natural::from_str("1234567890987").unwrap()),
704498996588u64,
);
assert_eq!(x, 810000006724u64);
type ModOutput = Natural
source§impl CeilingDivAssignNegMod for Natural
impl CeilingDivAssignNegMod for Natural
source§fn ceiling_div_assign_neg_mod(&mut self, other: Natural) -> Natural
fn ceiling_div_assign_neg_mod(&mut self, other: Natural) -> Natural
Divides a Natural
by another Natural
in place, taking the Natural
on the
right-hand side by value and returning the remainder of the negative of the first number
divided by the second.
The quotient and remainder satisfy $x = qy - r$ and $0 \leq r < y$.
$$ f(x, y) = y\left \lceil \frac{x}{y} \right \rceil - x, $$ $$ x \gets \left \lceil \frac{x}{y} \right \rceil. $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_base::num::arithmetic::traits::CeilingDivAssignNegMod;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 3 * 10 - 7 = 23
let mut x = Natural::from(23u32);
assert_eq!(x.ceiling_div_assign_neg_mod(Natural::from(10u32)), 7);
assert_eq!(x, 3);
// 810000006724 * 1234567890987 - 704498996588 = 1000000000000000000000000
let mut x = Natural::from_str("1000000000000000000000000").unwrap();
assert_eq!(
x.ceiling_div_assign_neg_mod(Natural::from_str("1234567890987").unwrap()),
704498996588u64,
);
assert_eq!(x, 810000006724u64);
type ModOutput = Natural
source§impl<'a, 'b> CeilingDivNegMod<&'b Natural> for &'a Natural
impl<'a, 'b> CeilingDivNegMod<&'b Natural> for &'a Natural
source§fn ceiling_div_neg_mod(self, other: &'b Natural) -> (Natural, Natural)
fn ceiling_div_neg_mod(self, other: &'b Natural) -> (Natural, Natural)
Divides a Natural
by another Natural
, taking both by reference and returning the
ceiling of the quotient and the remainder of the negative of the first Natural
divided
by the second.
The quotient and remainder satisfy $x = qy - r$ and $0 \leq r < y$.
$$ f(x, y) = \left ( \left \lceil \frac{x}{y} \right \rceil, \space y\left \lceil \frac{x}{y} \right \rceil - x \right ). $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_base::num::arithmetic::traits::CeilingDivNegMod;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 3 * 10 - 7 = 23
assert_eq!(
(&Natural::from(23u32)).ceiling_div_neg_mod(&Natural::from(10u32)).to_debug_string(),
"(3, 7)"
);
// 810000006724 * 1234567890987 - 704498996588 = 1000000000000000000000000
assert_eq!(
(&Natural::from_str("1000000000000000000000000").unwrap())
.ceiling_div_neg_mod(&Natural::from_str("1234567890987").unwrap())
.to_debug_string(),
"(810000006724, 704498996588)"
);
type DivOutput = Natural
type ModOutput = Natural
source§impl<'a> CeilingDivNegMod<&'a Natural> for Natural
impl<'a> CeilingDivNegMod<&'a Natural> for Natural
source§fn ceiling_div_neg_mod(self, other: &'a Natural) -> (Natural, Natural)
fn ceiling_div_neg_mod(self, other: &'a Natural) -> (Natural, Natural)
Divides a Natural
by another Natural
, taking the first by value and the second by
reference and returning the ceiling of the quotient and the remainder of the negative of the
first Natural
divided by the second.
The quotient and remainder satisfy $x = qy - r$ and $0 \leq r < y$.
$$ f(x, y) = \left ( \left \lceil \frac{x}{y} \right \rceil, \space y\left \lceil \frac{x}{y} \right \rceil - x \right ). $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_base::num::arithmetic::traits::CeilingDivNegMod;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 3 * 10 - 7 = 23
assert_eq!(
Natural::from(23u32).ceiling_div_neg_mod(&Natural::from(10u32)).to_debug_string(),
"(3, 7)"
);
// 810000006724 * 1234567890987 - 704498996588 = 1000000000000000000000000
assert_eq!(
Natural::from_str("1000000000000000000000000").unwrap()
.ceiling_div_neg_mod(&Natural::from_str("1234567890987").unwrap())
.to_debug_string(),
"(810000006724, 704498996588)"
);
type DivOutput = Natural
type ModOutput = Natural
source§impl<'a> CeilingDivNegMod<Natural> for &'a Natural
impl<'a> CeilingDivNegMod<Natural> for &'a Natural
source§fn ceiling_div_neg_mod(self, other: Natural) -> (Natural, Natural)
fn ceiling_div_neg_mod(self, other: Natural) -> (Natural, Natural)
Divides a Natural
by another Natural
, taking the first by reference and the second
by value and returning the ceiling of the quotient and the remainder of the negative of the
first Natural
divided by the second.
The quotient and remainder satisfy $x = qy - r$ and $0 \leq r < y$.
$$ f(x, y) = \left ( \left \lceil \frac{x}{y} \right \rceil, \space y\left \lceil \frac{x}{y} \right \rceil - x \right ). $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_base::num::arithmetic::traits::CeilingDivNegMod;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 3 * 10 - 7 = 23
assert_eq!(
(&Natural::from(23u32)).ceiling_div_neg_mod(Natural::from(10u32)).to_debug_string(),
"(3, 7)"
);
// 810000006724 * 1234567890987 - 704498996588 = 1000000000000000000000000
assert_eq!(
(&Natural::from_str("1000000000000000000000000").unwrap())
.ceiling_div_neg_mod(Natural::from_str("1234567890987").unwrap())
.to_debug_string(),
"(810000006724, 704498996588)"
);
type DivOutput = Natural
type ModOutput = Natural
source§impl CeilingDivNegMod for Natural
impl CeilingDivNegMod for Natural
source§fn ceiling_div_neg_mod(self, other: Natural) -> (Natural, Natural)
fn ceiling_div_neg_mod(self, other: Natural) -> (Natural, Natural)
Divides a Natural
by another Natural
, taking both by value and returning the ceiling
of the quotient and the remainder of the negative of the first Natural
divided by the
second.
The quotient and remainder satisfy $x = qy - r$ and $0 \leq r < y$.
$$ f(x, y) = \left ( \left \lceil \frac{x}{y} \right \rceil, \space y\left \lceil \frac{x}{y} \right \rceil - x \right ). $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_base::num::arithmetic::traits::CeilingDivNegMod;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 3 * 10 - 7 = 23
assert_eq!(
Natural::from(23u32).ceiling_div_neg_mod(Natural::from(10u32)).to_debug_string(),
"(3, 7)"
);
// 810000006724 * 1234567890987 - 704498996588 = 1000000000000000000000000
assert_eq!(
Natural::from_str("1000000000000000000000000").unwrap()
.ceiling_div_neg_mod(Natural::from_str("1234567890987").unwrap())
.to_debug_string(),
"(810000006724, 704498996588)"
);
type DivOutput = Natural
type ModOutput = Natural
source§impl<'a, 'b> CeilingLogBase<&'b Natural> for &'a Natural
impl<'a, 'b> CeilingLogBase<&'b Natural> for &'a Natural
source§fn ceiling_log_base(self, base: &Natural) -> u64
fn ceiling_log_base(self, base: &Natural) -> u64
Returns the ceiling of the base-$b$ logarithm of a positive Natural
.
$f(x, b) = \lceil\log_b x\rceil$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is x.significant_bits()
.
§Panics
Panics if self
is 0 or base
is less than 2.
§Examples
use malachite_base::num::arithmetic::traits::CeilingLogBase;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(80u32).ceiling_log_base(&Natural::from(3u32)), 4);
assert_eq!(Natural::from(81u32).ceiling_log_base(&Natural::from(3u32)), 4);
assert_eq!(Natural::from(82u32).ceiling_log_base(&Natural::from(3u32)), 5);
assert_eq!(Natural::from(4294967296u64).ceiling_log_base(&Natural::from(10u32)), 10);
This is equivalent to fmpz_clog
from fmpz/clog.c
, FLINT 2.7.1.
type Output = u64
source§impl<'a> CeilingLogBase2 for &'a Natural
impl<'a> CeilingLogBase2 for &'a Natural
source§fn ceiling_log_base_2(self) -> u64
fn ceiling_log_base_2(self) -> u64
Returns the ceiling of the base-2 logarithm of a positive Natural
.
$f(x) = \lceil\log_2 x\rceil$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if self
is 0.
§Examples
use malachite_base::num::arithmetic::traits::CeilingLogBase2;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(3u32).ceiling_log_base_2(), 2);
assert_eq!(Natural::from(100u32).ceiling_log_base_2(), 7);
type Output = u64
source§impl<'a> CeilingLogBasePowerOf2<u64> for &'a Natural
impl<'a> CeilingLogBasePowerOf2<u64> for &'a Natural
source§fn ceiling_log_base_power_of_2(self, pow: u64) -> u64
fn ceiling_log_base_power_of_2(self, pow: u64) -> u64
Returns the ceiling of the base-$2^k$ logarithm of a positive Natural
.
$f(x, k) = \lceil\log_{2^k} x\rceil$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if self
is 0 or pow
is 0.
§Examples
use malachite_base::num::arithmetic::traits::CeilingLogBasePowerOf2;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(100u32).ceiling_log_base_power_of_2(2), 4);
assert_eq!(Natural::from(4294967296u64).ceiling_log_base_power_of_2(8), 4);
type Output = u64
source§impl<'a> CeilingRoot<u64> for &'a Natural
impl<'a> CeilingRoot<u64> for &'a Natural
source§fn ceiling_root(self, exp: u64) -> Natural
fn ceiling_root(self, exp: u64) -> Natural
Returns the ceiling of the $n$th root of a Natural
, taking the Natural
by reference.
$f(x, n) = \lceil\sqrt[n]{x}\rceil$.
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if exp
is zero.
§Examples
use malachite_base::num::arithmetic::traits::CeilingRoot;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(999u16).ceiling_root(3), 10);
assert_eq!(Natural::from(1000u16).ceiling_root(3), 10);
assert_eq!(Natural::from(1001u16).ceiling_root(3), 11);
assert_eq!(Natural::from(100000000000u64).ceiling_root(5), 159);
type Output = Natural
source§impl CeilingRoot<u64> for Natural
impl CeilingRoot<u64> for Natural
source§fn ceiling_root(self, exp: u64) -> Natural
fn ceiling_root(self, exp: u64) -> Natural
Returns the ceiling of the $n$th root of a Natural
, taking the Natural
by value.
$f(x, n) = \lceil\sqrt[n]{x}\rceil$.
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if exp
is zero.
§Examples
use malachite_base::num::arithmetic::traits::CeilingRoot;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(999u16).ceiling_root(3), 10);
assert_eq!(Natural::from(1000u16).ceiling_root(3), 10);
assert_eq!(Natural::from(1001u16).ceiling_root(3), 11);
assert_eq!(Natural::from(100000000000u64).ceiling_root(5), 159);
type Output = Natural
source§impl CeilingRootAssign<u64> for Natural
impl CeilingRootAssign<u64> for Natural
source§fn ceiling_root_assign(&mut self, exp: u64)
fn ceiling_root_assign(&mut self, exp: u64)
Replaces a Natural
with the ceiling of its $n$th root.
$x \gets \lceil\sqrt[n]{x}\rceil$.
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if exp
is zero.
§Examples
use malachite_base::num::arithmetic::traits::CeilingRootAssign;
use malachite_nz::natural::Natural;
let mut x = Natural::from(999u16);
x.ceiling_root_assign(3);
assert_eq!(x, 10);
let mut x = Natural::from(1000u16);
x.ceiling_root_assign(3);
assert_eq!(x, 10);
let mut x = Natural::from(1001u16);
x.ceiling_root_assign(3);
assert_eq!(x, 11);
let mut x = Natural::from(100000000000u64);
x.ceiling_root_assign(5);
assert_eq!(x, 159);
source§impl<'a> CeilingSqrt for &'a Natural
impl<'a> CeilingSqrt for &'a Natural
source§fn ceiling_sqrt(self) -> Natural
fn ceiling_sqrt(self) -> Natural
Returns the ceiling of the square root of a Natural
, taking it by value.
$f(x) = \lceil\sqrt{x}\rceil$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::CeilingSqrt;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(99u8).ceiling_sqrt(), 10);
assert_eq!(Natural::from(100u8).ceiling_sqrt(), 10);
assert_eq!(Natural::from(101u8).ceiling_sqrt(), 11);
assert_eq!(Natural::from(1000000000u32).ceiling_sqrt(), 31623);
assert_eq!(Natural::from(10000000000u64).ceiling_sqrt(), 100000);
type Output = Natural
source§impl CeilingSqrt for Natural
impl CeilingSqrt for Natural
source§fn ceiling_sqrt(self) -> Natural
fn ceiling_sqrt(self) -> Natural
Returns the ceiling of the square root of a Natural
, taking it by value.
$f(x) = \lceil\sqrt{x}\rceil$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::CeilingSqrt;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(99u8).ceiling_sqrt(), 10);
assert_eq!(Natural::from(100u8).ceiling_sqrt(), 10);
assert_eq!(Natural::from(101u8).ceiling_sqrt(), 11);
assert_eq!(Natural::from(1000000000u32).ceiling_sqrt(), 31623);
assert_eq!(Natural::from(10000000000u64).ceiling_sqrt(), 100000);
type Output = Natural
source§impl CeilingSqrtAssign for Natural
impl CeilingSqrtAssign for Natural
source§fn ceiling_sqrt_assign(&mut self)
fn ceiling_sqrt_assign(&mut self)
Replaces a Natural
with the ceiling of its square root.
$x \gets \lceil\sqrt{x}\rceil$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::CeilingSqrtAssign;
use malachite_nz::natural::Natural;
let mut x = Natural::from(99u8);
x.ceiling_sqrt_assign();
assert_eq!(x, 10);
let mut x = Natural::from(100u8);
x.ceiling_sqrt_assign();
assert_eq!(x, 10);
let mut x = Natural::from(101u8);
x.ceiling_sqrt_assign();
assert_eq!(x, 11);
let mut x = Natural::from(1000000000u32);
x.ceiling_sqrt_assign();
assert_eq!(x, 31623);
let mut x = Natural::from(10000000000u64);
x.ceiling_sqrt_assign();
assert_eq!(x, 100000);
source§impl<'a, 'b> CheckedDiv<&'b Natural> for &'a Natural
impl<'a, 'b> CheckedDiv<&'b Natural> for &'a Natural
source§fn checked_div(self, other: &'b Natural) -> Option<Natural>
fn checked_div(self, other: &'b Natural) -> Option<Natural>
Divides a Natural
by another Natural
, taking both by reference. The quotient is
rounded towards negative infinity. The quotient and remainder (which is not computed)
satisfy $x = qy + r$ and $0 \leq r < y$. Returns None
when the second Natural
is zero,
Some
otherwise.
$$ f(x, y) = \begin{cases} \operatorname{Some}\left ( \left \lfloor \frac{x}{y} \right \rfloor \right ) & \text{if} \quad y \neq 0 \\ \text{None} & \text{otherwise} \end{cases} $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_base::num::arithmetic::traits::CheckedDiv;
use malachite_base::num::basic::traits::{One, Zero};
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
// 2 * 10 + 3 = 23
assert_eq!(
(&Natural::from(23u32)).checked_div(&Natural::from(10u32)).to_debug_string(),
"Some(2)"
);
assert_eq!((&Natural::ONE).checked_div(&Natural::ZERO), None);
type Output = Natural
source§impl<'a> CheckedDiv<&'a Natural> for Natural
impl<'a> CheckedDiv<&'a Natural> for Natural
source§fn checked_div(self, other: &'a Natural) -> Option<Natural>
fn checked_div(self, other: &'a Natural) -> Option<Natural>
Divides a Natural
by another Natural
, taking the first by value and the second by
reference. The quotient is rounded towards negative infinity. The quotient and remainder
(which is not computed) satisfy $x = qy + r$ and $0 \leq r < y$. Returns None
when the
second Natural
is zero, Some
otherwise.
$$ f(x, y) = \begin{cases} \operatorname{Some}\left ( \left \lfloor \frac{x}{y} \right \rfloor \right ) & \text{if} \quad y \neq 0 \\ \text{None} & \text{otherwise} \end{cases} $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_base::num::arithmetic::traits::CheckedDiv;
use malachite_base::num::basic::traits::{One, Zero};
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
// 2 * 10 + 3 = 23
assert_eq!(
Natural::from(23u32).checked_div(&Natural::from(10u32)).to_debug_string(),
"Some(2)"
);
assert_eq!(Natural::ONE.checked_div(&Natural::ZERO), None);
type Output = Natural
source§impl<'a> CheckedDiv<Natural> for &'a Natural
impl<'a> CheckedDiv<Natural> for &'a Natural
source§fn checked_div(self, other: Natural) -> Option<Natural>
fn checked_div(self, other: Natural) -> Option<Natural>
Divides a Natural
by another Natural
, taking the first by reference and the second
by value. The quotient is rounded towards negative infinity. The quotient and remainder
(which is not computed) satisfy $x = qy + r$ and $0 \leq r < y$. Returns None
when the
second Natural
is zero, Some
otherwise.
$$ f(x, y) = \begin{cases} \operatorname{Some}\left ( \left \lfloor \frac{x}{y} \right \rfloor \right ) & \text{if} \quad y \neq 0 \\ \text{None} & \text{otherwise} \end{cases} $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_base::num::arithmetic::traits::CheckedDiv;
use malachite_base::num::basic::traits::{One, Zero};
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
// 2 * 10 + 3 = 23
assert_eq!(
(&Natural::from(23u32)).checked_div(Natural::from(10u32)).to_debug_string(),
"Some(2)"
);
assert_eq!((&Natural::ONE).checked_div(Natural::ZERO), None);
type Output = Natural
source§impl CheckedDiv for Natural
impl CheckedDiv for Natural
source§fn checked_div(self, other: Natural) -> Option<Natural>
fn checked_div(self, other: Natural) -> Option<Natural>
Divides a Natural
by another Natural
, taking both by value. The quotient is rounded
towards negative infinity. The quotient and remainder (which is not computed) satisfy $x =
qy + r$ and $0 \leq r < y$. Returns None
when the second Natural
is zero, Some
otherwise.
$$ f(x, y) = \begin{cases} \operatorname{Some}\left ( \left \lfloor \frac{x}{y} \right \rfloor \right ) & \text{if} \quad y \neq 0 \\ \text{None} & \text{otherwise} \end{cases} $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_base::num::arithmetic::traits::CheckedDiv;
use malachite_base::num::basic::traits::{One, Zero};
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
// 2 * 10 + 3 = 23
assert_eq!(
Natural::from(23u32).checked_div(Natural::from(10u32)).to_debug_string(),
"Some(2)"
);
assert_eq!(Natural::ONE.checked_div(Natural::ZERO), None);
type Output = Natural
source§impl<'a, 'b> CheckedLogBase<&'b Natural> for &'a Natural
impl<'a, 'b> CheckedLogBase<&'b Natural> for &'a Natural
source§fn checked_log_base(self, base: &Natural) -> Option<u64>
fn checked_log_base(self, base: &Natural) -> Option<u64>
Returns the base-$b$ logarithm of a positive Natural
. If the Natural
is not a power
of $b$, then None
is returned.
$$ f(x, b) = \begin{cases} \operatorname{Some}(\log_b x) & \text{if} \quad \log_b x \in \Z, \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is x.significant_bits()
.
§Panics
Panics if self
is 0 or base
is less than 2.
§Examples
use malachite_base::num::arithmetic::traits::CheckedLogBase;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(80u32).checked_log_base(&Natural::from(3u32)), None);
assert_eq!(Natural::from(81u32).checked_log_base(&Natural::from(3u32)), Some(4));
assert_eq!(Natural::from(82u32).checked_log_base(&Natural::from(3u32)), None);
assert_eq!(Natural::from(4294967296u64).checked_log_base(&Natural::from(10u32)), None);
type Output = u64
source§impl<'a> CheckedLogBase2 for &'a Natural
impl<'a> CheckedLogBase2 for &'a Natural
source§fn checked_log_base_2(self) -> Option<u64>
fn checked_log_base_2(self) -> Option<u64>
Returns the base-2 logarithm of a positive Natural
. If the Natural
is not a power of
2, then None
is returned.
$$ f(x) = \begin{cases} \operatorname{Some}(\log_2 x) & \text{if} \quad \log_2 x \in \Z, \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if self
is 0.
§Examples
use malachite_base::num::arithmetic::traits::CheckedLogBase2;
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!(Natural::from(3u32).checked_log_base_2(), None);
assert_eq!(Natural::from(4u32).checked_log_base_2(), Some(2));
assert_eq!(
Natural::from_str("1267650600228229401496703205376").unwrap().checked_log_base_2(),
Some(100)
);
type Output = u64
source§impl<'a> CheckedLogBasePowerOf2<u64> for &'a Natural
impl<'a> CheckedLogBasePowerOf2<u64> for &'a Natural
source§fn checked_log_base_power_of_2(self, pow: u64) -> Option<u64>
fn checked_log_base_power_of_2(self, pow: u64) -> Option<u64>
Returns the base-$2^k$ logarithm of a positive Natural
. If the Natural
is not a
power of $2^k$, then None
is returned.
$$ f(x, k) = \begin{cases} \operatorname{Some}(\log_{2^k} x) & \text{if} \quad \log_{2^k} x \in \Z, \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if self
is 0 or pow
is 0.
§Examples
use malachite_base::num::arithmetic::traits::CheckedLogBasePowerOf2;
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!(Natural::from(100u32).checked_log_base_power_of_2(2), None);
assert_eq!(Natural::from(4294967296u64).checked_log_base_power_of_2(8), Some(4));
type Output = u64
source§impl<'a> CheckedRoot<u64> for &'a Natural
impl<'a> CheckedRoot<u64> for &'a Natural
source§fn checked_root(self, exp: u64) -> Option<Natural>
fn checked_root(self, exp: u64) -> Option<Natural>
Returns the the $n$th root of a Natural
, or None
if the Natural
is not a perfect
$n$th power. The Natural
is taken by reference.
$$ f(x, n) = \begin{cases} \operatorname{Some}(sqrt[n]{x}) & \text{if} \quad \sqrt[n]{x} \in \Z, \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if exp
is zero.
§Examples
use malachite_base::num::arithmetic::traits::CheckedRoot;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::from(999u16)).checked_root(3).to_debug_string(), "None");
assert_eq!((&Natural::from(1000u16)).checked_root(3).to_debug_string(), "Some(10)");
assert_eq!((&Natural::from(1001u16)).checked_root(3).to_debug_string(), "None");
assert_eq!((&Natural::from(100000000000u64)).checked_root(5).to_debug_string(), "None");
assert_eq!(
(&Natural::from(10000000000u64)).checked_root(5).to_debug_string(),
"Some(100)"
);
type Output = Natural
source§impl CheckedRoot<u64> for Natural
impl CheckedRoot<u64> for Natural
source§fn checked_root(self, exp: u64) -> Option<Natural>
fn checked_root(self, exp: u64) -> Option<Natural>
Returns the the $n$th root of a Natural
, or None
if the Natural
is not a perfect
$n$th power. The Natural
is taken by value.
$$ f(x, n) = \begin{cases} \operatorname{Some}(sqrt[n]{x}) & \text{if} \quad \sqrt[n]{x} \in \Z, \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if exp
is zero.
§Examples
use malachite_base::num::arithmetic::traits::CheckedRoot;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(999u16).checked_root(3).to_debug_string(), "None");
assert_eq!(Natural::from(1000u16).checked_root(3).to_debug_string(), "Some(10)");
assert_eq!(Natural::from(1001u16).checked_root(3).to_debug_string(), "None");
assert_eq!(Natural::from(100000000000u64).checked_root(5).to_debug_string(), "None");
assert_eq!(Natural::from(10000000000u64).checked_root(5).to_debug_string(), "Some(100)");
type Output = Natural
source§impl<'a> CheckedSqrt for &'a Natural
impl<'a> CheckedSqrt for &'a Natural
source§fn checked_sqrt(self) -> Option<Natural>
fn checked_sqrt(self) -> Option<Natural>
Returns the the square root of a Natural
, or None
if it is not a perfect square. The
Natural
is taken by value.
$$ f(x) = \begin{cases} \operatorname{Some}(sqrt{x}) & \text{if} \quad \sqrt{x} \in \Z, \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::CheckedSqrt;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::from(99u8)).checked_sqrt().to_debug_string(), "None");
assert_eq!((&Natural::from(100u8)).checked_sqrt().to_debug_string(), "Some(10)");
assert_eq!((&Natural::from(101u8)).checked_sqrt().to_debug_string(), "None");
assert_eq!((&Natural::from(1000000000u32)).checked_sqrt().to_debug_string(), "None");
assert_eq!(
(&Natural::from(10000000000u64)).checked_sqrt().to_debug_string(),
"Some(100000)"
);
type Output = Natural
source§impl CheckedSqrt for Natural
impl CheckedSqrt for Natural
source§fn checked_sqrt(self) -> Option<Natural>
fn checked_sqrt(self) -> Option<Natural>
Returns the the square root of a Natural
, or None
if it is not a perfect square. The
Natural
is taken by value.
$$ f(x) = \begin{cases} \operatorname{Some}(sqrt{x}) & \text{if} \quad \sqrt{x} \in \Z, \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::CheckedSqrt;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(99u8).checked_sqrt().to_debug_string(), "None");
assert_eq!(Natural::from(100u8).checked_sqrt().to_debug_string(), "Some(10)");
assert_eq!(Natural::from(101u8).checked_sqrt().to_debug_string(), "None");
assert_eq!(Natural::from(1000000000u32).checked_sqrt().to_debug_string(), "None");
assert_eq!(Natural::from(10000000000u64).checked_sqrt().to_debug_string(), "Some(100000)");
type Output = Natural
source§impl<'a, 'b> CheckedSub<&'a Natural> for &'b Natural
impl<'a, 'b> CheckedSub<&'a Natural> for &'b Natural
source§fn checked_sub(self, other: &'a Natural) -> Option<Natural>
fn checked_sub(self, other: &'a Natural) -> Option<Natural>
Subtracts a Natural
by another Natural
, taking both by reference and returning
None
if the result is negative.
$$ f(x, y) = \begin{cases} \operatorname{Some}(x - y) & \text{if} \quad x \geq y, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::{CheckedSub, Pow};
use malachite_base::num::basic::traits::Zero;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::ZERO).checked_sub(&Natural::from(123u32)).to_debug_string(), "None");
assert_eq!((&Natural::from(123u32)).checked_sub(&Natural::ZERO).to_debug_string(),
"Some(123)");
assert_eq!((&Natural::from(456u32)).checked_sub(&Natural::from(123u32)).to_debug_string(),
"Some(333)");
assert_eq!(
(&(Natural::from(10u32).pow(12) * Natural::from(3u32)))
.checked_sub(&Natural::from(10u32).pow(12)).to_debug_string(),
"Some(2000000000000)"
);
type Output = Natural
source§impl<'a> CheckedSub<&'a Natural> for Natural
impl<'a> CheckedSub<&'a Natural> for Natural
source§fn checked_sub(self, other: &'a Natural) -> Option<Natural>
fn checked_sub(self, other: &'a Natural) -> Option<Natural>
Subtracts a Natural
by another Natural
, taking the first by value and the second by
reference and returning None
if the result is negative.
$$ f(x, y) = \begin{cases} \operatorname{Some}(x - y) & \text{if} \quad x \geq y, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::{CheckedSub, Pow};
use malachite_base::num::basic::traits::Zero;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
assert_eq!(Natural::ZERO.checked_sub(&Natural::from(123u32)).to_debug_string(), "None");
assert_eq!(
Natural::from(123u32).checked_sub(&Natural::ZERO).to_debug_string(),
"Some(123)"
);
assert_eq!(Natural::from(456u32).checked_sub(&Natural::from(123u32)).to_debug_string(),
"Some(333)");
assert_eq!(
(Natural::from(10u32).pow(12) * Natural::from(3u32))
.checked_sub(&Natural::from(10u32).pow(12)).to_debug_string(),
"Some(2000000000000)"
);
type Output = Natural
source§impl<'a> CheckedSub<Natural> for &'a Natural
impl<'a> CheckedSub<Natural> for &'a Natural
source§fn checked_sub(self, other: Natural) -> Option<Natural>
fn checked_sub(self, other: Natural) -> Option<Natural>
Subtracts a Natural
by another Natural
, taking the first by reference and the second
by value and returning None
if the result is negative.
$$ f(x, y) = \begin{cases} \operatorname{Some}(x - y) & \text{if} \quad x \geq y, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::{CheckedSub, Pow};
use malachite_base::num::basic::traits::Zero;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::ZERO).checked_sub(Natural::from(123u32)).to_debug_string(), "None");
assert_eq!((&Natural::from(123u32)).checked_sub(Natural::ZERO).to_debug_string(),
"Some(123)");
assert_eq!((&Natural::from(456u32)).checked_sub(Natural::from(123u32)).to_debug_string(),
"Some(333)");
assert_eq!(
(&(Natural::from(10u32).pow(12) * Natural::from(3u32)))
.checked_sub(Natural::from(10u32).pow(12)).to_debug_string(),
"Some(2000000000000)"
);
type Output = Natural
source§impl CheckedSub for Natural
impl CheckedSub for Natural
source§fn checked_sub(self, other: Natural) -> Option<Natural>
fn checked_sub(self, other: Natural) -> Option<Natural>
Subtracts a Natural
by another Natural
, taking both by value and returning None
if
the result is negative.
$$ f(x, y) = \begin{cases} \operatorname{Some}(x - y) & \text{if} \quad x \geq y, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::{CheckedSub, Pow};
use malachite_base::num::basic::traits::Zero;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
assert_eq!(Natural::ZERO.checked_sub(Natural::from(123u32)).to_debug_string(), "None");
assert_eq!(
Natural::from(123u32).checked_sub(Natural::ZERO).to_debug_string(),
"Some(123)"
);
assert_eq!(
Natural::from(456u32).checked_sub(Natural::from(123u32)).to_debug_string(),
"Some(333)"
);
assert_eq!(
(Natural::from(10u32).pow(12) * Natural::from(3u32))
.checked_sub(Natural::from(10u32).pow(12)).to_debug_string(),
"Some(2000000000000)"
);
type Output = Natural
source§impl<'a> CheckedSubMul<&'a Natural> for Natural
impl<'a> CheckedSubMul<&'a Natural> for Natural
source§fn checked_sub_mul(self, y: &'a Natural, z: Natural) -> Option<Natural>
fn checked_sub_mul(self, y: &'a Natural, z: Natural) -> Option<Natural>
Subtracts a Natural
by the product of two other Natural
s, taking the first and third
by value and the second by reference and returning None
if the result is negative.
$$ f(x, y, z) = \begin{cases} \operatorname{Some}(x - yz) & \text{if} \quad x \geq yz, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
§Worst-case complexity
$T(n, m) = O(m + n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is max(y.significant_bits(), z.significant_bits())
, and $m$ is self.significant_bits()
.
§Panics
Panics if y * z
is greater than self
.
§Examples
use malachite_base::num::arithmetic::traits::{CheckedSubMul, Pow};
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
assert_eq!(
Natural::from(20u32).checked_sub_mul(&Natural::from(3u32), Natural::from(4u32))
.to_debug_string(),
"Some(8)"
);
assert_eq!(
Natural::from(10u32).checked_sub_mul(&Natural::from(3u32), Natural::from(4u32))
.to_debug_string(),
"None"
);
assert_eq!(
Natural::from(10u32).pow(12)
.checked_sub_mul(&Natural::from(0x10000u32), Natural::from(0x10000u32))
.to_debug_string(),
"Some(995705032704)"
);
type Output = Natural
source§impl<'a, 'b, 'c> CheckedSubMul<&'a Natural, &'b Natural> for &'c Natural
impl<'a, 'b, 'c> CheckedSubMul<&'a Natural, &'b Natural> for &'c Natural
source§fn checked_sub_mul(self, y: &'a Natural, z: &'b Natural) -> Option<Natural>
fn checked_sub_mul(self, y: &'a Natural, z: &'b Natural) -> Option<Natural>
Subtracts a Natural
by the product of two other Natural
s, taking all three by
reference and returning None
if the result is negative.
$$ f(x, y, z) = \begin{cases} \operatorname{Some}(x - yz) & \text{if} \quad x \geq yz, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
§Worst-case complexity
$T(n, m) = O(m + n \log n \log\log n)$
$M(n, m) = O(m + n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is max(y.significant_bits(), z.significant_bits())
, and $m$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::{CheckedSubMul, Pow};
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
assert_eq!(
(&Natural::from(20u32)).checked_sub_mul(&Natural::from(3u32), &Natural::from(4u32))
.to_debug_string(),
"Some(8)"
);
assert_eq!(
(&Natural::from(10u32)).checked_sub_mul(&Natural::from(3u32), &Natural::from(4u32))
.to_debug_string(),
"None"
);
assert_eq!(
(&Natural::from(10u32).pow(12))
.checked_sub_mul(&Natural::from(0x10000u32), &Natural::from(0x10000u32))
.to_debug_string(),
"Some(995705032704)"
);
type Output = Natural
source§impl<'a, 'b> CheckedSubMul<&'a Natural, &'b Natural> for Natural
impl<'a, 'b> CheckedSubMul<&'a Natural, &'b Natural> for Natural
source§fn checked_sub_mul(self, y: &'a Natural, z: &'b Natural) -> Option<Natural>
fn checked_sub_mul(self, y: &'a Natural, z: &'b Natural) -> Option<Natural>
Subtracts a Natural
by the product of two other Natural
s, taking the first by value
and the second and third by reference and returning None
if the result is negative.
$$ f(x, y, z) = \begin{cases} \operatorname{Some}(x - yz) & \text{if} \quad x \geq yz, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
§Worst-case complexity
$T(n, m) = O(m + n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is max(y.significant_bits(), z.significant_bits())
, and $m$ is self.significant_bits()
.
§Panics
Panics if y * z
is greater than self
.
§Examples
use malachite_base::num::arithmetic::traits::{CheckedSubMul, Pow};
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
assert_eq!(
Natural::from(20u32).checked_sub_mul(&Natural::from(3u32), &Natural::from(4u32))
.to_debug_string(),
"Some(8)"
);
assert_eq!(
Natural::from(10u32).checked_sub_mul(&Natural::from(3u32), &Natural::from(4u32))
.to_debug_string(),
"None"
);
assert_eq!(
Natural::from(10u32).pow(12)
.checked_sub_mul(&Natural::from(0x10000u32), &Natural::from(0x10000u32))
.to_debug_string(),
"Some(995705032704)"
);
type Output = Natural
source§impl<'a> CheckedSubMul<Natural, &'a Natural> for Natural
impl<'a> CheckedSubMul<Natural, &'a Natural> for Natural
source§fn checked_sub_mul(self, y: Natural, z: &'a Natural) -> Option<Natural>
fn checked_sub_mul(self, y: Natural, z: &'a Natural) -> Option<Natural>
Subtracts a Natural
by the product of two other Natural
s, taking the first two by
value and the third by reference and returning None
if the result is negative.
$$ f(x, y, z) = \begin{cases} \operatorname{Some}(x - yz) & \text{if} \quad x \geq yz, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
§Worst-case complexity
$T(n, m) = O(m + n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is max(y.significant_bits(), z.significant_bits())
, and $m$ is self.significant_bits()
.
§Panics
Panics if y * z
is greater than self
.
§Examples
use malachite_base::num::arithmetic::traits::{CheckedSubMul, Pow};
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
assert_eq!(
Natural::from(20u32).checked_sub_mul(Natural::from(3u32), &Natural::from(4u32))
.to_debug_string(),
"Some(8)"
);
assert_eq!(
Natural::from(10u32).checked_sub_mul(Natural::from(3u32), &Natural::from(4u32))
.to_debug_string(),
"None"
);
assert_eq!(
Natural::from(10u32).pow(12)
.checked_sub_mul(Natural::from(0x10000u32), &Natural::from(0x10000u32))
.to_debug_string(),
"Some(995705032704)"
);
type Output = Natural
source§impl CheckedSubMul for Natural
impl CheckedSubMul for Natural
source§fn checked_sub_mul(self, y: Natural, z: Natural) -> Option<Natural>
fn checked_sub_mul(self, y: Natural, z: Natural) -> Option<Natural>
Subtracts a Natural
by the product of two other Natural
s, taking all three by value
and returning None
if the result is negative.
$$ f(x, y, z) = \begin{cases} \operatorname{Some}(x - yz) & \text{if} \quad x \geq yz, \\ \operatorname{None} & \text{otherwise}. \end{cases} $$
§Worst-case complexity
$T(n, m) = O(m + n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is max(y.significant_bits(), z.significant_bits())
, and $m$ is self.significant_bits()
.
§Panics
Panics if y * z
is greater than self
.
§Examples
use malachite_base::num::arithmetic::traits::{CheckedSubMul, Pow};
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
assert_eq!(
Natural::from(20u32).checked_sub_mul(Natural::from(3u32), Natural::from(4u32))
.to_debug_string(),
"Some(8)"
);
assert_eq!(
Natural::from(10u32).checked_sub_mul(Natural::from(3u32), Natural::from(4u32))
.to_debug_string(),
"None"
);
assert_eq!(
Natural::from(10u32).pow(12)
.checked_sub_mul(Natural::from(0x10000u32), Natural::from(0x10000u32))
.to_debug_string(),
"Some(995705032704)"
);
type Output = Natural
source§impl<'a> ConvertibleFrom<&'a Integer> for Natural
impl<'a> ConvertibleFrom<&'a Integer> for Natural
source§fn convertible_from(value: &'a Integer) -> bool
fn convertible_from(value: &'a Integer) -> bool
Determines whether an Integer
can be converted to a Natural
(when the Integer
is
non-negative). Takes the Integer
by reference.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::conversion::traits::ConvertibleFrom;
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;
assert_eq!(Natural::convertible_from(&Integer::from(123)), true);
assert_eq!(Natural::convertible_from(&Integer::from(-123)), false);
assert_eq!(Natural::convertible_from(&Integer::from(10u32).pow(12)), true);
assert_eq!(Natural::convertible_from(&-Integer::from(10u32).pow(12)), false);
source§impl<'a> ConvertibleFrom<&'a Natural> for f32
impl<'a> ConvertibleFrom<&'a Natural> for f32
source§impl<'a> ConvertibleFrom<&'a Natural> for f64
impl<'a> ConvertibleFrom<&'a Natural> for f64
source§impl<'a> ConvertibleFrom<&'a Natural> for i128
impl<'a> ConvertibleFrom<&'a Natural> for i128
source§impl<'a> ConvertibleFrom<&'a Natural> for i16
impl<'a> ConvertibleFrom<&'a Natural> for i16
source§impl<'a> ConvertibleFrom<&'a Natural> for i32
impl<'a> ConvertibleFrom<&'a Natural> for i32
source§impl<'a> ConvertibleFrom<&'a Natural> for i64
impl<'a> ConvertibleFrom<&'a Natural> for i64
source§impl<'a> ConvertibleFrom<&'a Natural> for i8
impl<'a> ConvertibleFrom<&'a Natural> for i8
source§impl<'a> ConvertibleFrom<&'a Natural> for isize
impl<'a> ConvertibleFrom<&'a Natural> for isize
source§impl<'a> ConvertibleFrom<&'a Natural> for u128
impl<'a> ConvertibleFrom<&'a Natural> for u128
source§impl<'a> ConvertibleFrom<&'a Natural> for u16
impl<'a> ConvertibleFrom<&'a Natural> for u16
source§impl<'a> ConvertibleFrom<&'a Natural> for u32
impl<'a> ConvertibleFrom<&'a Natural> for u32
source§impl<'a> ConvertibleFrom<&'a Natural> for u64
impl<'a> ConvertibleFrom<&'a Natural> for u64
source§impl<'a> ConvertibleFrom<&'a Natural> for u8
impl<'a> ConvertibleFrom<&'a Natural> for u8
source§impl<'a> ConvertibleFrom<&'a Natural> for usize
impl<'a> ConvertibleFrom<&'a Natural> for usize
source§impl ConvertibleFrom<Integer> for Natural
impl ConvertibleFrom<Integer> for Natural
source§fn convertible_from(value: Integer) -> bool
fn convertible_from(value: Integer) -> bool
Determines whether an Integer
can be converted to a Natural
(when the Integer
is
non-negative). Takes the Integer
by value.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::conversion::traits::ConvertibleFrom;
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;
assert_eq!(Natural::convertible_from(Integer::from(123)), true);
assert_eq!(Natural::convertible_from(Integer::from(-123)), false);
assert_eq!(Natural::convertible_from(Integer::from(10u32).pow(12)), true);
assert_eq!(Natural::convertible_from(-Integer::from(10u32).pow(12)), false);
source§impl ConvertibleFrom<f32> for Natural
impl ConvertibleFrom<f32> for Natural
source§impl ConvertibleFrom<f64> for Natural
impl ConvertibleFrom<f64> for Natural
source§impl ConvertibleFrom<i128> for Natural
impl ConvertibleFrom<i128> for Natural
source§impl ConvertibleFrom<i16> for Natural
impl ConvertibleFrom<i16> for Natural
source§impl ConvertibleFrom<i32> for Natural
impl ConvertibleFrom<i32> for Natural
source§impl ConvertibleFrom<i64> for Natural
impl ConvertibleFrom<i64> for Natural
source§impl ConvertibleFrom<i8> for Natural
impl ConvertibleFrom<i8> for Natural
source§impl ConvertibleFrom<isize> for Natural
impl ConvertibleFrom<isize> for Natural
source§impl<'a, 'b> CoprimeWith<&'b Natural> for &'a Natural
impl<'a, 'b> CoprimeWith<&'b Natural> for &'a Natural
source§fn coprime_with(self, other: &'b Natural) -> bool
fn coprime_with(self, other: &'b Natural) -> bool
Returns whether two Natural
s are coprime; that is, whether they have no common factor
other than 1. Both Natural
s are taken by reference.
Every Natural
is coprime with 1. No Natural
is coprime with 0, except 1.
$f(x, y) = (\gcd(x, y) = 1)$.
$f(x, y) = ((k,m,n \in \N \land x=km \land y=kn) \implies k=1)$.
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::CoprimeWith;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::from(3u32)).coprime_with(Natural::from(5u32)), true);
assert_eq!((&Natural::from(12u32)).coprime_with(Natural::from(90u32)), false);
source§impl<'a> CoprimeWith<&'a Natural> for Natural
impl<'a> CoprimeWith<&'a Natural> for Natural
source§fn coprime_with(self, other: &'a Natural) -> bool
fn coprime_with(self, other: &'a Natural) -> bool
Returns whether two Natural
s are coprime; that is, whether they have no common factor
other than 1. The first Natural
is taken by value and the second by reference.
Every Natural
is coprime with 1. No Natural
is coprime with 0, except 1.
$f(x, y) = (\gcd(x, y) = 1)$.
$f(x, y) = ((k,m,n \in \N \land x=km \land y=kn) \implies k=1)$.
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::CoprimeWith;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(3u32).coprime_with(&Natural::from(5u32)), true);
assert_eq!(Natural::from(12u32).coprime_with(&Natural::from(90u32)), false);
source§impl<'a> CoprimeWith<Natural> for &'a Natural
impl<'a> CoprimeWith<Natural> for &'a Natural
source§fn coprime_with(self, other: Natural) -> bool
fn coprime_with(self, other: Natural) -> bool
Returns whether two Natural
s are coprime; that is, whether they have no common factor
other than 1. The first Natural
is taken by reference and the second by value.
Every Natural
is coprime with 1. No Natural
is coprime with 0, except 1.
$f(x, y) = (\gcd(x, y) = 1)$.
$f(x, y) = ((k,m,n \in \N \land x=km \land y=kn) \implies k=1)$.
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::CoprimeWith;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::from(3u32)).coprime_with(Natural::from(5u32)), true);
assert_eq!((&Natural::from(12u32)).coprime_with(Natural::from(90u32)), false);
source§impl CoprimeWith for Natural
impl CoprimeWith for Natural
source§fn coprime_with(self, other: Natural) -> bool
fn coprime_with(self, other: Natural) -> bool
Returns whether two Natural
s are coprime; that is, whether they have no common factor
other than 1. Both Natural
s are taken by value.
Every Natural
is coprime with 1. No Natural
is coprime with 0, except 1.
$f(x, y) = (\gcd(x, y) = 1)$.
$f(x, y) = ((k,m,n \in \N \land x=km \land y=kn) \implies k=1)$.
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::CoprimeWith;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(3u32).coprime_with(Natural::from(5u32)), true);
assert_eq!(Natural::from(12u32).coprime_with(Natural::from(90u32)), false);
source§impl CountOnes for &Natural
impl CountOnes for &Natural
source§fn count_ones(self) -> u64
fn count_ones(self) -> u64
Counts the number of ones in the binary expansion of a Natural
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::Zero;
use malachite_base::num::logic::traits::CountOnes;
use malachite_nz::natural::Natural;
assert_eq!(Natural::ZERO.count_ones(), 0);
// 105 = 1101001b
assert_eq!(Natural::from(105u32).count_ones(), 4);
// 10^12 = 1110100011010100101001010001000000000000b
assert_eq!(Natural::from(10u32).pow(12).count_ones(), 13);
source§impl Debug for Natural
impl Debug for Natural
source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Converts a Natural
to a String
.
This is the same as the Display::fmt
implementation.
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!(Natural::ZERO.to_debug_string(), "0");
assert_eq!(Natural::from(123u32).to_debug_string(), "123");
assert_eq!(
Natural::from_str("1000000000000").unwrap().to_debug_string(),
"1000000000000"
);
assert_eq!(format!("{:05?}", Natural::from(123u32)), "00123");
source§impl Digits<Natural> for Natural
impl Digits<Natural> for Natural
source§fn to_digits_asc(&self, base: &Natural) -> Vec<Natural>
fn to_digits_asc(&self, base: &Natural) -> Vec<Natural>
Returns a Vec
containing the digits of a Natural
in ascending order (least- to
most-significant).
If the Natural
is 0, the Vec
is empty; otherwise, it ends with a nonzero digit.
$f(x, b) = (d_i)_ {i=0}^{k-1}$, where $0 \leq d_i < b$ for all $i$, $k=0$ or $d_{k-1} \neq 0$, and
$$ \sum_{i=0}^{k-1}b^i d_i = x. $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if base
is less than 2.
§Examples
use malachite_base::num::basic::traits::{Two, Zero};
use malachite_base::num::conversion::traits::Digits;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
assert_eq!(Natural::ZERO.to_digits_asc(&Natural::from(6u32)).to_debug_string(), "[]");
assert_eq!(Natural::TWO.to_digits_asc(&Natural::from(6u32)).to_debug_string(), "[2]");
assert_eq!(
Natural::from(123456u32).to_digits_asc(&Natural::from(3u32)).to_debug_string(),
"[0, 1, 1, 0, 0, 1, 1, 2, 0, 0, 2]"
);
source§fn to_digits_desc(&self, base: &Natural) -> Vec<Natural>
fn to_digits_desc(&self, base: &Natural) -> Vec<Natural>
Returns a Vec
containing the digits of a Natural
in descending order (most- to
least-significant).
If the Natural
is 0, the Vec
is empty; otherwise, it begins with a nonzero digit.
$f(x, b) = (d_i)_ {i=0}^{k-1}$, where $0 \leq d_i < b$ for all $i$, $k=0$ or $d_{k-1} \neq 0$, and
$$ \sum_{i=0}^{k-1}b^i d_{k-i-1} = x. $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if base
is less than 2.
§Examples
use malachite_base::num::basic::traits::{Two, Zero};
use malachite_base::num::conversion::traits::Digits;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
assert_eq!(Natural::ZERO.to_digits_desc(&Natural::from(6u32)).to_debug_string(), "[]");
assert_eq!(Natural::TWO.to_digits_desc(&Natural::from(6u32)).to_debug_string(), "[2]");
assert_eq!(
Natural::from(123456u32).to_digits_desc(&Natural::from(3u32)).to_debug_string(),
"[2, 0, 0, 2, 1, 1, 0, 0, 1, 1, 0]"
);
source§fn from_digits_asc<I: Iterator<Item = Natural>>(
base: &Natural,
digits: I
) -> Option<Natural>
fn from_digits_asc<I: Iterator<Item = Natural>>( base: &Natural, digits: I ) -> Option<Natural>
Converts an iterator of digits into a Natural
.
The input digits are in ascending order (least- to most-significant). The function returns
None
if any of the digits are greater than or equal to the base.
$$ f((d_i)_ {i=0}^{k-1}, b) = \sum_{i=0}^{k-1}b^id_i. $$
§Worst-case complexity
$T(n, m) = O(nm (\log (nm))^2 \log\log (nm))$
$M(n, m) = O(nm \log (nm))$
where $T$ is time, $M$ is additional memory, $n$ is digits.count()
, and $m$ is
base.significant_bits()
.
§Panics
Panics if base
is less than 2.
§Examples
use malachite_base::num::conversion::traits::Digits;
use malachite_base::strings::ToDebugString;
use malachite_base::vecs::vec_from_str;
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!(
Natural::from_digits_asc(
&Natural::from(64u32),
vec_from_str::<Natural>("[0, 0, 0]").unwrap().into_iter()
).to_debug_string(),
"Some(0)"
);
assert_eq!(
Natural::from_digits_asc(
&Natural::from(3u32),
vec_from_str::<Natural>("[0, 1, 1, 0, 0, 1, 1, 2, 0, 0, 2]").unwrap().into_iter()
).to_debug_string(),
"Some(123456)"
);
assert_eq!(
Natural::from_digits_asc(
&Natural::from(8u32),
vec_from_str::<Natural>("[3, 7, 1]").unwrap().into_iter()
).to_debug_string(),
"Some(123)"
);
assert_eq!(
Natural::from_digits_asc(
&Natural::from(8u32),
vec_from_str::<Natural>("[1, 10, 3]").unwrap().into_iter()
).to_debug_string(),
"None"
);
source§fn from_digits_desc<I: Iterator<Item = Natural>>(
base: &Natural,
digits: I
) -> Option<Natural>
fn from_digits_desc<I: Iterator<Item = Natural>>( base: &Natural, digits: I ) -> Option<Natural>
Converts an iterator of digits into a Natural
.
The input digits are in descending order (most- to least-significant). The function returns
None
if any of the digits are greater than or equal to the base.
$$ f((d_i)_ {i=0}^{k-1}, b) = \sum_{i=0}^{k-1}b^{k-i-1}d_i. $$
§Worst-case complexity
$T(n, m) = O(nm (\log (nm))^2 \log\log (nm))$
$M(n, m) = O(nm \log (nm))$
where $T$ is time, $M$ is additional memory, $n$ is digits.count()
, and $m$ is
base.significant_bits()
.
§Panics
Panics if base
is less than 2.
§Examples
use malachite_base::num::conversion::traits::Digits;
use malachite_base::strings::ToDebugString;
use malachite_base::vecs::vec_from_str;
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!(
Natural::from_digits_desc(
&Natural::from(64u32),
vec_from_str::<Natural>("[0, 0, 0]").unwrap().into_iter()
).to_debug_string(),
"Some(0)"
);
assert_eq!(
Natural::from_digits_desc(
&Natural::from(3u32),
vec_from_str::<Natural>("[2, 0, 0, 2, 1, 1, 0, 0, 1, 1, 0]").unwrap().into_iter()
).to_debug_string(),
"Some(123456)"
);
assert_eq!(
Natural::from_digits_desc(
&Natural::from(8u32),
vec_from_str::<Natural>("[1, 7, 3]").unwrap().into_iter()
).to_debug_string(),
"Some(123)"
);
assert_eq!(
Natural::from_digits_desc(
&Natural::from(8u32),
vec_from_str::<Natural>("[3, 10, 1]").unwrap().into_iter()
).to_debug_string(),
"None"
);
source§impl Digits<u128> for Natural
impl Digits<u128> for Natural
source§fn to_digits_asc(&self, base: &u128) -> Vec<u128>
fn to_digits_asc(&self, base: &u128) -> Vec<u128>
Returns a Vec
containing the digits of a Natural
in ascending order (least-
to most-significant).
If the Natural
is 0, the Vec
is empty; otherwise, it ends with a nonzero
digit.
$f(x, b) = (d_i)_ {i=0}^{k-1}$, where $0 \leq d_i < b$ for all $i$, $k=0$ or $d_{k-1} \neq 0$, and
$$ \sum_{i=0}^{k-1}b^i d_i = x. $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if base
is less than 2.
§Examples
See here.
source§fn to_digits_desc(&self, base: &u128) -> Vec<u128>
fn to_digits_desc(&self, base: &u128) -> Vec<u128>
Returns a Vec
containing the digits of a Natural
in descending order (most-
to least-significant).
If the Natural
is 0, the Vec
is empty; otherwise, it begins with a nonzero
digit.
$f(x, b) = (d_i)_ {i=0}^{k-1}$, where $0 \leq d_i < b$ for all $i$, $k=0$ or $d_{k-1} \neq 0$, and
$$ \sum_{i=0}^{k-1}b^i d_{k-i-1} = x. $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if base
is less than 2.
§Examples
See here.
source§fn from_digits_asc<I: Iterator<Item = u128>>(
base: &u128,
digits: I
) -> Option<Natural>
fn from_digits_asc<I: Iterator<Item = u128>>( base: &u128, digits: I ) -> Option<Natural>
Converts an iterator of digits into a Natural
.
The input digits are in ascending order (least- to most-significant). The function
returns None
if any of the digits are greater than or equal to the base.
$$ f((d_i)_ {i=0}^{k-1}, b) = \sum_{i=0}^{k-1}b^id_i. $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is digits.count()
.
§Panics
Panics if base
is less than 2.
§Examples
See here.
source§fn from_digits_desc<I: Iterator<Item = u128>>(
base: &u128,
digits: I
) -> Option<Natural>
fn from_digits_desc<I: Iterator<Item = u128>>( base: &u128, digits: I ) -> Option<Natural>
Converts an iterator of digits into a Natural
.
The input digits are in descending order (most- to least-significant). The function
returns None
if any of the digits are greater than or equal to the base.
$$ f((d_i)_ {i=0}^{k-1}, b) = \sum_{i=0}^{k-1}b^{k-i-1}d_i. $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is digits.count()
.
§Panics
Panics if base
is less than 2.
§Examples
See here.
source§impl Digits<u16> for Natural
impl Digits<u16> for Natural
source§fn to_digits_asc(&self, base: &u16) -> Vec<u16>
fn to_digits_asc(&self, base: &u16) -> Vec<u16>
Returns a Vec
containing the digits of a Natural
in ascending order (least-
to most-significant).
If the Natural
is 0, the Vec
is empty; otherwise, it ends with a nonzero
digit.
$f(x, b) = (d_i)_ {i=0}^{k-1}$, where $0 \leq d_i < b$ for all $i$, $k=0$ or $d_{k-1} \neq 0$, and
$$ \sum_{i=0}^{k-1}b^i d_i = x. $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if base
is less than 2.
§Examples
See here.
source§fn to_digits_desc(&self, base: &u16) -> Vec<u16>
fn to_digits_desc(&self, base: &u16) -> Vec<u16>
Returns a Vec
containing the digits of a Natural
in descending order (most-
to least-significant).
If the Natural
is 0, the Vec
is empty; otherwise, it begins with a nonzero
digit.
$f(x, b) = (d_i)_ {i=0}^{k-1}$, where $0 \leq d_i < b$ for all $i$, $k=0$ or $d_{k-1} \neq 0$, and
$$ \sum_{i=0}^{k-1}b^i d_{k-i-1} = x. $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if base
is less than 2.
§Examples
See here.
source§fn from_digits_asc<I: Iterator<Item = u16>>(
base: &u16,
digits: I
) -> Option<Natural>
fn from_digits_asc<I: Iterator<Item = u16>>( base: &u16, digits: I ) -> Option<Natural>
Converts an iterator of digits into a Natural
.
The input digits are in ascending order (least- to most-significant). The function
returns None
if any of the digits are greater than or equal to the base.
$$ f((d_i)_ {i=0}^{k-1}, b) = \sum_{i=0}^{k-1}b^id_i. $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is digits.count()
.
§Panics
Panics if base
is less than 2.
§Examples
See here.
source§fn from_digits_desc<I: Iterator<Item = u16>>(
base: &u16,
digits: I
) -> Option<Natural>
fn from_digits_desc<I: Iterator<Item = u16>>( base: &u16, digits: I ) -> Option<Natural>
Converts an iterator of digits into a Natural
.
The input digits are in descending order (most- to least-significant). The function
returns None
if any of the digits are greater than or equal to the base.
$$ f((d_i)_ {i=0}^{k-1}, b) = \sum_{i=0}^{k-1}b^{k-i-1}d_i. $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is digits.count()
.
§Panics
Panics if base
is less than 2.
§Examples
See here.
source§impl Digits<u32> for Natural
impl Digits<u32> for Natural
source§fn to_digits_asc(&self, base: &u32) -> Vec<u32>
fn to_digits_asc(&self, base: &u32) -> Vec<u32>
Returns a Vec
containing the digits of a Natural
in ascending order (least-
to most-significant).
If the Natural
is 0, the Vec
is empty; otherwise, it ends with a nonzero
digit.
$f(x, b) = (d_i)_ {i=0}^{k-1}$, where $0 \leq d_i < b$ for all $i$, $k=0$ or $d_{k-1} \neq 0$, and
$$ \sum_{i=0}^{k-1}b^i d_i = x. $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if base
is less than 2.
§Examples
See here.
source§fn to_digits_desc(&self, base: &u32) -> Vec<u32>
fn to_digits_desc(&self, base: &u32) -> Vec<u32>
Returns a Vec
containing the digits of a Natural
in descending order (most-
to least-significant).
If the Natural
is 0, the Vec
is empty; otherwise, it begins with a nonzero
digit.
$f(x, b) = (d_i)_ {i=0}^{k-1}$, where $0 \leq d_i < b$ for all $i$, $k=0$ or $d_{k-1} \neq 0$, and
$$ \sum_{i=0}^{k-1}b^i d_{k-i-1} = x. $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if base
is less than 2.
§Examples
See here.
source§fn from_digits_asc<I: Iterator<Item = u32>>(
base: &u32,
digits: I
) -> Option<Natural>
fn from_digits_asc<I: Iterator<Item = u32>>( base: &u32, digits: I ) -> Option<Natural>
Converts an iterator of digits into a Natural
.
The input digits are in ascending order (least- to most-significant). The function
returns None
if any of the digits are greater than or equal to the base.
$$ f((d_i)_ {i=0}^{k-1}, b) = \sum_{i=0}^{k-1}b^id_i. $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is digits.count()
.
§Panics
Panics if base
is less than 2.
§Examples
See here.
source§fn from_digits_desc<I: Iterator<Item = u32>>(
base: &u32,
digits: I
) -> Option<Natural>
fn from_digits_desc<I: Iterator<Item = u32>>( base: &u32, digits: I ) -> Option<Natural>
Converts an iterator of digits into a Natural
.
The input digits are in descending order (most- to least-significant). The function
returns None
if any of the digits are greater than or equal to the base.
$$ f((d_i)_ {i=0}^{k-1}, b) = \sum_{i=0}^{k-1}b^{k-i-1}d_i. $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is digits.count()
.
§Panics
Panics if base
is less than 2.
§Examples
See here.
source§impl Digits<u64> for Natural
impl Digits<u64> for Natural
source§fn to_digits_asc(&self, base: &u64) -> Vec<u64>
fn to_digits_asc(&self, base: &u64) -> Vec<u64>
Returns a Vec
containing the digits of a Natural
in ascending order (least-
to most-significant).
If the Natural
is 0, the Vec
is empty; otherwise, it ends with a nonzero
digit.
$f(x, b) = (d_i)_ {i=0}^{k-1}$, where $0 \leq d_i < b$ for all $i$, $k=0$ or $d_{k-1} \neq 0$, and
$$ \sum_{i=0}^{k-1}b^i d_i = x. $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if base
is less than 2.
§Examples
See here.
source§fn to_digits_desc(&self, base: &u64) -> Vec<u64>
fn to_digits_desc(&self, base: &u64) -> Vec<u64>
Returns a Vec
containing the digits of a Natural
in descending order (most-
to least-significant).
If the Natural
is 0, the Vec
is empty; otherwise, it begins with a nonzero
digit.
$f(x, b) = (d_i)_ {i=0}^{k-1}$, where $0 \leq d_i < b$ for all $i$, $k=0$ or $d_{k-1} \neq 0$, and
$$ \sum_{i=0}^{k-1}b^i d_{k-i-1} = x. $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if base
is less than 2.
§Examples
See here.
source§fn from_digits_asc<I: Iterator<Item = u64>>(
base: &u64,
digits: I
) -> Option<Natural>
fn from_digits_asc<I: Iterator<Item = u64>>( base: &u64, digits: I ) -> Option<Natural>
Converts an iterator of digits into a Natural
.
The input digits are in ascending order (least- to most-significant). The function
returns None
if any of the digits are greater than or equal to the base.
$$ f((d_i)_ {i=0}^{k-1}, b) = \sum_{i=0}^{k-1}b^id_i. $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is digits.count()
.
§Panics
Panics if base
is less than 2.
§Examples
See here.
source§fn from_digits_desc<I: Iterator<Item = u64>>(
base: &u64,
digits: I
) -> Option<Natural>
fn from_digits_desc<I: Iterator<Item = u64>>( base: &u64, digits: I ) -> Option<Natural>
Converts an iterator of digits into a Natural
.
The input digits are in descending order (most- to least-significant). The function
returns None
if any of the digits are greater than or equal to the base.
$$ f((d_i)_ {i=0}^{k-1}, b) = \sum_{i=0}^{k-1}b^{k-i-1}d_i. $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is digits.count()
.
§Panics
Panics if base
is less than 2.
§Examples
See here.
source§impl Digits<u8> for Natural
impl Digits<u8> for Natural
source§fn to_digits_asc(&self, base: &u8) -> Vec<u8>
fn to_digits_asc(&self, base: &u8) -> Vec<u8>
Returns a Vec
containing the digits of a Natural
in ascending order (least- to
most-significant).
If the Natural
is 0, the Vec
is empty; otherwise, it ends with a nonzero digit.
$f(x, b) = (d_i)_ {i=0}^{k-1}$, where $0 \leq d_i < b$ for all $i$, $k=0$ or $d_{k-1} \neq 0$, and
$$ \sum_{i=0}^{k-1}b^i d_i = x. $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if base
is less than 2.
§Examples
See here.
source§fn to_digits_desc(&self, base: &u8) -> Vec<u8>
fn to_digits_desc(&self, base: &u8) -> Vec<u8>
Returns a Vec
containing the digits of a Natural
in descending order (most- to
least-significant).
If the Natural
is 0, the Vec
is empty; otherwise, it begins with a nonzero digit.
$f(x, b) = (d_i)_ {i=0}^{k-1}$, where $0 \leq d_i < b$ for all $i$, $k=0$ or $d_{k-1} \neq 0$, and
$$ \sum_{i=0}^{k-1}b^i d_{k-i-1} = x. $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if base
is less than 2.
§Examples
See here.
source§fn from_digits_asc<I: Iterator<Item = u8>>(
base: &u8,
digits: I
) -> Option<Natural>
fn from_digits_asc<I: Iterator<Item = u8>>( base: &u8, digits: I ) -> Option<Natural>
Converts an iterator of digits into a Natural
.
The input digits are in ascending order (least- to most-significant). The function returns
None
if any of the digits are greater than or equal to the base.
$$ f((d_i)_ {i=0}^{k-1}, b) = \sum_{i=0}^{k-1}b^id_i. $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is digits.count()
.
§Panics
Panics if base
is less than 2.
§Examples
See here.
source§fn from_digits_desc<I: Iterator<Item = u8>>(
base: &u8,
digits: I
) -> Option<Natural>
fn from_digits_desc<I: Iterator<Item = u8>>( base: &u8, digits: I ) -> Option<Natural>
Converts an iterator of digits into a Natural
.
The input digits are in descending order (most- to least-significant). The function returns
None
if any of the digits are greater than or equal to the base.
$$ f((d_i)_ {i=0}^{k-1}, b) = \sum_{i=0}^{k-1}b^{k-i-1}d_i. $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is digits.count()
.
§Panics
Panics if base
is less than 2.
§Examples
See here.
source§impl Digits<usize> for Natural
impl Digits<usize> for Natural
source§fn to_digits_asc(&self, base: &usize) -> Vec<usize>
fn to_digits_asc(&self, base: &usize) -> Vec<usize>
Returns a Vec
containing the digits of a Natural
in ascending order (least-
to most-significant).
If the Natural
is 0, the Vec
is empty; otherwise, it ends with a nonzero
digit.
$f(x, b) = (d_i)_ {i=0}^{k-1}$, where $0 \leq d_i < b$ for all $i$, $k=0$ or $d_{k-1} \neq 0$, and
$$ \sum_{i=0}^{k-1}b^i d_i = x. $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if base
is less than 2.
§Examples
See here.
source§fn to_digits_desc(&self, base: &usize) -> Vec<usize>
fn to_digits_desc(&self, base: &usize) -> Vec<usize>
Returns a Vec
containing the digits of a Natural
in descending order (most-
to least-significant).
If the Natural
is 0, the Vec
is empty; otherwise, it begins with a nonzero
digit.
$f(x, b) = (d_i)_ {i=0}^{k-1}$, where $0 \leq d_i < b$ for all $i$, $k=0$ or $d_{k-1} \neq 0$, and
$$ \sum_{i=0}^{k-1}b^i d_{k-i-1} = x. $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if base
is less than 2.
§Examples
See here.
source§fn from_digits_asc<I: Iterator<Item = usize>>(
base: &usize,
digits: I
) -> Option<Natural>
fn from_digits_asc<I: Iterator<Item = usize>>( base: &usize, digits: I ) -> Option<Natural>
Converts an iterator of digits into a Natural
.
The input digits are in ascending order (least- to most-significant). The function
returns None
if any of the digits are greater than or equal to the base.
$$ f((d_i)_ {i=0}^{k-1}, b) = \sum_{i=0}^{k-1}b^id_i. $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is digits.count()
.
§Panics
Panics if base
is less than 2.
§Examples
See here.
source§fn from_digits_desc<I: Iterator<Item = usize>>(
base: &usize,
digits: I
) -> Option<Natural>
fn from_digits_desc<I: Iterator<Item = usize>>( base: &usize, digits: I ) -> Option<Natural>
Converts an iterator of digits into a Natural
.
The input digits are in descending order (most- to least-significant). The function
returns None
if any of the digits are greater than or equal to the base.
$$ f((d_i)_ {i=0}^{k-1}, b) = \sum_{i=0}^{k-1}b^{k-i-1}d_i. $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is digits.count()
.
§Panics
Panics if base
is less than 2.
§Examples
See here.
source§impl Display for Natural
impl Display for Natural
source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Converts a Natural
to a String
.
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!(Natural::ZERO.to_string(), "0");
assert_eq!(Natural::from(123u32).to_string(), "123");
assert_eq!(
Natural::from_str("1000000000000").unwrap().to_string(),
"1000000000000"
);
assert_eq!(format!("{:05}", Natural::from(123u32)), "00123");
source§impl<'a, 'b> Div<&'b Natural> for &'a Natural
impl<'a, 'b> Div<&'b Natural> for &'a Natural
source§fn div(self, other: &'b Natural) -> Natural
fn div(self, other: &'b Natural) -> Natural
Divides a Natural
by another Natural
, taking both by reference. The quotient is
rounded towards negative infinity. The quotient and remainder (which is not computed)
satisfy $x = qy + r$ and $0 \leq r < y$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_base::num::arithmetic::traits::DivMod;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 2 * 10 + 3 = 23
assert_eq!(&Natural::from(23u32) / &Natural::from(10u32), 2);
// 810000006723 * 1234567890987 + 530068894399 = 1000000000000000000000000
assert_eq!(
&Natural::from_str("1000000000000000000000000").unwrap() /
&Natural::from_str("1234567890987").unwrap(),
810000006723u64
);
source§impl<'a> Div<&'a Natural> for Natural
impl<'a> Div<&'a Natural> for Natural
source§fn div(self, other: &'a Natural) -> Natural
fn div(self, other: &'a Natural) -> Natural
Divides a Natural
by another Natural
, taking the first by value and the second by
reference. The quotient is rounded towards negative infinity. The quotient and remainder
(which is not computed) satisfy $x = qy + r$ and $0 \leq r < y$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 2 * 10 + 3 = 23
assert_eq!(Natural::from(23u32) / &Natural::from(10u32), 2);
// 810000006723 * 1234567890987 + 530068894399 = 1000000000000000000000000
assert_eq!(
Natural::from_str("1000000000000000000000000").unwrap() /
&Natural::from_str("1234567890987").unwrap(),
810000006723u64
);
source§impl<'a> Div<Natural> for &'a Natural
impl<'a> Div<Natural> for &'a Natural
source§fn div(self, other: Natural) -> Natural
fn div(self, other: Natural) -> Natural
Divides a Natural
by another Natural
, taking the first by reference and the second
by value. The quotient is rounded towards negative infinity. The quotient and remainder
(which is not computed) satisfy $x = qy + r$ and $0 \leq r < y$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_base::num::arithmetic::traits::DivMod;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 2 * 10 + 3 = 23
assert_eq!(&Natural::from(23u32) / Natural::from(10u32), 2);
// 810000006723 * 1234567890987 + 530068894399 = 1000000000000000000000000
assert_eq!(
&Natural::from_str("1000000000000000000000000").unwrap() /
Natural::from_str("1234567890987").unwrap(),
810000006723u64
);
source§impl Div for Natural
impl Div for Natural
source§fn div(self, other: Natural) -> Natural
fn div(self, other: Natural) -> Natural
Divides a Natural
by another Natural
, taking both by value. The quotient is rounded
towards negative infinity. The quotient and remainder (which is not computed) satisfy $x =
qy + r$ and $0 \leq r < y$.
$$ f(x, y) = \left \lfloor \frac{x}{y} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 2 * 10 + 3 = 23
assert_eq!(Natural::from(23u32) / Natural::from(10u32), 2);
// 810000006723 * 1234567890987 + 530068894399 = 1000000000000000000000000
assert_eq!(
Natural::from_str("1000000000000000000000000").unwrap() /
Natural::from_str("1234567890987").unwrap(),
810000006723u64
);
source§impl<'a> DivAssign<&'a Natural> for Natural
impl<'a> DivAssign<&'a Natural> for Natural
source§fn div_assign(&mut self, other: &'a Natural)
fn div_assign(&mut self, other: &'a Natural)
Divides a Natural
by another Natural
in place, taking the Natural
on the
right-hand side by reference. The quotient is rounded towards negative infinity. The
quotient and remainder (which is not computed) satisfy $x = qy + r$ and $0 \leq r < y$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 2 * 10 + 3 = 23
let mut x = Natural::from(23u32);
x /= &Natural::from(10u32);
assert_eq!(x, 2);
// 810000006723 * 1234567890987 + 530068894399 = 1000000000000000000000000
let mut x = Natural::from_str("1000000000000000000000000").unwrap();
x /= &Natural::from_str("1234567890987").unwrap();
assert_eq!(x, 810000006723u64);
source§impl DivAssign for Natural
impl DivAssign for Natural
source§fn div_assign(&mut self, other: Natural)
fn div_assign(&mut self, other: Natural)
Divides a Natural
by another Natural
in place, taking the Natural
on the
right-hand side by value. The quotient is rounded towards negative infinity. The quotient
and remainder (which is not computed) satisfy $x = qy + r$ and $0 \leq r < y$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 2 * 10 + 3 = 23
let mut x = Natural::from(23u32);
x /= Natural::from(10u32);
assert_eq!(x, 2);
// 810000006723 * 1234567890987 + 530068894399 = 1000000000000000000000000
let mut x = Natural::from_str("1000000000000000000000000").unwrap();
x /= Natural::from_str("1234567890987").unwrap();
assert_eq!(x, 810000006723u64);
source§impl<'a> DivAssignMod<&'a Natural> for Natural
impl<'a> DivAssignMod<&'a Natural> for Natural
source§fn div_assign_mod(&mut self, other: &'a Natural) -> Natural
fn div_assign_mod(&mut self, other: &'a Natural) -> Natural
Divides a Natural
by another Natural
in place, taking the Natural
on the
right-hand side by value and returning the remainder. The quotient is rounded towards
negative infinity.
The quotient and remainder satisfy $x = qy + r$ and $0 \leq r < y$.
$$ f(x, y) = x - y\left \lfloor \frac{x}{y} \right \rfloor, $$ $$ x \gets \left \lfloor \frac{x}{y} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_base::num::arithmetic::traits::DivAssignMod;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 2 * 10 + 3 = 23
let mut x = Natural::from(23u32);
assert_eq!(x.div_assign_mod(&Natural::from(10u32)), 3);
assert_eq!(x, 2);
// 810000006723 * 1234567890987 + 530068894399 = 1000000000000000000000000
let mut x = Natural::from_str("1000000000000000000000000").unwrap();
assert_eq!(
x.div_assign_mod(&Natural::from_str("1234567890987").unwrap()),
530068894399u64
);
assert_eq!(x, 810000006723u64);
type ModOutput = Natural
source§impl DivAssignMod for Natural
impl DivAssignMod for Natural
source§fn div_assign_mod(&mut self, other: Natural) -> Natural
fn div_assign_mod(&mut self, other: Natural) -> Natural
Divides a Natural
by another Natural
in place, taking the Natural
on the
right-hand side by value and returning the remainder. The quotient is rounded towards
negative infinity.
The quotient and remainder satisfy $x = qy + r$ and $0 \leq r < y$.
$$ f(x, y) = x - y\left \lfloor \frac{x}{y} \right \rfloor, $$ $$ x \gets \left \lfloor \frac{x}{y} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_base::num::arithmetic::traits::DivAssignMod;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 2 * 10 + 3 = 23
let mut x = Natural::from(23u32);
assert_eq!(x.div_assign_mod(Natural::from(10u32)), 3);
assert_eq!(x, 2);
// 810000006723 * 1234567890987 + 530068894399 = 1000000000000000000000000
let mut x = Natural::from_str("1000000000000000000000000").unwrap();
assert_eq!(x.div_assign_mod(Natural::from_str("1234567890987").unwrap()), 530068894399u64);
assert_eq!(x, 810000006723u64);
type ModOutput = Natural
source§impl<'a> DivAssignRem<&'a Natural> for Natural
impl<'a> DivAssignRem<&'a Natural> for Natural
source§fn div_assign_rem(&mut self, other: &'a Natural) -> Natural
fn div_assign_rem(&mut self, other: &'a Natural) -> Natural
Divides a Natural
by another Natural
in place, taking the Natural
on the
right-hand side by reference and returning the remainder. The quotient is rounded towards
zero.
The quotient and remainder satisfy $x = qy + r$ and $0 \leq r < y$.
$$ f(x, y) = x - y\left \lfloor \frac{x}{y} \right \rfloor, $$ $$ x \gets \left \lfloor \frac{x}{y} \right \rfloor. $$
For Natural
s, div_assign_rem
is equivalent to
div_assign_mod
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_base::num::arithmetic::traits::DivAssignRem;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 2 * 10 + 3 = 23
let mut x = Natural::from(23u32);
assert_eq!(x.div_assign_rem(&Natural::from(10u32)), 3);
assert_eq!(x, 2);
// 810000006723 * 1234567890987 + 530068894399 = 1000000000000000000000000
let mut x = Natural::from_str("1000000000000000000000000").unwrap();
assert_eq!(
x.div_assign_rem(&Natural::from_str("1234567890987").unwrap()),
530068894399u64
);
assert_eq!(x, 810000006723u64);
type RemOutput = Natural
source§impl DivAssignRem for Natural
impl DivAssignRem for Natural
source§fn div_assign_rem(&mut self, other: Natural) -> Natural
fn div_assign_rem(&mut self, other: Natural) -> Natural
Divides a Natural
by another Natural
in place, taking the Natural
on the
right-hand side by value and returning the remainder. The quotient is rounded towards zero.
The quotient and remainder satisfy $x = qy + r$ and $0 \leq r < y$.
$$ f(x, y) = x - y\left \lfloor \frac{x}{y} \right \rfloor, $$ $$ x \gets \left \lfloor \frac{x}{y} \right \rfloor. $$
For Natural
s, div_assign_rem
is equivalent to
div_assign_mod
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_base::num::arithmetic::traits::DivAssignRem;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 2 * 10 + 3 = 23
let mut x = Natural::from(23u32);
assert_eq!(x.div_assign_rem(Natural::from(10u32)), 3);
assert_eq!(x, 2);
// 810000006723 * 1234567890987 + 530068894399 = 1000000000000000000000000
let mut x = Natural::from_str("1000000000000000000000000").unwrap();
assert_eq!(x.div_assign_rem(Natural::from_str("1234567890987").unwrap()), 530068894399u64);
assert_eq!(x, 810000006723u64);
type RemOutput = Natural
source§impl<'a, 'b> DivExact<&'b Natural> for &'a Natural
impl<'a, 'b> DivExact<&'b Natural> for &'a Natural
source§fn div_exact(self, other: &'b Natural) -> Natural
fn div_exact(self, other: &'b Natural) -> Natural
Divides a Natural
by another Natural
, taking both by reference. The first
Natural
must be exactly divisible by the second. If it isn’t, this function may panic or
return a meaningless result.
$$ f(x, y) = \frac{x}{y}. $$
If you are unsure whether the division will be exact, use &self / &other
instead. If
you’re unsure and you want to know, use (&self).div_mod(&other)
and check whether the
remainder is zero. If you want a function that panics if the division is not exact, use
(&self).div_round(&other, RoundingMode::Exact)
.
§Worst-case complexity
$T(n) = O(n \log n \log \log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero. May panic if self
is not divisible by other
.
§Examples
use malachite_base::num::arithmetic::traits::DivExact;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 123 * 456 = 56088
assert_eq!((&Natural::from(56088u32)).div_exact(&Natural::from(456u32)), 123);
// 123456789000 * 987654321000 = 121932631112635269000000
assert_eq!(
(&Natural::from_str("121932631112635269000000").unwrap())
.div_exact(&Natural::from_str("987654321000").unwrap()),
123456789000u64
);
type Output = Natural
source§impl<'a> DivExact<&'a Natural> for Natural
impl<'a> DivExact<&'a Natural> for Natural
source§fn div_exact(self, other: &'a Natural) -> Natural
fn div_exact(self, other: &'a Natural) -> Natural
Divides a Natural
by another Natural
, taking the first by value and the second by
reference. The first Natural
must be exactly divisible by the second. If it isn’t, this
function may panic or return a meaningless result.
$$ f(x, y) = \frac{x}{y}. $$
If you are unsure whether the division will be exact, use self / &other
instead. If you’re
unsure and you want to know, use self.div_mod(&other)
and check whether the remainder is
zero. If you want a function that panics if the division is not exact, use
self.div_round(&other, RoundingMode::Exact)
.
§Worst-case complexity
$T(n) = O(n \log n \log \log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero. May panic if self
is not divisible by other
.
§Examples
use malachite_base::num::arithmetic::traits::DivExact;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 123 * 456 = 56088
assert_eq!(Natural::from(56088u32).div_exact(&Natural::from(456u32)), 123);
// 123456789000 * 987654321000 = 121932631112635269000000
assert_eq!(
Natural::from_str("121932631112635269000000").unwrap()
.div_exact(&Natural::from_str("987654321000").unwrap()),
123456789000u64
);
type Output = Natural
source§impl<'a> DivExact<Natural> for &'a Natural
impl<'a> DivExact<Natural> for &'a Natural
source§fn div_exact(self, other: Natural) -> Natural
fn div_exact(self, other: Natural) -> Natural
Divides a Natural
by another Natural
, taking the first by reference and the second
by value. The first Natural
must be exactly divisible by the second. If it isn’t, this
function may panic or return a meaningless result.
$$ f(x, y) = \frac{x}{y}. $$
If you are unsure whether the division will be exact, use &self / other
instead. If you’re
unsure and you want to know, use self.div_mod(other)
and check whether the remainder is
zero. If you want a function that panics if the division is not exact, use
(&self).div_round(other, RoundingMode::Exact)
.
§Worst-case complexity
$T(n) = O(n \log n \log \log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero. May panic if self
is not divisible by other
.
§Examples
use malachite_base::num::arithmetic::traits::DivExact;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 123 * 456 = 56088
assert_eq!((&Natural::from(56088u32)).div_exact(Natural::from(456u32)), 123);
// 123456789000 * 987654321000 = 121932631112635269000000
assert_eq!(
(&Natural::from_str("121932631112635269000000").unwrap())
.div_exact(Natural::from_str("987654321000").unwrap()),
123456789000u64
);
type Output = Natural
source§impl DivExact for Natural
impl DivExact for Natural
source§fn div_exact(self, other: Natural) -> Natural
fn div_exact(self, other: Natural) -> Natural
Divides a Natural
by another Natural
, taking both by value. The first Natural
must be exactly divisible by the second. If it isn’t, this function may panic or return a
meaningless result.
$$ f(x, y) = \frac{x}{y}. $$
If you are unsure whether the division will be exact, use self / other
instead. If you’re
unsure and you want to know, use self.div_mod(other)
and check whether the remainder is
zero. If you want a function that panics if the division is not exact, use
self.div_round(other, RoundingMode::Exact)
.
§Worst-case complexity
$T(n) = O(n \log n \log \log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero. May panic if self
is not divisible by other
.
§Examples
use malachite_base::num::arithmetic::traits::DivExact;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 123 * 456 = 56088
assert_eq!(Natural::from(56088u32).div_exact(Natural::from(456u32)), 123);
// 123456789000 * 987654321000 = 121932631112635269000000
assert_eq!(
Natural::from_str("121932631112635269000000").unwrap()
.div_exact(Natural::from_str("987654321000").unwrap()),
123456789000u64
);
type Output = Natural
source§impl<'a> DivExactAssign<&'a Natural> for Natural
impl<'a> DivExactAssign<&'a Natural> for Natural
source§fn div_exact_assign(&mut self, other: &'a Natural)
fn div_exact_assign(&mut self, other: &'a Natural)
Divides a Natural
by another Natural
in place, taking the Natural
on the
right-hand side by reference. The first Natural
must be exactly divisible by the second.
If it isn’t, this function may panic or return a meaningless result.
$$ x \gets \frac{x}{y}. $$
If you are unsure whether the division will be exact, use self /= &other
instead. If
you’re unsure and you want to know, use self.div_assign_mod(&other)
and check whether the
remainder is zero. If you want a function that panics if the division is not exact, use
self.div_round_assign(&other, RoundingMode::Exact)
.
§Worst-case complexity
$T(n) = O(n \log n \log \log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero. May panic if self
is not divisible by other
.
§Examples
use malachite_base::num::arithmetic::traits::DivExactAssign;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 123 * 456 = 56088
let mut x = Natural::from(56088u32);
x.div_exact_assign(&Natural::from(456u32));
assert_eq!(x, 123);
// 123456789000 * 987654321000 = 121932631112635269000000
let mut x = Natural::from_str("121932631112635269000000").unwrap();
x.div_exact_assign(&Natural::from_str("987654321000").unwrap());
assert_eq!(x, 123456789000u64);
source§impl DivExactAssign for Natural
impl DivExactAssign for Natural
source§fn div_exact_assign(&mut self, other: Natural)
fn div_exact_assign(&mut self, other: Natural)
Divides a Natural
by another Natural
in place, taking the Natural
on the
right-hand side by value. The first Natural
must be exactly divisible by the second. If
it isn’t, this function may panic or return a meaningless result.
$$ x \gets \frac{x}{y}. $$
If you are unsure whether the division will be exact, use self /= other
instead. If you’re
unsure and you want to know, use self.div_assign_mod(other)
and check whether the
remainder is zero. If you want a function that panics if the division is not exact, use
self.div_round_assign(other, RoundingMode::Exact)
.
§Worst-case complexity
$T(n) = O(n \log n \log \log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero. May panic if self
is not divisible by other
.
§Examples
use malachite_base::num::arithmetic::traits::DivExactAssign;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 123 * 456 = 56088
let mut x = Natural::from(56088u32);
x.div_exact_assign(Natural::from(456u32));
assert_eq!(x, 123);
// 123456789000 * 987654321000 = 121932631112635269000000
let mut x = Natural::from_str("121932631112635269000000").unwrap();
x.div_exact_assign(Natural::from_str("987654321000").unwrap());
assert_eq!(x, 123456789000u64);
source§impl<'a, 'b> DivMod<&'b Natural> for &'a Natural
impl<'a, 'b> DivMod<&'b Natural> for &'a Natural
source§fn div_mod(self, other: &'b Natural) -> (Natural, Natural)
fn div_mod(self, other: &'b Natural) -> (Natural, Natural)
Divides a Natural
by another Natural
, taking both by reference and returning the
quotient and remainder. The quotient is rounded towards negative infinity.
The quotient and remainder satisfy $x = qy + r$ and $0 \leq r < y$.
$$ f(x, y) = \left ( \left \lfloor \frac{x}{y} \right \rfloor, \space x - y\left \lfloor \frac{x}{y} \right \rfloor \right ). $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_base::num::arithmetic::traits::DivMod;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 2 * 10 + 3 = 23
assert_eq!(
(&Natural::from(23u32)).div_mod(&Natural::from(10u32)).to_debug_string(),
"(2, 3)"
);
// 810000006723 * 1234567890987 + 530068894399 = 1000000000000000000000000
assert_eq!(
(&Natural::from_str("1000000000000000000000000").unwrap())
.div_mod(&Natural::from_str("1234567890987").unwrap()).to_debug_string(),
"(810000006723, 530068894399)"
);
type DivOutput = Natural
type ModOutput = Natural
source§impl<'a> DivMod<&'a Natural> for Natural
impl<'a> DivMod<&'a Natural> for Natural
source§fn div_mod(self, other: &'a Natural) -> (Natural, Natural)
fn div_mod(self, other: &'a Natural) -> (Natural, Natural)
Divides a Natural
by another Natural
, taking the first by value and the second by
reference and returning the quotient and remainder. The quotient is rounded towards negative
infinity.
The quotient and remainder satisfy $x = qy + r$ and $0 \leq r < y$.
$$ f(x, y) = \left ( \left \lfloor \frac{x}{y} \right \rfloor, \space x - y\left \lfloor \frac{x}{y} \right \rfloor \right ). $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_base::num::arithmetic::traits::DivMod;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 2 * 10 + 3 = 23
assert_eq!(
Natural::from(23u32).div_mod(&Natural::from(10u32)).to_debug_string(),
"(2, 3)"
);
// 810000006723 * 1234567890987 + 530068894399 = 1000000000000000000000000
assert_eq!(
Natural::from_str("1000000000000000000000000").unwrap()
.div_mod(&Natural::from_str("1234567890987").unwrap()).to_debug_string(),
"(810000006723, 530068894399)"
);
type DivOutput = Natural
type ModOutput = Natural
source§impl<'a> DivMod<Natural> for &'a Natural
impl<'a> DivMod<Natural> for &'a Natural
source§fn div_mod(self, other: Natural) -> (Natural, Natural)
fn div_mod(self, other: Natural) -> (Natural, Natural)
Divides a Natural
by another Natural
, taking the first by reference and the second
by value and returning the quotient and remainder. The quotient is rounded towards negative
infinity.
The quotient and remainder satisfy $x = qy + r$ and $0 \leq r < y$.
$$ f(x, y) = \left ( \left \lfloor \frac{x}{y} \right \rfloor, \space x - y\left \lfloor \frac{x}{y} \right \rfloor \right ). $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_base::num::arithmetic::traits::DivMod;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 2 * 10 + 3 = 23
assert_eq!(
(&Natural::from(23u32)).div_mod(Natural::from(10u32)).to_debug_string(),
"(2, 3)"
);
// 810000006723 * 1234567890987 + 530068894399 = 1000000000000000000000000
assert_eq!(
(&Natural::from_str("1000000000000000000000000").unwrap())
.div_mod(Natural::from_str("1234567890987").unwrap()).to_debug_string(),
"(810000006723, 530068894399)"
);
type DivOutput = Natural
type ModOutput = Natural
source§impl DivMod for Natural
impl DivMod for Natural
source§fn div_mod(self, other: Natural) -> (Natural, Natural)
fn div_mod(self, other: Natural) -> (Natural, Natural)
Divides a Natural
by another Natural
, taking both by value and returning the
quotient and remainder. The quotient is rounded towards negative infinity.
The quotient and remainder satisfy $x = qy + r$ and $0 \leq r < y$.
$$ f(x, y) = \left ( \left \lfloor \frac{x}{y} \right \rfloor, \space x - y\left \lfloor \frac{x}{y} \right \rfloor \right ). $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_base::num::arithmetic::traits::DivMod;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 2 * 10 + 3 = 23
assert_eq!(Natural::from(23u32).div_mod(Natural::from(10u32)).to_debug_string(), "(2, 3)");
// 810000006723 * 1234567890987 + 530068894399 = 1000000000000000000000000
assert_eq!(
Natural::from_str("1000000000000000000000000").unwrap()
.div_mod(Natural::from_str("1234567890987").unwrap()).to_debug_string(),
"(810000006723, 530068894399)"
);
type DivOutput = Natural
type ModOutput = Natural
source§impl<'a, 'b> DivRem<&'b Natural> for &'a Natural
impl<'a, 'b> DivRem<&'b Natural> for &'a Natural
source§fn div_rem(self, other: &'b Natural) -> (Natural, Natural)
fn div_rem(self, other: &'b Natural) -> (Natural, Natural)
Divides a Natural
by another Natural
, taking both by reference and returning the
quotient and remainder. The quotient is rounded towards zero.
The quotient and remainder satisfy $x = qy + r$ and $0 \leq r < y$.
$$ f(x, y) = \left ( \left \lfloor \frac{x}{y} \right \rfloor, \space x - y\left \lfloor \frac{x}{y} \right \rfloor \right ). $$
For Natural
s, div_rem
is equivalent to
div_mod
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_base::num::arithmetic::traits::DivRem;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 2 * 10 + 3 = 23
assert_eq!(
(&Natural::from(23u32)).div_rem(&Natural::from(10u32)).to_debug_string(),
"(2, 3)"
);
// 810000006723 * 1234567890987 + 530068894399 = 1000000000000000000000000
assert_eq!(
(&Natural::from_str("1000000000000000000000000").unwrap())
.div_rem(&Natural::from_str("1234567890987").unwrap()).to_debug_string(),
"(810000006723, 530068894399)"
);
type DivOutput = Natural
type RemOutput = Natural
source§impl<'a> DivRem<&'a Natural> for Natural
impl<'a> DivRem<&'a Natural> for Natural
source§fn div_rem(self, other: &'a Natural) -> (Natural, Natural)
fn div_rem(self, other: &'a Natural) -> (Natural, Natural)
Divides a Natural
by another Natural
, taking the first by value and the second by
reference and returning the quotient and remainder. The quotient is rounded towards zero.
The quotient and remainder satisfy $x = qy + r$ and $0 \leq r < y$.
$$ f(x, y) = \left ( \left \lfloor \frac{x}{y} \right \rfloor, \space x - y\left \lfloor \frac{x}{y} \right \rfloor \right ). $$
For Natural
s, div_rem
is equivalent to
div_mod
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_base::num::arithmetic::traits::DivRem;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 2 * 10 + 3 = 23
assert_eq!(
Natural::from(23u32).div_rem(&Natural::from(10u32)).to_debug_string(),
"(2, 3)"
);
// 810000006723 * 1234567890987 + 530068894399 = 1000000000000000000000000
assert_eq!(
Natural::from_str("1000000000000000000000000").unwrap()
.div_rem(&Natural::from_str("1234567890987").unwrap()).to_debug_string(),
"(810000006723, 530068894399)"
);
type DivOutput = Natural
type RemOutput = Natural
source§impl<'a> DivRem<Natural> for &'a Natural
impl<'a> DivRem<Natural> for &'a Natural
source§fn div_rem(self, other: Natural) -> (Natural, Natural)
fn div_rem(self, other: Natural) -> (Natural, Natural)
Divides a Natural
by another Natural
, taking the first by reference and the second
by value and returning the quotient and remainder. The quotient is rounded towards zero.
The quotient and remainder satisfy $x = qy + r$ and $0 \leq r < y$.
$$ f(x, y) = \left ( \left \lfloor \frac{x}{y} \right \rfloor, \space x - y\left \lfloor \frac{x}{y} \right \rfloor \right ). $$
For Natural
s, div_rem
is equivalent to
div_mod
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_base::num::arithmetic::traits::DivRem;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 2 * 10 + 3 = 23
assert_eq!(
(&Natural::from(23u32)).div_rem(Natural::from(10u32)).to_debug_string(),
"(2, 3)"
);
// 810000006723 * 1234567890987 + 530068894399 = 1000000000000000000000000
assert_eq!(
(&Natural::from_str("1000000000000000000000000").unwrap())
.div_rem(Natural::from_str("1234567890987").unwrap()).to_debug_string(),
"(810000006723, 530068894399)"
);
type DivOutput = Natural
type RemOutput = Natural
source§impl DivRem for Natural
impl DivRem for Natural
source§fn div_rem(self, other: Natural) -> (Natural, Natural)
fn div_rem(self, other: Natural) -> (Natural, Natural)
Divides a Natural
by another Natural
, taking both by value and returning the
quotient and remainder. The quotient is rounded towards zero.
The quotient and remainder satisfy $x = qy + r$ and $0 \leq r < y$.
$$ f(x, y) = \left ( \left \lfloor \frac{x}{y} \right \rfloor, \space x - y\left \lfloor \frac{x}{y} \right \rfloor \right ). $$
For Natural
s, div_rem
is equivalent to
div_mod
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_base::num::arithmetic::traits::DivRem;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 2 * 10 + 3 = 23
assert_eq!(Natural::from(23u32).div_rem(Natural::from(10u32)).to_debug_string(), "(2, 3)");
// 810000006723 * 1234567890987 + 530068894399 = 1000000000000000000000000
assert_eq!(
Natural::from_str("1000000000000000000000000").unwrap()
.div_rem(Natural::from_str("1234567890987").unwrap()).to_debug_string(),
"(810000006723, 530068894399)"
);
type DivOutput = Natural
type RemOutput = Natural
source§impl<'a, 'b> DivRound<&'b Natural> for &'a Natural
impl<'a, 'b> DivRound<&'b Natural> for &'a Natural
source§fn div_round(self, other: &'b Natural, rm: RoundingMode) -> (Natural, Ordering)
fn div_round(self, other: &'b Natural, rm: RoundingMode) -> (Natural, Ordering)
Divides a Natural
by another Natural
, taking both by reference and rounding
according to a specified rounding mode. An Ordering
is also returned, indicating whether
the returned value is less than, equal to, or greater than the exact value.
Let $q = \frac{x}{y}$, and let $g$ be the function that just returns the first element of
the pair, without the Ordering
:
$$ g(x, y, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor. $$
$$ g(x, y, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil. $$
$$ g(x, y, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd.} \end{cases} $$
$g(x, y, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then $f(x, y, r) = (g(x, y, r), \operatorname{cmp}(g(x, y, r), q))$.
§Worst-case complexity
$T(n) = O(n \log n \log \log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero, or if rm
is Exact
but self
is not divisible by other
.
§Examples
use malachite_base::num::arithmetic::traits::{DivRound, Pow};
use malachite_base::rounding_modes::RoundingMode;
use malachite_nz::natural::Natural;
use core::cmp::Ordering;
assert_eq!(
(&Natural::from(10u32)).div_round(&Natural::from(4u32), RoundingMode::Down),
(Natural::from(2u32), Ordering::Less)
);
assert_eq!(
(&Natural::from(10u32).pow(12)).div_round(&Natural::from(3u32), RoundingMode::Floor),
(Natural::from(333333333333u64), Ordering::Less)
);
assert_eq!(
(&Natural::from(10u32)).div_round(&Natural::from(4u32), RoundingMode::Up),
(Natural::from(3u32), Ordering::Greater)
);
assert_eq!(
(&Natural::from(10u32).pow(12)).div_round(&Natural::from(3u32), RoundingMode::Ceiling),
(Natural::from(333333333334u64), Ordering::Greater)
);
assert_eq!(
(&Natural::from(10u32)).div_round(&Natural::from(5u32), RoundingMode::Exact),
(Natural::from(2u32), Ordering::Equal)
);
assert_eq!(
(&Natural::from(10u32)).div_round(&Natural::from(3u32), RoundingMode::Nearest),
(Natural::from(3u32), Ordering::Less)
);
assert_eq!(
(&Natural::from(20u32)).div_round(&Natural::from(3u32), RoundingMode::Nearest),
(Natural::from(7u32), Ordering::Greater)
);
assert_eq!(
(&Natural::from(10u32)).div_round(&Natural::from(4u32), RoundingMode::Nearest),
(Natural::from(2u32), Ordering::Less)
);
assert_eq!(
(&Natural::from(14u32)).div_round(&Natural::from(4u32), RoundingMode::Nearest),
(Natural::from(4u32), Ordering::Greater)
);
type Output = Natural
source§impl<'a> DivRound<&'a Natural> for Natural
impl<'a> DivRound<&'a Natural> for Natural
source§fn div_round(self, other: &'a Natural, rm: RoundingMode) -> (Natural, Ordering)
fn div_round(self, other: &'a Natural, rm: RoundingMode) -> (Natural, Ordering)
Divides a Natural
by another Natural
, taking the first by value and the second by
reference and rounding according to a specified rounding mode. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater than the
exact value.
Let $q = \frac{x}{y}$, and let $g$ be the function that just returns the first element of
the pair, without the Ordering
:
$$ g(x, y, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor. $$
$$ g(x, y, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil. $$
$$ g(x, y, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd.} \end{cases} $$
$g(x, y, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then $f(x, y, r) = (g(x, y, r), \operatorname{cmp}(g(x, y, r), q))$.
§Worst-case complexity
$T(n) = O(n \log n \log \log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero, or if rm
is Exact
but self
is not divisible by other
.
§Examples
use malachite_base::num::arithmetic::traits::{DivRound, Pow};
use malachite_base::rounding_modes::RoundingMode;
use malachite_nz::natural::Natural;
use core::cmp::Ordering;
assert_eq!(
Natural::from(10u32).div_round(&Natural::from(4u32), RoundingMode::Down),
(Natural::from(2u32), Ordering::Less)
);
assert_eq!(
Natural::from(10u32).pow(12).div_round(&Natural::from(3u32), RoundingMode::Floor),
(Natural::from(333333333333u64), Ordering::Less)
);
assert_eq!(
Natural::from(10u32).div_round(&Natural::from(4u32), RoundingMode::Up),
(Natural::from(3u32), Ordering::Greater)
);
assert_eq!(
Natural::from(10u32).pow(12).div_round(&Natural::from(3u32), RoundingMode::Ceiling),
(Natural::from(333333333334u64), Ordering::Greater)
);
assert_eq!(
Natural::from(10u32).div_round(&Natural::from(5u32), RoundingMode::Exact),
(Natural::from(2u32), Ordering::Equal)
);
assert_eq!(
Natural::from(10u32).div_round(&Natural::from(3u32), RoundingMode::Nearest),
(Natural::from(3u32), Ordering::Less)
);
assert_eq!(
Natural::from(20u32).div_round(&Natural::from(3u32), RoundingMode::Nearest),
(Natural::from(7u32), Ordering::Greater)
);
assert_eq!(
Natural::from(10u32).div_round(&Natural::from(4u32), RoundingMode::Nearest),
(Natural::from(2u32), Ordering::Less)
);
assert_eq!(
Natural::from(14u32).div_round(&Natural::from(4u32), RoundingMode::Nearest),
(Natural::from(4u32), Ordering::Greater)
);
type Output = Natural
source§impl<'a> DivRound<Natural> for &'a Natural
impl<'a> DivRound<Natural> for &'a Natural
source§fn div_round(self, other: Natural, rm: RoundingMode) -> (Natural, Ordering)
fn div_round(self, other: Natural, rm: RoundingMode) -> (Natural, Ordering)
Divides a Natural
by another Natural
, taking the first by reference and the second
by value and rounding according to a specified rounding mode. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater than the
exact value.
Let $q = \frac{x}{y}$, and let $g$ be the function that just returns the first element of
the pair, without the Ordering
:
$$ g(x, y, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor. $$
$$ g(x, y, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil. $$
$$ g(x, y, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd.} \end{cases} $$
$g(x, y, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then $f(x, y, r) = (g(x, y, r), \operatorname{cmp}(g(x, y, r), q))$.
§Worst-case complexity
$T(n) = O(n \log n \log \log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero, or if rm
is Exact
but self
is not divisible by other
.
§Examples
use malachite_base::num::arithmetic::traits::{DivRound, Pow};
use malachite_base::rounding_modes::RoundingMode;
use malachite_nz::natural::Natural;
use core::cmp::Ordering;
assert_eq!(
(&Natural::from(10u32)).div_round(Natural::from(4u32), RoundingMode::Down),
(Natural::from(2u32), Ordering::Less)
);
assert_eq!(
(&Natural::from(10u32).pow(12)).div_round(Natural::from(3u32), RoundingMode::Floor),
(Natural::from(333333333333u64), Ordering::Less)
);
assert_eq!(
(&Natural::from(10u32)).div_round(Natural::from(4u32), RoundingMode::Up),
(Natural::from(3u32), Ordering::Greater)
);
assert_eq!(
(&Natural::from(10u32).pow(12)).div_round(Natural::from(3u32), RoundingMode::Ceiling),
(Natural::from(333333333334u64), Ordering::Greater)
);
assert_eq!(
(&Natural::from(10u32)).div_round(Natural::from(5u32), RoundingMode::Exact),
(Natural::from(2u32), Ordering::Equal)
);
assert_eq!(
(&Natural::from(10u32)).div_round(Natural::from(3u32), RoundingMode::Nearest),
(Natural::from(3u32), Ordering::Less)
);
assert_eq!(
(&Natural::from(20u32)).div_round(Natural::from(3u32), RoundingMode::Nearest),
(Natural::from(7u32), Ordering::Greater)
);
assert_eq!(
(&Natural::from(10u32)).div_round(Natural::from(4u32), RoundingMode::Nearest),
(Natural::from(2u32), Ordering::Less)
);
assert_eq!(
(&Natural::from(14u32)).div_round(Natural::from(4u32), RoundingMode::Nearest),
(Natural::from(4u32), Ordering::Greater)
);
type Output = Natural
source§impl DivRound for Natural
impl DivRound for Natural
source§fn div_round(self, other: Natural, rm: RoundingMode) -> (Natural, Ordering)
fn div_round(self, other: Natural, rm: RoundingMode) -> (Natural, Ordering)
Divides a Natural
by another Natural
, taking both by value and rounding according to
a specified rounding mode. An Ordering
is also returned, indicating whether the returned
value is less than, equal to, or greater than the exact value.
Let $q = \frac{x}{y}$, and let $g$ be the function that just returns the first element of
the pair, without the Ordering
:
$$ g(x, y, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor. $$
$$ g(x, y, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil. $$
$$ g(x, y, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd.} \end{cases} $$
$g(x, y, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then $f(x, y, r) = (g(x, y, r), \operatorname{cmp}(g(x, y, r), q))$.
§Worst-case complexity
$T(n) = O(n \log n \log \log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero, or if rm
is Exact
but self
is not divisible by other
.
§Examples
use malachite_base::num::arithmetic::traits::{DivRound, Pow};
use malachite_base::rounding_modes::RoundingMode;
use malachite_nz::natural::Natural;
use core::cmp::Ordering;
assert_eq!(
Natural::from(10u32).div_round(Natural::from(4u32), RoundingMode::Down),
(Natural::from(2u32), Ordering::Less)
);
assert_eq!(
Natural::from(10u32).pow(12).div_round(Natural::from(3u32), RoundingMode::Floor),
(Natural::from(333333333333u64), Ordering::Less)
);
assert_eq!(
Natural::from(10u32).div_round(Natural::from(4u32), RoundingMode::Up),
(Natural::from(3u32), Ordering::Greater)
);
assert_eq!(
Natural::from(10u32).pow(12).div_round(Natural::from(3u32), RoundingMode::Ceiling),
(Natural::from(333333333334u64), Ordering::Greater)
);
assert_eq!(
Natural::from(10u32).div_round(Natural::from(5u32), RoundingMode::Exact),
(Natural::from(2u32), Ordering::Equal)
);
assert_eq!(
Natural::from(10u32).div_round(Natural::from(3u32), RoundingMode::Nearest),
(Natural::from(3u32), Ordering::Less)
);
assert_eq!(
Natural::from(20u32).div_round(Natural::from(3u32), RoundingMode::Nearest),
(Natural::from(7u32), Ordering::Greater)
);
assert_eq!(
Natural::from(10u32).div_round(Natural::from(4u32), RoundingMode::Nearest),
(Natural::from(2u32), Ordering::Less)
);
assert_eq!(
Natural::from(14u32).div_round(Natural::from(4u32), RoundingMode::Nearest),
(Natural::from(4u32), Ordering::Greater)
);
type Output = Natural
source§impl<'a> DivRoundAssign<&'a Natural> for Natural
impl<'a> DivRoundAssign<&'a Natural> for Natural
source§fn div_round_assign(&mut self, other: &'a Natural, rm: RoundingMode) -> Ordering
fn div_round_assign(&mut self, other: &'a Natural, rm: RoundingMode) -> Ordering
Divides a Natural
by another Natural
in place, taking the Natural
on the
right-hand side by reference and rounding according to a specified rounding mode. An
Ordering
is returned, indicating whether the assigned value is less than, equal to, or
greater than the exact value.
See the DivRound
documentation for details.
§Worst-case complexity
$T(n) = O(n \log n \log \log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero, or if rm
is Exact
but self
is not divisible by other
.
§Examples
use malachite_base::num::arithmetic::traits::{DivRoundAssign, Pow};
use malachite_base::rounding_modes::RoundingMode;
use malachite_nz::natural::Natural;
use core::cmp::Ordering;
let mut n = Natural::from(10u32);
assert_eq!(n.div_round_assign(&Natural::from(4u32), RoundingMode::Down), Ordering::Less);
assert_eq!(n, 2);
let mut n = Natural::from(10u32).pow(12);
assert_eq!(n.div_round_assign(&Natural::from(3u32), RoundingMode::Floor), Ordering::Less);
assert_eq!(n, 333333333333u64);
let mut n = Natural::from(10u32);
assert_eq!(n.div_round_assign(&Natural::from(4u32), RoundingMode::Up), Ordering::Greater);
assert_eq!(n, 3);
let mut n = Natural::from(10u32).pow(12);
assert_eq!(
n.div_round_assign(&Natural::from(3u32), RoundingMode::Ceiling),
Ordering::Greater
);
assert_eq!(n, 333333333334u64);
let mut n = Natural::from(10u32);
assert_eq!(n.div_round_assign(&Natural::from(5u32), RoundingMode::Exact), Ordering::Equal);
assert_eq!(n, 2);
let mut n = Natural::from(10u32);
assert_eq!(
n.div_round_assign(&Natural::from(3u32), RoundingMode::Nearest),
Ordering::Less
);
assert_eq!(n, 3);
let mut n = Natural::from(20u32);
assert_eq!(
n.div_round_assign(&Natural::from(3u32), RoundingMode::Nearest),
Ordering::Greater
);
assert_eq!(n, 7);
let mut n = Natural::from(10u32);
assert_eq!(
n.div_round_assign(&Natural::from(4u32), RoundingMode::Nearest),
Ordering::Less
);
assert_eq!(n, 2);
let mut n = Natural::from(14u32);
assert_eq!(
n.div_round_assign(&Natural::from(4u32), RoundingMode::Nearest),
Ordering::Greater
);
assert_eq!(n, 4);
source§impl DivRoundAssign for Natural
impl DivRoundAssign for Natural
source§fn div_round_assign(&mut self, other: Natural, rm: RoundingMode) -> Ordering
fn div_round_assign(&mut self, other: Natural, rm: RoundingMode) -> Ordering
Divides a Natural
by another Natural
in place, taking the Natural
on the
right-hand side by value and rounding according to a specified rounding mode. An
Ordering
is returned, indicating whether the assigned value is less than, equal to, or
greater than the exact value.
See the DivRound
documentation for details.
§Worst-case complexity
$T(n) = O(n \log n \log \log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero, or if rm
is Exact
but self
is not divisible by other
.
§Examples
use malachite_base::num::arithmetic::traits::{DivRoundAssign, Pow};
use malachite_base::rounding_modes::RoundingMode;
use malachite_nz::natural::Natural;
use core::cmp::Ordering;
let mut n = Natural::from(10u32);
assert_eq!(n.div_round_assign(Natural::from(4u32), RoundingMode::Down), Ordering::Less);
assert_eq!(n, 2);
let mut n = Natural::from(10u32).pow(12);
assert_eq!(n.div_round_assign(Natural::from(3u32), RoundingMode::Floor), Ordering::Less);
assert_eq!(n, 333333333333u64);
let mut n = Natural::from(10u32);
assert_eq!(n.div_round_assign(Natural::from(4u32), RoundingMode::Up), Ordering::Greater);
assert_eq!(n, 3);
let mut n = Natural::from(10u32).pow(12);
assert_eq!(
n.div_round_assign(&Natural::from(3u32), RoundingMode::Ceiling),
Ordering::Greater
);
assert_eq!(n, 333333333334u64);
let mut n = Natural::from(10u32);
assert_eq!(n.div_round_assign(Natural::from(5u32), RoundingMode::Exact), Ordering::Equal);
assert_eq!(n, 2);
let mut n = Natural::from(10u32);
assert_eq!(n.div_round_assign(Natural::from(3u32), RoundingMode::Nearest), Ordering::Less);
assert_eq!(n, 3);
let mut n = Natural::from(20u32);
assert_eq!(
n.div_round_assign(Natural::from(3u32), RoundingMode::Nearest),
Ordering::Greater
);
assert_eq!(n, 7);
let mut n = Natural::from(10u32);
assert_eq!(n.div_round_assign(Natural::from(4u32), RoundingMode::Nearest), Ordering::Less);
assert_eq!(n, 2);
let mut n = Natural::from(14u32);
assert_eq!(
n.div_round_assign(Natural::from(4u32), RoundingMode::Nearest),
Ordering::Greater
);
assert_eq!(n, 4);
source§impl<'a, 'b> DivisibleBy<&'b Natural> for &'a Natural
impl<'a, 'b> DivisibleBy<&'b Natural> for &'a Natural
source§fn divisible_by(self, other: &'b Natural) -> bool
fn divisible_by(self, other: &'b Natural) -> bool
Returns whether a Natural
is divisible by another Natural
; in other words, whether
the first is a multiple of the second. Both Natural
s are taken by reference.
This means that zero is divisible by any Natural
, including zero; but a nonzero
Natural
is never divisible by zero.
It’s more efficient to use this function than to compute the remainder and check whether it’s zero.
§Worst-case complexity
$T(n) = O(n \log n \log \log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::DivisibleBy;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!((&Natural::ZERO).divisible_by(&Natural::ZERO), true);
assert_eq!((&Natural::from(100u32)).divisible_by(&Natural::from(3u32)), false);
assert_eq!((&Natural::from(102u32)).divisible_by(&Natural::from(3u32)), true);
assert_eq!(
(&Natural::from_str("1000000000000000000000000").unwrap())
.divisible_by(&Natural::from_str("1000000000000").unwrap()),
true
);
source§impl<'a> DivisibleBy<&'a Natural> for Natural
impl<'a> DivisibleBy<&'a Natural> for Natural
source§fn divisible_by(self, other: &'a Natural) -> bool
fn divisible_by(self, other: &'a Natural) -> bool
Returns whether a Natural
is divisible by another Natural
; in other words, whether
the first is a multiple of the second. The first Natural
s is taken by reference and the
second by value.
This means that zero is divisible by any Natural
, including zero; but a nonzero
Natural
is never divisible by zero.
It’s more efficient to use this function than to compute the remainder and check whether it’s zero.
§Worst-case complexity
$T(n) = O(n \log n \log \log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::DivisibleBy;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!(Natural::ZERO.divisible_by(&Natural::ZERO), true);
assert_eq!(Natural::from(100u32).divisible_by(&Natural::from(3u32)), false);
assert_eq!(Natural::from(102u32).divisible_by(&Natural::from(3u32)), true);
assert_eq!(
Natural::from_str("1000000000000000000000000").unwrap()
.divisible_by(&Natural::from_str("1000000000000").unwrap()),
true
);
source§impl<'a> DivisibleBy<Natural> for &'a Natural
impl<'a> DivisibleBy<Natural> for &'a Natural
source§fn divisible_by(self, other: Natural) -> bool
fn divisible_by(self, other: Natural) -> bool
Returns whether a Natural
is divisible by another Natural
; in other words, whether
the first is a multiple of the second. The first Natural
s are taken by reference and the
second by value.
This means that zero is divisible by any Natural
, including zero; but a nonzero
Natural
is never divisible by zero.
It’s more efficient to use this function than to compute the remainder and check whether it’s zero.
§Worst-case complexity
$T(n) = O(n \log n \log \log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::DivisibleBy;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!((&Natural::ZERO).divisible_by(Natural::ZERO), true);
assert_eq!((&Natural::from(100u32)).divisible_by(Natural::from(3u32)), false);
assert_eq!((&Natural::from(102u32)).divisible_by(Natural::from(3u32)), true);
assert_eq!(
(&Natural::from_str("1000000000000000000000000").unwrap())
.divisible_by(Natural::from_str("1000000000000").unwrap()),
true
);
source§impl DivisibleBy for Natural
impl DivisibleBy for Natural
source§fn divisible_by(self, other: Natural) -> bool
fn divisible_by(self, other: Natural) -> bool
Returns whether a Natural
is divisible by another Natural
; in other words, whether
the first is a multiple of the second. Both Natural
s are taken by value.
This means that zero is divisible by any Natural
, including zero; but a nonzero
Natural
is never divisible by zero.
It’s more efficient to use this function than to compute the remainder and check whether it’s zero.
§Worst-case complexity
$T(n) = O(n \log n \log \log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::DivisibleBy;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!(Natural::ZERO.divisible_by(Natural::ZERO), true);
assert_eq!(Natural::from(100u32).divisible_by(Natural::from(3u32)), false);
assert_eq!(Natural::from(102u32).divisible_by(Natural::from(3u32)), true);
assert_eq!(
Natural::from_str("1000000000000000000000000").unwrap()
.divisible_by(Natural::from_str("1000000000000").unwrap()),
true
);
source§impl<'a> DivisibleByPowerOf2 for &'a Natural
impl<'a> DivisibleByPowerOf2 for &'a Natural
source§fn divisible_by_power_of_2(self, pow: u64) -> bool
fn divisible_by_power_of_2(self, pow: u64) -> bool
Returns whether a Natural
is divisible by $2^k$.
$f(x, k) = (2^k|x)$.
$f(x, k) = (\exists n \in \N : \ x = n2^k)$.
If self
is 0, the result is always true; otherwise, it is equivalent to
self.trailing_zeros().unwrap() <= pow
, but more efficient.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is min(pow, self.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::{DivisibleByPowerOf2, Pow};
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!(Natural::ZERO.divisible_by_power_of_2(100), true);
assert_eq!(Natural::from(100u32).divisible_by_power_of_2(2), true);
assert_eq!(Natural::from(100u32).divisible_by_power_of_2(3), false);
assert_eq!(Natural::from(10u32).pow(12).divisible_by_power_of_2(12), true);
assert_eq!(Natural::from(10u32).pow(12).divisible_by_power_of_2(13), false);
source§impl DoubleFactorial for Natural
impl DoubleFactorial for Natural
source§fn double_factorial(n: u64) -> Natural
fn double_factorial(n: u64) -> Natural
Computes the double factorial of a number.
$$ f(n) = n!! = n \times (n - 2) \times (n - 4) \times \cdots \times i, $$ where $i$ is 1 if $n$ is odd and $2$ if $n$ is even.
$n!! = O(\sqrt{n}(n/e)^{n/2})$.
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
§Examples
use malachite_base::num::arithmetic::traits::DoubleFactorial;
use malachite_nz::natural::Natural;
assert_eq!(Natural::double_factorial(0), 1);
assert_eq!(Natural::double_factorial(1), 1);
assert_eq!(Natural::double_factorial(2), 2);
assert_eq!(Natural::double_factorial(3), 3);
assert_eq!(Natural::double_factorial(4), 8);
assert_eq!(Natural::double_factorial(5), 15);
assert_eq!(Natural::double_factorial(6), 48);
assert_eq!(Natural::double_factorial(7), 105);
assert_eq!(
Natural::double_factorial(99).to_string(),
"2725392139750729502980713245400918633290796330545803413734328823443106201171875"
);
assert_eq!(
Natural::double_factorial(100).to_string(),
"34243224702511976248246432895208185975118675053719198827915654463488000000000000"
);
This is equivalent to mpz_2fac_ui
from mpz/2fac_ui.c
, GMP 6.2.1.
source§impl<'a, 'b, 'c> EqMod<&'b Integer, &'c Natural> for &'a Integer
impl<'a, 'b, 'c> EqMod<&'b Integer, &'c Natural> for &'a Integer
source§fn eq_mod(self, other: &'b Integer, m: &'c Natural) -> bool
fn eq_mod(self, other: &'b Integer, m: &'c Natural) -> bool
Returns whether an Integer
is equivalent to another Integer
modulo a Natural
;
that is, whether the difference between the two Integer
s is a multiple of the
Natural
. All three numbers are taken by reference.
Two Integer
s are equal to each other modulo 0 iff they are equal.
$f(x, y, m) = (x \equiv y \mod m)$.
$f(x, y, m) = (\exists k \in \Z : x - y = km)$.
§Worst-case complexity
$T(n) = O(n \log n \log \log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::EqMod;
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!(
(&Integer::from(123)).eq_mod(&Integer::from(223), &Natural::from(100u32)),
true
);
assert_eq!(
(&Integer::from_str("1000000987654").unwrap()).eq_mod(
&Integer::from_str("-999999012346").unwrap(),
&Natural::from_str("1000000000000").unwrap()
),
true
);
assert_eq!(
(&Integer::from_str("1000000987654").unwrap()).eq_mod(
&Integer::from_str("2000000987655").unwrap(),
&Natural::from_str("1000000000000").unwrap()
),
false
);
source§impl<'a, 'b> EqMod<&'a Integer, &'b Natural> for Integer
impl<'a, 'b> EqMod<&'a Integer, &'b Natural> for Integer
source§fn eq_mod(self, other: &'a Integer, m: &'b Natural) -> bool
fn eq_mod(self, other: &'a Integer, m: &'b Natural) -> bool
Returns whether an Integer
is equivalent to another Integer
modulo a Natural
;
that is, whether the difference between the two Integer
s is a multiple of the
Natural
. The first number is taken by value and the second and third by reference.
Two Integer
s are equal to each other modulo 0 iff they are equal.
$f(x, y, m) = (x \equiv y \mod m)$.
$f(x, y, m) = (\exists k \in \Z : x - y = km)$.
§Worst-case complexity
$T(n) = O(n \log n \log \log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::EqMod;
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!(
Integer::from(123).eq_mod(&Integer::from(223), &Natural::from(100u32)),
true
);
assert_eq!(
Integer::from_str("1000000987654").unwrap().eq_mod(
&Integer::from_str("-999999012346").unwrap(),
&Natural::from_str("1000000000000").unwrap()
),
true
);
assert_eq!(
Integer::from_str("1000000987654").unwrap().eq_mod(
&Integer::from_str("2000000987655").unwrap(),
&Natural::from_str("1000000000000").unwrap()
),
false
);
source§impl<'a, 'b> EqMod<&'b Integer, Natural> for &'a Integer
impl<'a, 'b> EqMod<&'b Integer, Natural> for &'a Integer
source§fn eq_mod(self, other: &'b Integer, m: Natural) -> bool
fn eq_mod(self, other: &'b Integer, m: Natural) -> bool
Returns whether an Integer
is equivalent to another Integer
modulo a Natural
;
that is, whether the difference between the two Integer
s is a multiple of the
Natural
. The first two numbers are taken by reference and the third by value.
Two Integer
s are equal to each other modulo 0 iff they are equal.
$f(x, y, m) = (x \equiv y \mod m)$.
$f(x, y, m) = (\exists k \in \Z : x - y = km)$.
§Worst-case complexity
$T(n) = O(n \log n \log \log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::EqMod;
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!(
(&Integer::from(123)).eq_mod(&Integer::from(223), Natural::from(100u32)),
true
);
assert_eq!(
(&Integer::from_str("1000000987654").unwrap()).eq_mod(
&Integer::from_str("-999999012346").unwrap(),
Natural::from_str("1000000000000").unwrap()
),
true
);
assert_eq!(
(&Integer::from_str("1000000987654").unwrap()).eq_mod(
&Integer::from_str("2000000987655").unwrap(),
Natural::from_str("1000000000000").unwrap()
),
false
);
source§impl<'a> EqMod<&'a Integer, Natural> for Integer
impl<'a> EqMod<&'a Integer, Natural> for Integer
source§fn eq_mod(self, other: &'a Integer, m: Natural) -> bool
fn eq_mod(self, other: &'a Integer, m: Natural) -> bool
Returns whether an Integer
is equivalent to another Integer
modulo a Natural
;
that is, whether the difference between the two Integer
s is a multiple of the
Natural
. The first and third numbers are taken by value and the second by reference.
Two Integer
s are equal to each other modulo 0 iff they are equal.
$f(x, y, m) = (x \equiv y \mod m)$.
$f(x, y, m) = (\exists k \in \Z : x - y = km)$.
§Worst-case complexity
$T(n) = O(n \log n \log \log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::EqMod;
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!(
Integer::from(123).eq_mod(&Integer::from(223), Natural::from(100u32)),
true
);
assert_eq!(
Integer::from_str("1000000987654").unwrap().eq_mod(
&Integer::from_str("-999999012346").unwrap(),
Natural::from_str("1000000000000").unwrap()
),
true
);
assert_eq!(
Integer::from_str("1000000987654").unwrap().eq_mod(
&Integer::from_str("2000000987655").unwrap(),
Natural::from_str("1000000000000").unwrap()
),
false
);
source§impl<'a> EqMod<&'a Natural> for Natural
impl<'a> EqMod<&'a Natural> for Natural
source§fn eq_mod(self, other: &'a Natural, m: Natural) -> bool
fn eq_mod(self, other: &'a Natural, m: Natural) -> bool
Returns whether a Natural
is equivalent to another Natural
modulo a third; that is,
whether the difference between the first two is a multiple of the third. The first and third
are taken by value and the second by reference.
Two Natural
s are equal to each other modulo 0 iff they are equal.
$f(x, y, m) = (x \equiv y \mod m)$.
$f(x, y, m) = (\exists k \in \Z : x - y = km)$.
§Worst-case complexity
$T(n) = O(n \log n \log \log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::EqMod;
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!(
Natural::from(123u32).eq_mod(&Natural::from(223u32), Natural::from(100u32)),
true
);
assert_eq!(
Natural::from_str("1000000987654").unwrap().eq_mod(
&Natural::from_str("2000000987654").unwrap(),
Natural::from_str("1000000000000").unwrap()
),
true
);
assert_eq!(
Natural::from_str("1000000987654").unwrap().eq_mod(
&Natural::from_str("2000000987655").unwrap(),
Natural::from_str("1000000000000").unwrap()
),
false
);
source§impl<'a, 'b, 'c> EqMod<&'b Natural, &'c Natural> for &'a Natural
impl<'a, 'b, 'c> EqMod<&'b Natural, &'c Natural> for &'a Natural
source§fn eq_mod(self, other: &'b Natural, m: &'c Natural) -> bool
fn eq_mod(self, other: &'b Natural, m: &'c Natural) -> bool
Returns whether a Natural
is equivalent to another Natural
modulo a third; that is,
whether the difference between the first two is a multiple of the third. All three are taken
by reference.
Two Natural
s are equal to each other modulo 0 iff they are equal.
$f(x, y, m) = (x \equiv y \mod m)$.
$f(x, y, m) = (\exists k \in \Z : x - y = km)$.
§Worst-case complexity
$T(n) = O(n \log n \log \log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::EqMod;
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!(
(&Natural::from(123u32)).eq_mod(&Natural::from(223u32), &Natural::from(100u32)),
true
);
assert_eq!(
(&Natural::from_str("1000000987654").unwrap()).eq_mod(
&Natural::from_str("2000000987654").unwrap(),
&Natural::from_str("1000000000000").unwrap()
),
true
);
assert_eq!(
(&Natural::from_str("1000000987654").unwrap()).eq_mod(
&Natural::from_str("2000000987655").unwrap(),
&Natural::from_str("1000000000000").unwrap()
),
false
);
source§impl<'a, 'b> EqMod<&'a Natural, &'b Natural> for Natural
impl<'a, 'b> EqMod<&'a Natural, &'b Natural> for Natural
source§fn eq_mod(self, other: &'a Natural, m: &'b Natural) -> bool
fn eq_mod(self, other: &'a Natural, m: &'b Natural) -> bool
Returns whether a Natural
is equivalent to another Natural
modulo a third; that is,
whether the difference between the first two is a multiple of the third. The first is taken
by value and the second and third by reference.
Two Natural
s are equal to each other modulo 0 iff they are equal.
$f(x, y, m) = (x \equiv y \mod m)$.
$f(x, y, m) = (\exists k \in \Z : x - y = km)$.
§Worst-case complexity
$T(n) = O(n \log n \log \log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::EqMod;
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!(
Natural::from(123u32).eq_mod(&Natural::from(223u32), &Natural::from(100u32)),
true
);
assert_eq!(
Natural::from_str("1000000987654").unwrap().eq_mod(
&Natural::from_str("2000000987654").unwrap(),
&Natural::from_str("1000000000000").unwrap()
),
true
);
assert_eq!(
Natural::from_str("1000000987654").unwrap().eq_mod(
&Natural::from_str("2000000987655").unwrap(),
&Natural::from_str("1000000000000").unwrap()
),
false
);
source§impl<'a, 'b> EqMod<&'b Natural, Natural> for &'a Natural
impl<'a, 'b> EqMod<&'b Natural, Natural> for &'a Natural
source§fn eq_mod(self, other: &'b Natural, m: Natural) -> bool
fn eq_mod(self, other: &'b Natural, m: Natural) -> bool
Returns whether a Natural
is equivalent to another Natural
modulo a third; that is,
whether the difference between the first two is a multiple of the third. The first and
second are taken by reference and the third by value.
Two Natural
s are equal to each other modulo 0 iff they are equal.
$f(x, y, m) = (x \equiv y \mod m)$.
$f(x, y, m) = (\exists k \in \Z : x - y = km)$.
§Worst-case complexity
$T(n) = O(n \log n \log \log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::EqMod;
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!(
(&Natural::from(123u32)).eq_mod(&Natural::from(223u32), Natural::from(100u32)),
true
);
assert_eq!(
(&Natural::from_str("1000000987654").unwrap()).eq_mod(
&Natural::from_str("2000000987654").unwrap(),
Natural::from_str("1000000000000").unwrap()
),
true
);
assert_eq!(
(&Natural::from_str("1000000987654").unwrap()).eq_mod(
&Natural::from_str("2000000987655").unwrap(),
Natural::from_str("1000000000000").unwrap()
),
false
);
source§impl<'a, 'b> EqMod<Integer, &'b Natural> for &'a Integer
impl<'a, 'b> EqMod<Integer, &'b Natural> for &'a Integer
source§fn eq_mod(self, other: Integer, m: &'b Natural) -> bool
fn eq_mod(self, other: Integer, m: &'b Natural) -> bool
Returns whether an Integer
is equivalent to another Integer
modulo a Natural
;
that is, whether the difference between the two Integer
s is a multiple of the
Natural
. The first and third numbers are taken by reference and the third by value.
Two Integer
s are equal to each other modulo 0 iff they are equal.
$f(x, y, m) = (x \equiv y \mod m)$.
$f(x, y, m) = (\exists k \in \Z : x - y = km)$.
§Worst-case complexity
$T(n) = O(n \log n \log \log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::EqMod;
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!(
(&Integer::from(123)).eq_mod(Integer::from(223), &Natural::from(100u32)),
true
);
assert_eq!(
(&Integer::from_str("1000000987654").unwrap()).eq_mod(
Integer::from_str("-999999012346").unwrap(),
&Natural::from_str("1000000000000").unwrap()
),
true
);
assert_eq!(
(&Integer::from_str("1000000987654").unwrap()).eq_mod(
Integer::from_str("2000000987655").unwrap(),
&Natural::from_str("1000000000000").unwrap()
),
false
);
source§impl<'a> EqMod<Integer, &'a Natural> for Integer
impl<'a> EqMod<Integer, &'a Natural> for Integer
source§fn eq_mod(self, other: Integer, m: &'a Natural) -> bool
fn eq_mod(self, other: Integer, m: &'a Natural) -> bool
Returns whether an Integer
is equivalent to another Integer
modulo a Natural
;
that is, whether the difference between the two Integer
s is a multiple of the
Natural
. The first two numbers are taken by value and the third by reference.
Two Integer
s are equal to each other modulo 0 iff they are equal.
$f(x, y, m) = (x \equiv y \mod m)$.
$f(x, y, m) = (\exists k \in \Z : x - y = km)$.
§Worst-case complexity
$T(n) = O(n \log n \log \log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::EqMod;
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!(
Integer::from(123).eq_mod(Integer::from(223), &Natural::from(100u32)),
true
);
assert_eq!(
Integer::from_str("1000000987654").unwrap().eq_mod(
Integer::from_str("-999999012346").unwrap(),
&Natural::from_str("1000000000000").unwrap()
),
true
);
assert_eq!(
Integer::from_str("1000000987654").unwrap().eq_mod(
Integer::from_str("2000000987655").unwrap(),
&Natural::from_str("1000000000000").unwrap()
),
false
);
source§impl<'a> EqMod<Integer, Natural> for &'a Integer
impl<'a> EqMod<Integer, Natural> for &'a Integer
source§fn eq_mod(self, other: Integer, m: Natural) -> bool
fn eq_mod(self, other: Integer, m: Natural) -> bool
Returns whether an Integer
is equivalent to another Integer
modulo a Natural
;
that is, whether the difference between the two Integer
s is a multiple of the
Natural
. The first number is taken by reference and the second and third by value.
Two Integer
s are equal to each other modulo 0 iff they are equal.
$f(x, y, m) = (x \equiv y \mod m)$.
$f(x, y, m) = (\exists k \in \Z : x - y = km)$.
§Worst-case complexity
$T(n) = O(n \log n \log \log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::EqMod;
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!(
(&Integer::from(123)).eq_mod(Integer::from(223), Natural::from(100u32)),
true
);
assert_eq!(
(&Integer::from_str("1000000987654").unwrap()).eq_mod(
Integer::from_str("-999999012346").unwrap(),
Natural::from_str("1000000000000").unwrap()
),
true
);
assert_eq!(
(&Integer::from_str("1000000987654").unwrap()).eq_mod(
Integer::from_str("2000000987655").unwrap(),
Natural::from_str("1000000000000").unwrap()
),
false
);
source§impl EqMod<Integer, Natural> for Integer
impl EqMod<Integer, Natural> for Integer
source§fn eq_mod(self, other: Integer, m: Natural) -> bool
fn eq_mod(self, other: Integer, m: Natural) -> bool
Returns whether an Integer
is equivalent to another Integer
modulo a Natural
;
that is, whether the difference between the two Integer
s is a multiple of the
Natural
. All three numbers are taken by value.
Two Integer
s are equal to each other modulo 0 iff they are equal.
$f(x, y, m) = (x \equiv y \mod m)$.
$f(x, y, m) = (\exists k \in \Z : x - y = km)$.
§Worst-case complexity
$T(n) = O(n \log n \log \log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::EqMod;
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!(
Integer::from(123).eq_mod(Integer::from(223), Natural::from(100u32)),
true
);
assert_eq!(
Integer::from_str("1000000987654").unwrap().eq_mod(
Integer::from_str("-999999012346").unwrap(),
Natural::from_str("1000000000000").unwrap()
),
true
);
assert_eq!(
Integer::from_str("1000000987654").unwrap().eq_mod(
Integer::from_str("2000000987655").unwrap(),
Natural::from_str("1000000000000").unwrap()
),
false
);
source§impl<'a, 'b> EqMod<Natural, &'b Natural> for &'a Natural
impl<'a, 'b> EqMod<Natural, &'b Natural> for &'a Natural
source§fn eq_mod(self, other: Natural, m: &'b Natural) -> bool
fn eq_mod(self, other: Natural, m: &'b Natural) -> bool
Returns whether a Natural
is equivalent to another Natural
modulo a third; that is,
whether the difference between the first two is a multiple of the third. The first and third
are taken by reference and the second by value.
Two Natural
s are equal to each other modulo 0 iff they are equal.
$f(x, y, m) = (x \equiv y \mod m)$.
$f(x, y, m) = (\exists k \in \Z : x - y = km)$.
§Worst-case complexity
$T(n) = O(n \log n \log \log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::EqMod;
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!(
(&Natural::from(123u32)).eq_mod(Natural::from(223u32), &Natural::from(100u32)),
true
);
assert_eq!(
(&Natural::from_str("1000000987654").unwrap()).eq_mod(
Natural::from_str("2000000987654").unwrap(),
&Natural::from_str("1000000000000").unwrap()
),
true
);
assert_eq!(
(&Natural::from_str("1000000987654").unwrap()).eq_mod(
Natural::from_str("2000000987655").unwrap(),
&Natural::from_str("1000000000000").unwrap()
),
false
);
source§impl<'a> EqMod<Natural, &'a Natural> for Natural
impl<'a> EqMod<Natural, &'a Natural> for Natural
source§fn eq_mod(self, other: Natural, m: &'a Natural) -> bool
fn eq_mod(self, other: Natural, m: &'a Natural) -> bool
Returns whether a Natural
is equivalent to another Natural
modulo a third; that is,
whether the difference between the first two is a multiple of the third. The first two are
taken by value and the third by reference.
Two Natural
s are equal to each other modulo 0 iff they are equal.
$f(x, y, m) = (x \equiv y \mod m)$.
$f(x, y, m) = (\exists k \in \Z : x - y = km)$.
§Worst-case complexity
$T(n) = O(n \log n \log \log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::EqMod;
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!(
Natural::from(123u32).eq_mod(Natural::from(223u32), &Natural::from(100u32)),
true
);
assert_eq!(
Natural::from_str("1000000987654").unwrap().eq_mod(
Natural::from_str("2000000987654").unwrap(),
&Natural::from_str("1000000000000").unwrap()
),
true
);
assert_eq!(
Natural::from_str("1000000987654").unwrap().eq_mod(
Natural::from_str("2000000987655").unwrap(),
&Natural::from_str("1000000000000").unwrap()
),
false
);
source§impl<'a> EqMod<Natural, Natural> for &'a Natural
impl<'a> EqMod<Natural, Natural> for &'a Natural
source§fn eq_mod(self, other: Natural, m: Natural) -> bool
fn eq_mod(self, other: Natural, m: Natural) -> bool
Returns whether a Natural
is equivalent to another Natural
modulo a third; that is,
whether the difference between the first two is a multiple of the third. The first is taken
by reference and the second and third by value.
Two Natural
s are equal to each other modulo 0 iff they are equal.
$f(x, y, m) = (x \equiv y \mod m)$.
$f(x, y, m) = (\exists k \in \Z : x - y = km)$.
§Worst-case complexity
$T(n) = O(n \log n \log \log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::EqMod;
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!(
(&Natural::from(123u32)).eq_mod(Natural::from(223u32), Natural::from(100u32)),
true
);
assert_eq!(
(&Natural::from_str("1000000987654").unwrap()).eq_mod(
Natural::from_str("2000000987654").unwrap(),
Natural::from_str("1000000000000").unwrap()
),
true
);
assert_eq!(
(&Natural::from_str("1000000987654").unwrap()).eq_mod(
Natural::from_str("2000000987655").unwrap(),
Natural::from_str("1000000000000").unwrap()
),
false
);
source§impl EqMod for Natural
impl EqMod for Natural
source§fn eq_mod(self, other: Natural, m: Natural) -> bool
fn eq_mod(self, other: Natural, m: Natural) -> bool
Returns whether a Natural
is equivalent to another Natural
modulo a third; that is,
whether the difference between the first two is a multiple of the third. All three are taken
by value.
Two Natural
s are equal to each other modulo 0 iff they are equal.
$f(x, y, m) = (x \equiv y \mod m)$.
$f(x, y, m) = (\exists k \in \Z : x - y = km)$.
§Worst-case complexity
$T(n) = O(n \log n \log \log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::EqMod;
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!(
Natural::from(123u32).eq_mod(Natural::from(223u32), Natural::from(100u32)),
true
);
assert_eq!(
Natural::from_str("1000000987654").unwrap().eq_mod(
Natural::from_str("2000000987654").unwrap(),
Natural::from_str("1000000000000").unwrap()
),
true
);
assert_eq!(
Natural::from_str("1000000987654").unwrap().eq_mod(
Natural::from_str("2000000987655").unwrap(),
Natural::from_str("1000000000000").unwrap()
),
false
);
source§impl<'a, 'b> EqModPowerOf2<&'b Natural> for &'a Natural
impl<'a, 'b> EqModPowerOf2<&'b Natural> for &'a Natural
source§fn eq_mod_power_of_2(self, other: &'b Natural, pow: u64) -> bool
fn eq_mod_power_of_2(self, other: &'b Natural, pow: u64) -> bool
Returns whether one Natural
is equal to another modulo $2^k$; that is, whether their $k$
least-significant bits are equal.
$f(x, y, k) = (x \equiv y \mod 2^k)$.
$f(x, y, k) = (\exists n \in \Z : x - y = n2^k)$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is min(pow, self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::EqModPowerOf2;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::ZERO).eq_mod_power_of_2(&Natural::from(256u32), 8), true);
assert_eq!(
(&Natural::from(0b1101u32)).eq_mod_power_of_2(&Natural::from(0b10101u32), 3),
true
);
assert_eq!(
(&Natural::from(0b1101u32)).eq_mod_power_of_2(&Natural::from(0b10101u32), 4),
false
);
source§impl<'a, 'b> ExtendedGcd<&'a Natural> for &'b Natural
impl<'a, 'b> ExtendedGcd<&'a Natural> for &'b Natural
source§fn extended_gcd(self, other: &'a Natural) -> (Natural, Integer, Integer)
fn extended_gcd(self, other: &'a Natural) -> (Natural, Integer, Integer)
Computes the GCD (greatest common divisor) of two Natural
s $a$ and $b$, and also the
coefficients $x$ and $y$ in Bézout’s identity $ax+by=\gcd(a,b)$. Both Natural
s are
taken by reference.
The are infinitely many $x$, $y$ that satisfy the identity for any $a$, $b$, so the full specification is more detailed:
- $f(0, 0) = (0, 0, 0)$.
- $f(a, ak) = (a, 1, 0)$ if $a > 0$ and $k \neq 1$.
- $f(bk, b) = (b, 0, 1)$ if $b > 0$.
- $f(a, b) = (g, x, y)$ if $a \neq 0$ and $b \neq 0$ and $\gcd(a, b) \neq \min(a, b)$, where $g = \gcd(a, b) \geq 0$, $ax + by = g$, $x \leq \lfloor b/g \rfloor$, and $y \leq \lfloor a/g \rfloor$.
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::ExtendedGcd;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
assert_eq!(
(&Natural::from(3u32)).extended_gcd(&Natural::from(5u32)).to_debug_string(),
"(1, 2, -1)"
);
assert_eq!(
(&Natural::from(240u32)).extended_gcd(&Natural::from(46u32)).to_debug_string(),
"(2, -9, 47)"
);
type Gcd = Natural
type Cofactor = Integer
source§impl<'a> ExtendedGcd<&'a Natural> for Natural
impl<'a> ExtendedGcd<&'a Natural> for Natural
source§fn extended_gcd(self, other: &'a Natural) -> (Natural, Integer, Integer)
fn extended_gcd(self, other: &'a Natural) -> (Natural, Integer, Integer)
Computes the GCD (greatest common divisor) of two Natural
s $a$ and $b$, and also the
coefficients $x$ and $y$ in Bézout’s identity $ax+by=\gcd(a,b)$. The first Natural
is
taken by value and the second by reference.
The are infinitely many $x$, $y$ that satisfy the identity for any $a$, $b$, so the full specification is more detailed:
- $f(0, 0) = (0, 0, 0)$.
- $f(a, ak) = (a, 1, 0)$ if $a > 0$ and $k \neq 1$.
- $f(bk, b) = (b, 0, 1)$ if $b > 0$.
- $f(a, b) = (g, x, y)$ if $a \neq 0$ and $b \neq 0$ and $\gcd(a, b) \neq \min(a, b)$, where $g = \gcd(a, b) \geq 0$, $ax + by = g$, $x \leq \lfloor b/g \rfloor$, and $y \leq \lfloor a/g \rfloor$.
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::ExtendedGcd;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
assert_eq!(
Natural::from(3u32).extended_gcd(&Natural::from(5u32)).to_debug_string(),
"(1, 2, -1)"
);
assert_eq!(
Natural::from(240u32).extended_gcd(&Natural::from(46u32)).to_debug_string(),
"(2, -9, 47)"
);
type Gcd = Natural
type Cofactor = Integer
source§impl<'a> ExtendedGcd<Natural> for &'a Natural
impl<'a> ExtendedGcd<Natural> for &'a Natural
source§fn extended_gcd(self, other: Natural) -> (Natural, Integer, Integer)
fn extended_gcd(self, other: Natural) -> (Natural, Integer, Integer)
Computes the GCD (greatest common divisor) of two Natural
s $a$ and $b$, and also the
coefficients $x$ and $y$ in Bézout’s identity $ax+by=\gcd(a,b)$. The first Natural
is
taken by reference and the second by value.
The are infinitely many $x$, $y$ that satisfy the identity for any $a$, $b$, so the full specification is more detailed:
- $f(0, 0) = (0, 0, 0)$.
- $f(a, ak) = (a, 1, 0)$ if $a > 0$ and $k \neq 1$.
- $f(bk, b) = (b, 0, 1)$ if $b > 0$.
- $f(a, b) = (g, x, y)$ if $a \neq 0$ and $b \neq 0$ and $\gcd(a, b) \neq \min(a, b)$, where $g = \gcd(a, b) \geq 0$, $ax + by = g$, $x \leq \lfloor b/g \rfloor$, and $y \leq \lfloor a/g \rfloor$.
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::ExtendedGcd;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
assert_eq!(
(&Natural::from(3u32)).extended_gcd(Natural::from(5u32)).to_debug_string(),
"(1, 2, -1)"
);
assert_eq!(
(&Natural::from(240u32)).extended_gcd(Natural::from(46u32)).to_debug_string(),
"(2, -9, 47)"
);
type Gcd = Natural
type Cofactor = Integer
source§impl ExtendedGcd for Natural
impl ExtendedGcd for Natural
source§fn extended_gcd(self, other: Natural) -> (Natural, Integer, Integer)
fn extended_gcd(self, other: Natural) -> (Natural, Integer, Integer)
Computes the GCD (greatest common divisor) of two Natural
s $a$ and $b$, and also the
coefficients $x$ and $y$ in Bézout’s identity $ax+by=\gcd(a,b)$. Both Natural
s are
taken by value.
The are infinitely many $x$, $y$ that satisfy the identity for any $a$, $b$, so the full specification is more detailed:
- $f(0, 0) = (0, 0, 0)$.
- $f(a, ak) = (a, 1, 0)$ if $a > 0$ and $k \neq 1$.
- $f(bk, b) = (b, 0, 1)$ if $b > 0$.
- $f(a, b) = (g, x, y)$ if $a \neq 0$ and $b \neq 0$ and $\gcd(a, b) \neq \min(a, b)$, where $g = \gcd(a, b) \geq 0$, $ax + by = g$, $x \leq \lfloor b/g \rfloor$, and $y \leq \lfloor a/g \rfloor$.
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::ExtendedGcd;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
assert_eq!(
Natural::from(3u32).extended_gcd(Natural::from(5u32)).to_debug_string(),
"(1, 2, -1)"
);
assert_eq!(
Natural::from(240u32).extended_gcd(Natural::from(46u32)).to_debug_string(),
"(2, -9, 47)"
);
type Gcd = Natural
type Cofactor = Integer
source§impl Factorial for Natural
impl Factorial for Natural
source§fn factorial(n: u64) -> Natural
fn factorial(n: u64) -> Natural
Computes the factorial of a number.
$$ f(n) = n! = 1 \times 2 \times 3 \times \cdots \times n. $$
$n! = O(\sqrt{n}(n/e)^n)$.
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is n
.
§Examples
use malachite_base::num::arithmetic::traits::Factorial;
use malachite_nz::natural::Natural;
assert_eq!(Natural::factorial(0), 1);
assert_eq!(Natural::factorial(1), 1);
assert_eq!(Natural::factorial(2), 2);
assert_eq!(Natural::factorial(3), 6);
assert_eq!(Natural::factorial(4), 24);
assert_eq!(Natural::factorial(5), 120);
assert_eq!(
Natural::factorial(100).to_string(),
"9332621544394415268169923885626670049071596826438162146859296389521759999322991560894\
1463976156518286253697920827223758251185210916864000000000000000000000000"
);
This is equivalent to mpz_fac_ui
from mpz/fac_ui.c
, GMP 6.2.1.
source§impl<'a, 'b> FloorLogBase<&'b Natural> for &'a Natural
impl<'a, 'b> FloorLogBase<&'b Natural> for &'a Natural
source§fn floor_log_base(self, base: &Natural) -> u64
fn floor_log_base(self, base: &Natural) -> u64
Returns the floor of the base-$b$ logarithm of a positive Natural
.
$f(x, b) = \lfloor\log_b x\rfloor$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is x.significant_bits()
.
§Panics
Panics if self
is 0 or base
is less than 2.
§Examples
use malachite_base::num::arithmetic::traits::FloorLogBase;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(80u32).floor_log_base(&Natural::from(3u32)), 3);
assert_eq!(Natural::from(81u32).floor_log_base(&Natural::from(3u32)), 4);
assert_eq!(Natural::from(82u32).floor_log_base(&Natural::from(3u32)), 4);
assert_eq!(Natural::from(4294967296u64).floor_log_base(&Natural::from(10u32)), 9);
This is equivalent to fmpz_flog
from fmpz/flog.c
, FLINT 2.7.1.
type Output = u64
source§impl<'a> FloorLogBase2 for &'a Natural
impl<'a> FloorLogBase2 for &'a Natural
source§fn floor_log_base_2(self) -> u64
fn floor_log_base_2(self) -> u64
Returns the floor of the base-2 logarithm of a positive Natural
.
$f(x) = \lfloor\log_2 x\rfloor$.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if self
is 0.
§Examples
use malachite_base::num::arithmetic::traits::FloorLogBase2;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(3u32).floor_log_base_2(), 1);
assert_eq!(Natural::from(100u32).floor_log_base_2(), 6);
type Output = u64
source§impl<'a> FloorLogBasePowerOf2<u64> for &'a Natural
impl<'a> FloorLogBasePowerOf2<u64> for &'a Natural
source§fn floor_log_base_power_of_2(self, pow: u64) -> u64
fn floor_log_base_power_of_2(self, pow: u64) -> u64
Returns the floor of the base-$2^k$ logarithm of a positive Natural
.
$f(x, k) = \lfloor\log_{2^k} x\rfloor$.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if self
is 0 or pow
is 0.
§Examples
use malachite_base::num::arithmetic::traits::FloorLogBasePowerOf2;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(100u32).floor_log_base_power_of_2(2), 3);
assert_eq!(Natural::from(4294967296u64).floor_log_base_power_of_2(8), 4);
type Output = u64
source§impl<'a> FloorRoot<u64> for &'a Natural
impl<'a> FloorRoot<u64> for &'a Natural
source§fn floor_root(self, exp: u64) -> Natural
fn floor_root(self, exp: u64) -> Natural
Returns the floor of the $n$th root of a Natural
, taking the Natural
by reference.
$f(x, n) = \lfloor\sqrt[n]{x}\rfloor$.
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if exp
is zero.
§Examples
use malachite_base::num::arithmetic::traits::FloorRoot;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::from(999u16)).floor_root(3), 9);
assert_eq!((&Natural::from(1000u16)).floor_root(3), 10);
assert_eq!((&Natural::from(1001u16)).floor_root(3), 10);
assert_eq!((&Natural::from(100000000000u64)).floor_root(5), 158);
type Output = Natural
source§impl FloorRoot<u64> for Natural
impl FloorRoot<u64> for Natural
source§fn floor_root(self, exp: u64) -> Natural
fn floor_root(self, exp: u64) -> Natural
Returns the floor of the $n$th root of a Natural
, taking the Natural
by value.
$f(x, n) = \lfloor\sqrt[n]{x}\rfloor$.
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if exp
is zero.
§Examples
use malachite_base::num::arithmetic::traits::FloorRoot;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(999u16).floor_root(3), 9);
assert_eq!(Natural::from(1000u16).floor_root(3), 10);
assert_eq!(Natural::from(1001u16).floor_root(3), 10);
assert_eq!(Natural::from(100000000000u64).floor_root(5), 158);
type Output = Natural
source§impl FloorRootAssign<u64> for Natural
impl FloorRootAssign<u64> for Natural
source§fn floor_root_assign(&mut self, exp: u64)
fn floor_root_assign(&mut self, exp: u64)
Replaces a Natural
with the floor of its $n$th root.
$x \gets \lfloor\sqrt[n]{x}\rfloor$.
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if exp
is zero.
§Examples
use malachite_base::num::arithmetic::traits::FloorRootAssign;
use malachite_nz::natural::Natural;
let mut x = Natural::from(999u16);
x.floor_root_assign(3);
assert_eq!(x, 9);
let mut x = Natural::from(1000u16);
x.floor_root_assign(3);
assert_eq!(x, 10);
let mut x = Natural::from(1001u16);
x.floor_root_assign(3);
assert_eq!(x, 10);
let mut x = Natural::from(100000000000u64);
x.floor_root_assign(5);
assert_eq!(x, 158);
source§impl<'a> FloorSqrt for &'a Natural
impl<'a> FloorSqrt for &'a Natural
source§fn floor_sqrt(self) -> Natural
fn floor_sqrt(self) -> Natural
Returns the floor of the square root of a Natural
, taking it by value.
$f(x) = \lfloor\sqrt{x}\rfloor$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::FloorSqrt;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::from(99u8)).floor_sqrt(), 9);
assert_eq!((&Natural::from(100u8)).floor_sqrt(), 10);
assert_eq!((&Natural::from(101u8)).floor_sqrt(), 10);
assert_eq!((&Natural::from(1000000000u32)).floor_sqrt(), 31622);
assert_eq!((&Natural::from(10000000000u64)).floor_sqrt(), 100000);
type Output = Natural
source§impl FloorSqrt for Natural
impl FloorSqrt for Natural
source§fn floor_sqrt(self) -> Natural
fn floor_sqrt(self) -> Natural
Returns the floor of the square root of a Natural
, taking it by value.
$f(x) = \lfloor\sqrt{x}\rfloor$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::FloorSqrt;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(99u8).floor_sqrt(), 9);
assert_eq!(Natural::from(100u8).floor_sqrt(), 10);
assert_eq!(Natural::from(101u8).floor_sqrt(), 10);
assert_eq!(Natural::from(1000000000u32).floor_sqrt(), 31622);
assert_eq!(Natural::from(10000000000u64).floor_sqrt(), 100000);
type Output = Natural
source§impl FloorSqrtAssign for Natural
impl FloorSqrtAssign for Natural
source§fn floor_sqrt_assign(&mut self)
fn floor_sqrt_assign(&mut self)
Replaces a Natural
with the floor of its square root.
$x \gets \lfloor\sqrt{x}\rfloor$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::FloorSqrtAssign;
use malachite_nz::natural::Natural;
let mut x = Natural::from(99u8);
x.floor_sqrt_assign();
assert_eq!(x, 9);
let mut x = Natural::from(100u8);
x.floor_sqrt_assign();
assert_eq!(x, 10);
let mut x = Natural::from(101u8);
x.floor_sqrt_assign();
assert_eq!(x, 10);
let mut x = Natural::from(1000000000u32);
x.floor_sqrt_assign();
assert_eq!(x, 31622);
let mut x = Natural::from(10000000000u64);
x.floor_sqrt_assign();
assert_eq!(x, 100000);
source§impl<'a> From<&'a Natural> for Integer
impl<'a> From<&'a Natural> for Integer
source§fn from(value: &'a Natural) -> Integer
fn from(value: &'a Natural) -> Integer
Converts a Natural
to an Integer
, taking the Natural
by reference.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is value.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;
assert_eq!(Integer::from(&Natural::from(123u32)), 123);
assert_eq!(Integer::from(&Natural::from(10u32).pow(12)), 1000000000000u64);
source§impl From<Natural> for Integer
impl From<Natural> for Integer
source§fn from(value: Natural) -> Integer
fn from(value: Natural) -> Integer
Converts a Natural
to an Integer
, taking the Natural
by value.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;
assert_eq!(Integer::from(Natural::from(123u32)), 123);
assert_eq!(Integer::from(Natural::from(10u32).pow(12)), 1000000000000u64);
source§impl From<bool> for Natural
impl From<bool> for Natural
source§fn from(b: bool) -> Natural
fn from(b: bool) -> Natural
Converts a bool
to 0 or 1.
This function is known as the Iverson bracket.
$$ f(P) = [P] = \begin{cases} 1 & \text{if} \quad P, \\ 0 & \text{otherwise}. \end{cases} $$
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(false), 0);
assert_eq!(Natural::from(true), 1);
source§impl FromSciString for Natural
impl FromSciString for Natural
source§fn from_sci_string_with_options(
s: &str,
options: FromSciStringOptions
) -> Option<Natural>
fn from_sci_string_with_options( s: &str, options: FromSciStringOptions ) -> Option<Natural>
Converts a string, possibly in scientfic notation, to a Natural
.
Use FromSciStringOptions
to specify the base (from 2 to 36, inclusive) and the rounding
mode, in case rounding is necessary because the string represents a non-integer.
If the base is greater than 10, the higher digits are represented by the letters 'a'
through 'z'
or 'A'
through 'Z'
; the case doesn’t matter and doesn’t need to be
consistent.
Exponents are allowed, and are indicated using the character 'e'
or 'E'
. If the base is
15 or greater, an ambiguity arises where it may not be clear whether 'e'
is a digit or an
exponent indicator. To resolve this ambiguity, always use a '+'
or '-'
sign after the
exponent indicator when the base is 15 or greater.
The exponent itself is always parsed using base 10.
Decimal (or other-base) points are allowed. These are most useful in conjunction with
exponents, but they may be used on their own. If the string represents a non-integer, the
rounding mode specified in options
is used to round to an integer.
If the string is unparseable, None
is returned. None
is also returned if the rounding
mode in options is Exact
, but rounding is necessary.
§Worst-case complexity
$T(n, m) = O(m^n n \log m (\log n + \log\log m))$
$M(n, m) = O(m^n n \log m)$
where $T$ is time, $M$ is additional memory, $n$ is s.len()
, and $m$ is options.base
.
§Examples
use malachite_base::num::conversion::string::options::FromSciStringOptions;
use malachite_base::num::conversion::traits::FromSciString;
use malachite_base::rounding_modes::RoundingMode;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from_sci_string("123").unwrap(), 123);
assert_eq!(Natural::from_sci_string("123.5").unwrap(), 124);
assert_eq!(Natural::from_sci_string("-123.5"), None);
assert_eq!(Natural::from_sci_string("1.23e10").unwrap(), 12300000000u64);
let mut options = FromSciStringOptions::default();
assert_eq!(Natural::from_sci_string_with_options("123.5", options).unwrap(), 124);
options.set_rounding_mode(RoundingMode::Floor);
assert_eq!(Natural::from_sci_string_with_options("123.5", options).unwrap(), 123);
options = FromSciStringOptions::default();
options.set_base(16);
assert_eq!(Natural::from_sci_string_with_options("ff", options).unwrap(), 255);
options = FromSciStringOptions::default();
options.set_base(36);
assert_eq!(Natural::from_sci_string_with_options("1e5", options).unwrap(), 1805);
assert_eq!(Natural::from_sci_string_with_options("1e+5", options).unwrap(), 60466176);
assert_eq!(Natural::from_sci_string_with_options("1e-5", options).unwrap(), 0);
source§fn from_sci_string(s: &str) -> Option<Self>
fn from_sci_string(s: &str) -> Option<Self>
&str
, possibly in scientific notation, to a number, using the default
FromSciStringOptions
.source§impl FromStr for Natural
impl FromStr for Natural
source§fn from_str(s: &str) -> Result<Natural, ()>
fn from_str(s: &str) -> Result<Natural, ()>
Converts an string to a Natural
.
If the string does not represent a valid Natural
, an Err
is returned. To be valid, the
string must be nonempty and only contain the char
s '0'
through '9'
. Leading zeros
are allowed.
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is s.len()
.
§Examples
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!(Natural::from_str("123456").unwrap(), 123456);
assert_eq!(Natural::from_str("00123456").unwrap(), 123456);
assert_eq!(Natural::from_str("0").unwrap(), 0);
assert!(Natural::from_str("").is_err());
assert!(Natural::from_str("a").is_err());
assert!(Natural::from_str("-5").is_err());
source§impl FromStringBase for Natural
impl FromStringBase for Natural
source§fn from_string_base(base: u8, s: &str) -> Option<Natural>
fn from_string_base(base: u8, s: &str) -> Option<Natural>
Converts an string, in a specified base, to a Natural
.
If the string does not represent a valid Natural
, an Err
is returned. To be valid, the
string must be nonempty and only contain the char
s '0'
through '9'
, 'a'
through
'z'
, and 'A'
through 'Z'
; and only characters that represent digits smaller than the
base are allowed. Leading zeros are always allowed.
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is s.len()
.
§Panics
Panics if base
is less than 2 or greater than 36.
§Examples
use malachite_base::num::conversion::traits::{Digits, FromStringBase};
use malachite_nz::natural::Natural;
assert_eq!(Natural::from_string_base(10, "123456").unwrap(), 123456);
assert_eq!(Natural::from_string_base(10, "00123456").unwrap(), 123456);
assert_eq!(Natural::from_string_base(16, "0").unwrap(), 0);
assert_eq!(Natural::from_string_base(16, "deadbeef").unwrap(), 3735928559u32);
assert_eq!(Natural::from_string_base(16, "deAdBeEf").unwrap(), 3735928559u32);
assert!(Natural::from_string_base(10, "").is_none());
assert!(Natural::from_string_base(10, "a").is_none());
assert!(Natural::from_string_base(10, "-5").is_none());
assert!(Natural::from_string_base(2, "2").is_none());
source§impl<'a, 'b> Gcd<&'a Natural> for &'b Natural
impl<'a, 'b> Gcd<&'a Natural> for &'b Natural
source§fn gcd(self, other: &'a Natural) -> Natural
fn gcd(self, other: &'a Natural) -> Natural
Computes the GCD (greatest common divisor) of two Natural
s, taking both by reference.
The GCD of 0 and $n$, for any $n$, is 0. In particular, $\gcd(0, 0) = 0$, which makes sense if we interpret “greatest” to mean “greatest by the divisibility order”.
$$ f(x, y) = \gcd(x, y). $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::Gcd;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::from(3u32)).gcd(&Natural::from(5u32)), 1);
assert_eq!((&Natural::from(12u32)).gcd(&Natural::from(90u32)), 6);
type Output = Natural
source§impl<'a> Gcd<&'a Natural> for Natural
impl<'a> Gcd<&'a Natural> for Natural
source§fn gcd(self, other: &'a Natural) -> Natural
fn gcd(self, other: &'a Natural) -> Natural
Computes the GCD (greatest common divisor) of two Natural
s, taking the first by value
and the second by reference.
The GCD of 0 and $n$, for any $n$, is 0. In particular, $\gcd(0, 0) = 0$, which makes sense if we interpret “greatest” to mean “greatest by the divisibility order”.
$$ f(x, y) = \gcd(x, y). $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::Gcd;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(3u32).gcd(&Natural::from(5u32)), 1);
assert_eq!(Natural::from(12u32).gcd(&Natural::from(90u32)), 6);
type Output = Natural
source§impl<'a> Gcd<Natural> for &'a Natural
impl<'a> Gcd<Natural> for &'a Natural
source§fn gcd(self, other: Natural) -> Natural
fn gcd(self, other: Natural) -> Natural
Computes the GCD (greatest common divisor) of two Natural
s, taking the first by
reference and the second by value.
The GCD of 0 and $n$, for any $n$, is 0. In particular, $\gcd(0, 0) = 0$, which makes sense if we interpret “greatest” to mean “greatest by the divisibility order”.
$$ f(x, y) = \gcd(x, y). $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::Gcd;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::from(3u32)).gcd(Natural::from(5u32)), 1);
assert_eq!((&Natural::from(12u32)).gcd(Natural::from(90u32)), 6);
type Output = Natural
source§impl Gcd for Natural
impl Gcd for Natural
source§fn gcd(self, other: Natural) -> Natural
fn gcd(self, other: Natural) -> Natural
Computes the GCD (greatest common divisor) of two Natural
s, taking both by value.
The GCD of 0 and $n$, for any $n$, is 0. In particular, $\gcd(0, 0) = 0$, which makes sense if we interpret “greatest” to mean “greatest by the divisibility order”.
$$ f(x, y) = \gcd(x, y). $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::Gcd;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(3u32).gcd(Natural::from(5u32)), 1);
assert_eq!(Natural::from(12u32).gcd(Natural::from(90u32)), 6);
type Output = Natural
source§impl<'a> GcdAssign<&'a Natural> for Natural
impl<'a> GcdAssign<&'a Natural> for Natural
source§fn gcd_assign(&mut self, other: &'a Natural)
fn gcd_assign(&mut self, other: &'a Natural)
Replaces a Natural
by its GCD (greatest common divisor) with another Natural
, taking
the Natural
on the right-hand side by reference.
$$ x \gets \gcd(x, y). $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::GcdAssign;
use malachite_nz::natural::Natural;
let mut x = Natural::from(3u32);
x.gcd_assign(&Natural::from(5u32));
assert_eq!(x, 1);
let mut x = Natural::from(12u32);
x.gcd_assign(&Natural::from(90u32));
assert_eq!(x, 6);
source§impl GcdAssign for Natural
impl GcdAssign for Natural
source§fn gcd_assign(&mut self, other: Natural)
fn gcd_assign(&mut self, other: Natural)
Replaces a Natural
by its GCD (greatest common divisor) with another Natural
, taking
the Natural
on the right-hand side by value.
$$ x \gets \gcd(x, y). $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::GcdAssign;
use malachite_nz::natural::Natural;
let mut x = Natural::from(3u32);
x.gcd_assign(Natural::from(5u32));
assert_eq!(x, 1);
let mut x = Natural::from(12u32);
x.gcd_assign(Natural::from(90u32));
assert_eq!(x, 6);
source§impl<'a, 'b> HammingDistance<&'a Natural> for &'b Natural
impl<'a, 'b> HammingDistance<&'a Natural> for &'b Natural
source§fn hamming_distance(self, other: &'a Natural) -> u64
fn hamming_distance(self, other: &'a Natural) -> u64
Determines the Hamming distance between two [Natural]
s.
Both Natural
s have infinitely many implicit leading zeros.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::One;
use malachite_base::num::logic::traits::HammingDistance;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(123u32).hamming_distance(&Natural::from(123u32)), 0);
// 105 = 1101001b, 123 = 1111011
assert_eq!(Natural::from(105u32).hamming_distance(&Natural::from(123u32)), 2);
let n = Natural::ONE << 100u32;
assert_eq!(n.hamming_distance(&(&n - Natural::ONE)), 101);
source§impl<'a> IntegerMantissaAndExponent<Natural, u64, Natural> for &'a Natural
impl<'a> IntegerMantissaAndExponent<Natural, u64, Natural> for &'a Natural
source§fn integer_mantissa_and_exponent(self) -> (Natural, u64)
fn integer_mantissa_and_exponent(self) -> (Natural, u64)
Returns a Natural
’s integer mantissa and exponent.
When $x$ is nonzero, we can write $x = 2^{e_i}m_i$, where $e_i$ is an integer and $m_i$ is an odd integer. $$ f(x) = (\frac{|x|}{2^{e_i}}, e_i), $$ where $e_i$ is the unique integer such that $x/2^{e_i}$ is an odd integer.
The inverse operation is
from_integer_mantissa_and_exponent
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if self
is zero.
§Examples
use malachite_base::num::conversion::traits::IntegerMantissaAndExponent;
use malachite_nz::natural::Natural;
assert_eq!(
Natural::from(123u32).integer_mantissa_and_exponent(),
(Natural::from(123u32), 0)
);
assert_eq!(
Natural::from(100u32).integer_mantissa_and_exponent(),
(Natural::from(25u32), 2)
);
source§fn integer_mantissa(self) -> Natural
fn integer_mantissa(self) -> Natural
Returns a Natural
’s integer mantissa.
When $x$ is nonzero, we can write $x = 2^{e_i}m_i$, where $e_i$ is an integer and $m_i$ is an odd integer. $$ f(x) = \frac{|x|}{2^{e_i}}, $$ where $e_i$ is the unique integer such that $x/2^{e_i}$ is an odd integer.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if self
is zero.
§Examples
use malachite_base::num::conversion::traits::IntegerMantissaAndExponent;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(123u32).integer_mantissa(), 123);
assert_eq!(Natural::from(100u32).integer_mantissa(), 25);
source§fn integer_exponent(self) -> u64
fn integer_exponent(self) -> u64
Returns a Natural
’s integer exponent.
When $x$ is nonzero, we can write $x = 2^{e_i}m_i$, where $e_i$ is an integer and $m_i$ is an odd integer. $$ f(x) = e_i, $$ where $e_i$ is the unique integer such that $x/2^{e_i}$ is an odd integer.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if self
is zero.
§Examples
use malachite_base::num::conversion::traits::IntegerMantissaAndExponent;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(123u32).integer_exponent(), 0);
assert_eq!(Natural::from(100u32).integer_exponent(), 2);
source§fn from_integer_mantissa_and_exponent(
integer_mantissa: Natural,
integer_exponent: u64
) -> Option<Natural>
fn from_integer_mantissa_and_exponent( integer_mantissa: Natural, integer_exponent: u64 ) -> Option<Natural>
Constructs a Natural
from its integer mantissa and exponent.
When $x$ is nonzero, we can write $x = 2^{e_i}m_i$, where $e_i$ is an integer and $m_i$ is an odd integer.
$$ f(x) = 2^{e_i}m_i. $$
The input does not have to be reduced; that is, the mantissa does not have to be odd.
The result is an Option
, but for this trait implementation the result is always Some
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is `integer_mantissa.significant_bits()
- integer_exponent`.
§Examples
use malachite_base::num::conversion::traits::IntegerMantissaAndExponent;
use malachite_nz::natural::Natural;
let n = <&Natural as IntegerMantissaAndExponent<_, _, _>>
::from_integer_mantissa_and_exponent(Natural::from(123u32), 0).unwrap();
assert_eq!(n, 123);
let n = <&Natural as IntegerMantissaAndExponent<_, _, _>>
::from_integer_mantissa_and_exponent(Natural::from(25u32), 2).unwrap();
assert_eq!(n, 100);
source§impl<'a> IsInteger for &'a Natural
impl<'a> IsInteger for &'a Natural
source§fn is_integer(self) -> bool
fn is_integer(self) -> bool
Determines whether a Natural
is an integer. It always returns true
.
$f(x) = \textrm{true}$.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::basic::traits::{One, Zero};
use malachite_base::num::conversion::traits::IsInteger;
use malachite_nz::natural::Natural;
assert_eq!(Natural::ZERO.is_integer(), true);
assert_eq!(Natural::ONE.is_integer(), true);
assert_eq!(Natural::from(100u32).is_integer(), true);
source§impl IsPowerOf2 for Natural
impl IsPowerOf2 for Natural
source§fn is_power_of_2(&self) -> bool
fn is_power_of_2(&self) -> bool
Determines whether a Natural
is an integer power of 2.
$f(x) = (\exists n \in \Z : 2^n = x)$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::{IsPowerOf2, Pow};
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!(Natural::ZERO.is_power_of_2(), false);
assert_eq!(Natural::from(123u32).is_power_of_2(), false);
assert_eq!(Natural::from(0x80u32).is_power_of_2(), true);
assert_eq!(Natural::from(10u32).pow(12).is_power_of_2(), false);
assert_eq!(Natural::from_str("1099511627776").unwrap().is_power_of_2(), true);
source§impl<'a, 'b> JacobiSymbol<&'a Natural> for &'b Natural
impl<'a, 'b> JacobiSymbol<&'a Natural> for &'b Natural
source§fn jacobi_symbol(self, other: &'a Natural) -> i8
fn jacobi_symbol(self, other: &'a Natural) -> i8
Computes the Jacobi symbol of two Natural
s, taking both by reference.
$$ f(x, y) = \left ( \frac{x}{y} \right ). $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Panics
Panics if other
is even.
§Examples
use malachite_base::num::arithmetic::traits::JacobiSymbol;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::from(10u32)).jacobi_symbol(&Natural::from(5u32)), 0);
assert_eq!((&Natural::from(7u32)).jacobi_symbol(&Natural::from(5u32)), -1);
assert_eq!((&Natural::from(11u32)).jacobi_symbol(&Natural::from(5u32)), 1);
assert_eq!((&Natural::from(11u32)).jacobi_symbol(&Natural::from(9u32)), 1);
source§impl<'a> JacobiSymbol<&'a Natural> for Natural
impl<'a> JacobiSymbol<&'a Natural> for Natural
source§fn jacobi_symbol(self, other: &'a Natural) -> i8
fn jacobi_symbol(self, other: &'a Natural) -> i8
Computes the Jacobi symbol of two Natural
s, taking the first by value and the second by
reference.
$$ f(x, y) = \left ( \frac{x}{y} \right ). $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Panics
Panics if other
is even.
§Examples
use malachite_base::num::arithmetic::traits::JacobiSymbol;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(10u32).jacobi_symbol(&Natural::from(5u32)), 0);
assert_eq!(Natural::from(7u32).jacobi_symbol(&Natural::from(5u32)), -1);
assert_eq!(Natural::from(11u32).jacobi_symbol(&Natural::from(5u32)), 1);
assert_eq!(Natural::from(11u32).jacobi_symbol(&Natural::from(9u32)), 1);
source§impl<'a> JacobiSymbol<Natural> for &'a Natural
impl<'a> JacobiSymbol<Natural> for &'a Natural
source§fn jacobi_symbol(self, other: Natural) -> i8
fn jacobi_symbol(self, other: Natural) -> i8
Computes the Jacobi symbol of two Natural
s, taking the first by reference and the second
by value.
$$ f(x, y) = \left ( \frac{x}{y} \right ). $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Panics
Panics if other
is even.
§Examples
use malachite_base::num::arithmetic::traits::JacobiSymbol;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::from(10u32)).jacobi_symbol(Natural::from(5u32)), 0);
assert_eq!((&Natural::from(7u32)).jacobi_symbol(Natural::from(5u32)), -1);
assert_eq!((&Natural::from(11u32)).jacobi_symbol(Natural::from(5u32)), 1);
assert_eq!((&Natural::from(11u32)).jacobi_symbol(Natural::from(9u32)), 1);
source§impl JacobiSymbol for Natural
impl JacobiSymbol for Natural
source§fn jacobi_symbol(self, other: Natural) -> i8
fn jacobi_symbol(self, other: Natural) -> i8
Computes the Jacobi symbol of two Natural
s, taking both by value.
$$ f(x, y) = \left ( \frac{x}{y} \right ). $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Panics
Panics if other
is even.
§Examples
use malachite_base::num::arithmetic::traits::JacobiSymbol;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(10u32).jacobi_symbol(Natural::from(5u32)), 0);
assert_eq!(Natural::from(7u32).jacobi_symbol(Natural::from(5u32)), -1);
assert_eq!(Natural::from(11u32).jacobi_symbol(Natural::from(5u32)), 1);
assert_eq!(Natural::from(11u32).jacobi_symbol(Natural::from(9u32)), 1);
source§impl<'a, 'b> KroneckerSymbol<&'a Natural> for &'b Natural
impl<'a, 'b> KroneckerSymbol<&'a Natural> for &'b Natural
source§fn kronecker_symbol(self, other: &'a Natural) -> i8
fn kronecker_symbol(self, other: &'a Natural) -> i8
Computes the Kronecker symbol of two Natural
s, taking both by reference.
$$ f(x, y) = \left ( \frac{x}{y} \right ). $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::KroneckerSymbol;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::from(10u32)).kronecker_symbol(Natural::from(5u32)), 0);
assert_eq!((&Natural::from(7u32)).kronecker_symbol(Natural::from(5u32)), -1);
assert_eq!((&Natural::from(11u32)).kronecker_symbol(Natural::from(5u32)), 1);
assert_eq!((&Natural::from(11u32)).kronecker_symbol(Natural::from(9u32)), 1);
assert_eq!((&Natural::from(11u32)).kronecker_symbol(Natural::from(8u32)), -1);
source§impl<'a> KroneckerSymbol<&'a Natural> for Natural
impl<'a> KroneckerSymbol<&'a Natural> for Natural
source§fn kronecker_symbol(self, other: &'a Natural) -> i8
fn kronecker_symbol(self, other: &'a Natural) -> i8
Computes the Kronecker symbol of two Natural
s, taking the first by value and the second
by reference.
$$ f(x, y) = \left ( \frac{x}{y} \right ). $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::KroneckerSymbol;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(10u32).kronecker_symbol(&Natural::from(5u32)), 0);
assert_eq!(Natural::from(7u32).kronecker_symbol(&Natural::from(5u32)), -1);
assert_eq!(Natural::from(11u32).kronecker_symbol(&Natural::from(5u32)), 1);
assert_eq!(Natural::from(11u32).kronecker_symbol(&Natural::from(9u32)), 1);
assert_eq!(Natural::from(11u32).kronecker_symbol(&Natural::from(8u32)), -1);
source§impl<'a> KroneckerSymbol<Natural> for &'a Natural
impl<'a> KroneckerSymbol<Natural> for &'a Natural
source§fn kronecker_symbol(self, other: Natural) -> i8
fn kronecker_symbol(self, other: Natural) -> i8
Computes the Kronecker symbol of two Natural
s, taking the first by reference and the
second by value.
$$ f(x, y) = \left ( \frac{x}{y} \right ). $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::KroneckerSymbol;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::from(10u32)).kronecker_symbol(Natural::from(5u32)), 0);
assert_eq!((&Natural::from(7u32)).kronecker_symbol(Natural::from(5u32)), -1);
assert_eq!((&Natural::from(11u32)).kronecker_symbol(Natural::from(5u32)), 1);
assert_eq!((&Natural::from(11u32)).kronecker_symbol(Natural::from(9u32)), 1);
assert_eq!((&Natural::from(11u32)).kronecker_symbol(Natural::from(8u32)), -1);
source§impl KroneckerSymbol for Natural
impl KroneckerSymbol for Natural
source§fn kronecker_symbol(self, other: Natural) -> i8
fn kronecker_symbol(self, other: Natural) -> i8
Computes the Kronecker symbol of two Natural
s, taking both by value.
$$ f(x, y) = \left ( \frac{x}{y} \right ). $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::KroneckerSymbol;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(10u32).kronecker_symbol(Natural::from(5u32)), 0);
assert_eq!(Natural::from(7u32).kronecker_symbol(Natural::from(5u32)), -1);
assert_eq!(Natural::from(11u32).kronecker_symbol(Natural::from(5u32)), 1);
assert_eq!(Natural::from(11u32).kronecker_symbol(Natural::from(9u32)), 1);
assert_eq!(Natural::from(11u32).kronecker_symbol(Natural::from(8u32)), -1);
source§impl<'a, 'b> Lcm<&'a Natural> for &'b Natural
impl<'a, 'b> Lcm<&'a Natural> for &'b Natural
source§fn lcm(self, other: &'a Natural) -> Natural
fn lcm(self, other: &'a Natural) -> Natural
Computes the LCM (least common multiple) of two Natural
s, taking both by reference.
$$ f(x, y) = \operatorname{lcm}(x, y). $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::Lcm;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::from(3u32)).lcm(&Natural::from(5u32)), 15);
assert_eq!((&Natural::from(12u32)).lcm(&Natural::from(90u32)), 180);
type Output = Natural
source§impl<'a> Lcm<&'a Natural> for Natural
impl<'a> Lcm<&'a Natural> for Natural
source§fn lcm(self, other: &'a Natural) -> Natural
fn lcm(self, other: &'a Natural) -> Natural
Computes the LCM (least common multiple) of two Natural
s, taking the first by value and
the second by reference.
$$ f(x, y) = \operatorname{lcm}(x, y). $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::Lcm;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(3u32).lcm(&Natural::from(5u32)), 15);
assert_eq!(Natural::from(12u32).lcm(&Natural::from(90u32)), 180);
type Output = Natural
source§impl<'a> Lcm<Natural> for &'a Natural
impl<'a> Lcm<Natural> for &'a Natural
source§fn lcm(self, other: Natural) -> Natural
fn lcm(self, other: Natural) -> Natural
Computes the LCM (least common multiple) of two Natural
s, taking the first by reference
and the second by value.
$$ f(x, y) = \operatorname{lcm}(x, y). $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::Lcm;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::from(3u32)).lcm(Natural::from(5u32)), 15);
assert_eq!((&Natural::from(12u32)).lcm(Natural::from(90u32)), 180);
type Output = Natural
source§impl Lcm for Natural
impl Lcm for Natural
source§fn lcm(self, other: Natural) -> Natural
fn lcm(self, other: Natural) -> Natural
Computes the LCM (least common multiple) of two Natural
s, taking both by value.
$$ f(x, y) = \operatorname{lcm}(x, y). $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::Lcm;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(3u32).lcm(Natural::from(5u32)), 15);
assert_eq!(Natural::from(12u32).lcm(Natural::from(90u32)), 180);
type Output = Natural
source§impl<'a> LcmAssign<&'a Natural> for Natural
impl<'a> LcmAssign<&'a Natural> for Natural
source§fn lcm_assign(&mut self, other: &'a Natural)
fn lcm_assign(&mut self, other: &'a Natural)
Replaces a Natural
by its LCM (least common multiple) with another Natural
, taking
the Natural
on the right-hand side by reference.
$$ x \gets \operatorname{lcm}(x, y). $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::LcmAssign;
use malachite_nz::natural::Natural;
let mut x = Natural::from(3u32);
x.lcm_assign(&Natural::from(5u32));
assert_eq!(x, 15);
let mut x = Natural::from(12u32);
x.lcm_assign(&Natural::from(90u32));
assert_eq!(x, 180);
source§impl LcmAssign for Natural
impl LcmAssign for Natural
source§fn lcm_assign(&mut self, other: Natural)
fn lcm_assign(&mut self, other: Natural)
Replaces a Natural
by its LCM (least common multiple) with another Natural
, taking
the Natural
on the right-hand side by value.
$$ x \gets \operatorname{lcm}(x, y). $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::arithmetic::traits::LcmAssign;
use malachite_nz::natural::Natural;
let mut x = Natural::from(3u32);
x.lcm_assign(Natural::from(5u32));
assert_eq!(x, 15);
let mut x = Natural::from(12u32);
x.lcm_assign(Natural::from(90u32));
assert_eq!(x, 180);
source§impl<'a, 'b> LegendreSymbol<&'a Natural> for &'b Natural
impl<'a, 'b> LegendreSymbol<&'a Natural> for &'b Natural
source§fn legendre_symbol(self, other: &'a Natural) -> i8
fn legendre_symbol(self, other: &'a Natural) -> i8
Computes the Legendre symbol of two Natural
s, taking both by reference.
This implementation is identical to that of JacobiSymbol
, since there is no
computational benefit to requiring that the denominator be prime.
$$ f(x, y) = \left ( \frac{x}{y} \right ). $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Panics
Panics if other
is even.
§Examples
use malachite_base::num::arithmetic::traits::LegendreSymbol;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::from(10u32)).legendre_symbol(&Natural::from(5u32)), 0);
assert_eq!((&Natural::from(7u32)).legendre_symbol(&Natural::from(5u32)), -1);
assert_eq!((&Natural::from(11u32)).legendre_symbol(&Natural::from(5u32)), 1);
source§impl<'a> LegendreSymbol<&'a Natural> for Natural
impl<'a> LegendreSymbol<&'a Natural> for Natural
source§fn legendre_symbol(self, other: &'a Natural) -> i8
fn legendre_symbol(self, other: &'a Natural) -> i8
Computes the Legendre symbol of two Natural
s, taking the first by value and the second
by reference.
This implementation is identical to that of JacobiSymbol
, since there is no
computational benefit to requiring that the denominator be prime.
$$ f(x, y) = \left ( \frac{x}{y} \right ). $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Panics
Panics if other
is even.
§Examples
use malachite_base::num::arithmetic::traits::LegendreSymbol;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(10u32).legendre_symbol(&Natural::from(5u32)), 0);
assert_eq!(Natural::from(7u32).legendre_symbol(&Natural::from(5u32)), -1);
assert_eq!(Natural::from(11u32).legendre_symbol(&Natural::from(5u32)), 1);
source§impl<'a> LegendreSymbol<Natural> for &'a Natural
impl<'a> LegendreSymbol<Natural> for &'a Natural
source§fn legendre_symbol(self, other: Natural) -> i8
fn legendre_symbol(self, other: Natural) -> i8
Computes the Legendre symbol of two Natural
s, taking both the first by reference and the
second by value.
This implementation is identical to that of JacobiSymbol
, since there is no
computational benefit to requiring that the denominator be prime.
$$ f(x, y) = \left ( \frac{x}{y} \right ). $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Panics
Panics if other
is even.
§Examples
use malachite_base::num::arithmetic::traits::LegendreSymbol;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::from(10u32)).legendre_symbol(Natural::from(5u32)), 0);
assert_eq!((&Natural::from(7u32)).legendre_symbol(Natural::from(5u32)), -1);
assert_eq!((&Natural::from(11u32)).legendre_symbol(Natural::from(5u32)), 1);
source§impl LegendreSymbol for Natural
impl LegendreSymbol for Natural
source§fn legendre_symbol(self, other: Natural) -> i8
fn legendre_symbol(self, other: Natural) -> i8
Computes the Legendre symbol of two Natural
s, taking both by value.
This implementation is identical to that of JacobiSymbol
, since there is no
computational benefit to requiring that the denominator be prime.
$$ f(x, y) = \left ( \frac{x}{y} \right ). $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Panics
Panics if other
is even.
§Examples
use malachite_base::num::arithmetic::traits::LegendreSymbol;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(10u32).legendre_symbol(Natural::from(5u32)), 0);
assert_eq!(Natural::from(7u32).legendre_symbol(Natural::from(5u32)), -1);
assert_eq!(Natural::from(11u32).legendre_symbol(Natural::from(5u32)), 1);
source§impl LowMask for Natural
impl LowMask for Natural
source§fn low_mask(bits: u64) -> Natural
fn low_mask(bits: u64) -> Natural
Returns a Natural
whose least significant $b$ bits are true
and whose other bits are
false
.
$f(b) = 2^b - 1$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is bits
.
§Examples
use malachite_base::num::logic::traits::LowMask;
use malachite_nz::natural::Natural;
assert_eq!(Natural::low_mask(0), 0);
assert_eq!(Natural::low_mask(3), 7);
assert_eq!(Natural::low_mask(100).to_string(), "1267650600228229401496703205375");
source§impl LowerHex for Natural
impl LowerHex for Natural
source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Converts a Natural
to a hexadecimal String
using lowercase characters.
Using the #
format flag prepends "0x"
to the string.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_base::strings::ToLowerHexString;
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!(Natural::ZERO.to_lower_hex_string(), "0");
assert_eq!(Natural::from(123u32).to_lower_hex_string(), "7b");
assert_eq!(
Natural::from_str("1000000000000").unwrap().to_lower_hex_string(),
"e8d4a51000"
);
assert_eq!(format!("{:07x}", Natural::from(123u32)), "000007b");
assert_eq!(format!("{:#x}", Natural::ZERO), "0x0");
assert_eq!(format!("{:#x}", Natural::from(123u32)), "0x7b");
assert_eq!(
format!("{:#x}", Natural::from_str("1000000000000").unwrap()),
"0xe8d4a51000"
);
assert_eq!(format!("{:#07x}", Natural::from(123u32)), "0x0007b");
source§impl<'a, 'b> Mod<&'b Natural> for &'a Natural
impl<'a, 'b> Mod<&'b Natural> for &'a Natural
source§fn mod_op(self, other: &'b Natural) -> Natural
fn mod_op(self, other: &'b Natural) -> Natural
Divides a Natural
by another Natural
, taking both by reference and returning just
the remainder.
If the quotient were computed, the quotient and remainder would satisfy $x = qy + r$ and $0 \leq r < y$.
$$ f(x, y) = x - y\left \lfloor \frac{x}{y} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_base::num::arithmetic::traits::Mod;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 2 * 10 + 3 = 23
assert_eq!((&Natural::from(23u32)).mod_op(&Natural::from(10u32)), 3);
// 810000006723 * 1234567890987 + 530068894399 = 1000000000000000000000000
assert_eq!(
(&Natural::from_str("1000000000000000000000000").unwrap())
.mod_op(&Natural::from_str("1234567890987").unwrap()),
530068894399u64
);
type Output = Natural
source§impl<'a> Mod<&'a Natural> for Natural
impl<'a> Mod<&'a Natural> for Natural
source§fn mod_op(self, other: &'a Natural) -> Natural
fn mod_op(self, other: &'a Natural) -> Natural
Divides a Natural
by another Natural
, taking the first by value and the second by
reference and returning just the remainder.
If the quotient were computed, the quotient and remainder would satisfy $x = qy + r$ and $0 \leq r < y$.
$$ f(x, y) = x - y\left \lfloor \frac{x}{y} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_base::num::arithmetic::traits::Mod;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 2 * 10 + 3 = 23
assert_eq!(Natural::from(23u32).mod_op(&Natural::from(10u32)), 3);
// 810000006723 * 1234567890987 + 530068894399 = 1000000000000000000000000
assert_eq!(
Natural::from_str("1000000000000000000000000").unwrap()
.mod_op(&Natural::from_str("1234567890987").unwrap()),
530068894399u64
);
type Output = Natural
source§impl<'a> Mod<Natural> for &'a Natural
impl<'a> Mod<Natural> for &'a Natural
source§fn mod_op(self, other: Natural) -> Natural
fn mod_op(self, other: Natural) -> Natural
Divides a Natural
by another Natural
, taking the first by reference and the second
by value and returning just the remainder.
If the quotient were computed, the quotient and remainder would satisfy $x = qy + r$ and $0 \leq r < y$.
$$ f(x, y) = x - y\left \lfloor \frac{x}{y} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_base::num::arithmetic::traits::Mod;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 2 * 10 + 3 = 23
assert_eq!((&Natural::from(23u32)).mod_op(Natural::from(10u32)), 3);
// 810000006723 * 1234567890987 + 530068894399 = 1000000000000000000000000
assert_eq!(
(&Natural::from_str("1000000000000000000000000").unwrap())
.mod_op(Natural::from_str("1234567890987").unwrap()),
530068894399u64
);
type Output = Natural
source§impl Mod for Natural
impl Mod for Natural
source§fn mod_op(self, other: Natural) -> Natural
fn mod_op(self, other: Natural) -> Natural
Divides a Natural
by another Natural
, taking both by value and returning just the
remainder.
If the quotient were computed, the quotient and remainder would satisfy $x = qy + r$ and $0 \leq r < y$.
$$ f(x, y) = x - y\left \lfloor \frac{x}{y} \right \rfloor. $$
This function is called mod_op
rather than mod
because mod
is a Rust keyword.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_base::num::arithmetic::traits::Mod;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 2 * 10 + 3 = 23
assert_eq!(Natural::from(23u32).mod_op(Natural::from(10u32)), 3);
// 810000006723 * 1234567890987 + 530068894399 = 1000000000000000000000000
assert_eq!(
Natural::from_str("1000000000000000000000000").unwrap()
.mod_op(Natural::from_str("1234567890987").unwrap()),
530068894399u64
);
type Output = Natural
source§impl<'a> ModAdd<&'a Natural> for Natural
impl<'a> ModAdd<&'a Natural> for Natural
source§fn mod_add(self, other: &'a Natural, m: Natural) -> Natural
fn mod_add(self, other: &'a Natural, m: Natural) -> Natural
Adds two Natural
s modulo a third Natural
$m$. The inputs must be already reduced
modulo $m$. The first and third Natural
s are taken by value and the second by reference.
$f(x, y, m) = z$, where $x, y, z < m$ and $x + y \equiv z \mod m$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModAdd;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!(Natural::ZERO.mod_add(&Natural::from(3u32), Natural::from(5u32)), 3);
assert_eq!(Natural::from(7u32).mod_add(&Natural::from(5u32), Natural::from(10u32)), 2);
This is equivalent to _fmpz_mod_addN
from fmpz_mod/add.c
, FLINT 2.7.1, where b
and m
are taken by value and c
is taken by reference.
type Output = Natural
source§impl<'a, 'b, 'c> ModAdd<&'b Natural, &'c Natural> for &'a Natural
impl<'a, 'b, 'c> ModAdd<&'b Natural, &'c Natural> for &'a Natural
source§fn mod_add(self, other: &'b Natural, m: &'c Natural) -> Natural
fn mod_add(self, other: &'b Natural, m: &'c Natural) -> Natural
Adds two Natural
s modulo a third Natural
$m$. The inputs must be already reduced
modulo $m$. All three Natural
s are taken by reference.
$f(x, y, m) = z$, where $x, y, z < m$ and $x + y \equiv z \mod m$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModAdd;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::ZERO).mod_add(&Natural::from(3u32), &Natural::from(5u32)), 3);
assert_eq!((&Natural::from(7u32)).mod_add(&Natural::from(5u32), &Natural::from(10u32)), 2);
This is equivalent to _fmpz_mod_addN
from fmpz_mod/add.c
, FLINT 2.7.1, where b
, c
,
and m
are taken by reference.
type Output = Natural
source§impl<'a, 'b> ModAdd<&'a Natural, &'b Natural> for Natural
impl<'a, 'b> ModAdd<&'a Natural, &'b Natural> for Natural
source§fn mod_add(self, other: &'a Natural, m: &'b Natural) -> Natural
fn mod_add(self, other: &'a Natural, m: &'b Natural) -> Natural
Adds two Natural
s modulo a third Natural
$m$. The inputs must be already reduced
modulo $m$. The first Natural
is taken by value and the second and third by reference.
$f(x, y, m) = z$, where $x, y, z < m$ and $x + y \equiv z \mod m$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModAdd;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!(Natural::ZERO.mod_add(&Natural::from(3u32), &Natural::from(5u32)), 3);
assert_eq!(Natural::from(7u32).mod_add(&Natural::from(5u32), &Natural::from(10u32)), 2);
This is equivalent to _fmpz_mod_addN
from fmpz_mod/add.c
, FLINT 2.7.1, where b
is
taken by value and c
and m
are taken by reference.
type Output = Natural
source§impl<'a, 'b> ModAdd<&'b Natural, Natural> for &'a Natural
impl<'a, 'b> ModAdd<&'b Natural, Natural> for &'a Natural
source§fn mod_add(self, other: &'b Natural, m: Natural) -> Natural
fn mod_add(self, other: &'b Natural, m: Natural) -> Natural
Adds two Natural
s modulo a third Natural
$m$. The inputs must be already reduced
modulo $m$. The first two Natural
s are taken by reference and the third by value.
$f(x, y, m) = z$, where $x, y, z < m$ and $x + y \equiv z \mod m$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModAdd;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::ZERO).mod_add(&Natural::from(3u32), Natural::from(5u32)), 3);
assert_eq!((&Natural::from(7u32)).mod_add(&Natural::from(5u32), Natural::from(10u32)), 2);
This is equivalent to _fmpz_mod_addN
from fmpz_mod/add.c
, FLINT 2.7.1, where b
and c
are taken by reference and m
is taken by value.
type Output = Natural
source§impl<'a, 'b> ModAdd<Natural, &'b Natural> for &'a Natural
impl<'a, 'b> ModAdd<Natural, &'b Natural> for &'a Natural
source§fn mod_add(self, other: Natural, m: &'b Natural) -> Natural
fn mod_add(self, other: Natural, m: &'b Natural) -> Natural
Adds two Natural
s modulo a third Natural
$m$. The inputs must be already reduced
modulo $m$. The first and third Natural
s are taken by reference and the second by value.
$f(x, y, m) = z$, where $x, y, z < m$ and $x + y \equiv z \mod m$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModAdd;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::ZERO).mod_add(Natural::from(3u32), &Natural::from(5u32)), 3);
assert_eq!((&Natural::from(7u32)).mod_add(Natural::from(5u32), &Natural::from(10u32)), 2);
This is equivalent to _fmpz_mod_addN
from fmpz_mod/add.c
, FLINT 2.7.1, where b
and m
are taken by reference and c
is taken by value.
type Output = Natural
source§impl<'a> ModAdd<Natural, &'a Natural> for Natural
impl<'a> ModAdd<Natural, &'a Natural> for Natural
source§fn mod_add(self, other: Natural, m: &'a Natural) -> Natural
fn mod_add(self, other: Natural, m: &'a Natural) -> Natural
Adds two Natural
s modulo a third Natural
$m$. The inputs must be already reduced
modulo $m$. The first two Natural
s are taken by value and the third by reference.
$f(x, y, m) = z$, where $x, y, z < m$ and $x + y \equiv z \mod m$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModAdd;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!(Natural::ZERO.mod_add(Natural::from(3u32), &Natural::from(5u32)), 3);
assert_eq!(Natural::from(7u32).mod_add(Natural::from(5u32), &Natural::from(10u32)), 2);
This is equivalent to _fmpz_mod_addN
from fmpz_mod/add.c
, FLINT 2.7.1, where b
and c
are taken by value and m
is taken by reference.
type Output = Natural
source§impl<'a> ModAdd<Natural, Natural> for &'a Natural
impl<'a> ModAdd<Natural, Natural> for &'a Natural
source§fn mod_add(self, other: Natural, m: Natural) -> Natural
fn mod_add(self, other: Natural, m: Natural) -> Natural
Adds two Natural
s modulo a third Natural
$m$. The inputs must be already reduced
modulo $m$. The first Natural
is taken by reference and the second and third by value.
$f(x, y, m) = z$, where $x, y, z < m$ and $x + y \equiv z \mod m$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModAdd;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!(
(&Natural::ZERO).mod_add(Natural::from(3u32), Natural::from(5u32)).to_string(),
"3"
);
assert_eq!(
(&Natural::from(7u32)).mod_add(Natural::from(5u32), Natural::from(10u32)).to_string(),
"2"
);
This is equivalent to _fmpz_mod_addN
from fmpz_mod/add.c
, FLINT 2.7.1, where b
is
taken by reference and c
and m
are taken by value.
type Output = Natural
source§impl ModAdd for Natural
impl ModAdd for Natural
source§fn mod_add(self, other: Natural, m: Natural) -> Natural
fn mod_add(self, other: Natural, m: Natural) -> Natural
Adds two Natural
s modulo a third Natural
$m$. The inputs must be already reduced
modulo $m$. All three Natural
s are taken by value.
$f(x, y, m) = z$, where $x, y, z < m$ and $x + y \equiv z \mod m$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModAdd;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!(Natural::ZERO.mod_add(Natural::from(3u32), Natural::from(5u32)), 3);
assert_eq!(Natural::from(7u32).mod_add(Natural::from(5u32), Natural::from(10u32)), 2);
This is equivalent to _fmpz_mod_addN
from fmpz_mod/add.c
, FLINT 2.7.1, where b
, c
,
and m
are taken by value.
type Output = Natural
source§impl<'a> ModAddAssign<&'a Natural> for Natural
impl<'a> ModAddAssign<&'a Natural> for Natural
source§fn mod_add_assign(&mut self, other: &'a Natural, m: Natural)
fn mod_add_assign(&mut self, other: &'a Natural, m: Natural)
Adds two Natural
s modulo a third Natural
$m$, in place. The inputs must be already
reduced modulo $m$. The first Natural
on the right-hand side is taken by reference and
the second by value.
$x \gets z$, where $x, y, z < m$ and $x + y \equiv z \mod m$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModAddAssign;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
let mut x = Natural::ZERO;
x.mod_add_assign(&Natural::from(3u32), Natural::from(5u32));
assert_eq!(x, 3);
let mut x = Natural::from(7u32);
x.mod_add_assign(&Natural::from(5u32), Natural::from(10u32));
assert_eq!(x, 2);
This is equivalent to _fmpz_mod_addN
from fmpz_mod/add.c
, FLINT 2.7.1, where b
and m
are taken by value, c
is taken by reference, and a == b
.
source§impl<'a, 'b> ModAddAssign<&'a Natural, &'b Natural> for Natural
impl<'a, 'b> ModAddAssign<&'a Natural, &'b Natural> for Natural
source§fn mod_add_assign(&mut self, other: &'a Natural, m: &'b Natural)
fn mod_add_assign(&mut self, other: &'a Natural, m: &'b Natural)
Adds two Natural
s modulo a third Natural
$m$, in place. The inputs must be already
reduced modulo $m$. Both Natural
s on the right-hand side are taken by reference.
$x \gets z$, where $x, y, z < m$ and $x + y \equiv z \mod m$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModAddAssign;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
let mut x = Natural::ZERO;
x.mod_add_assign(&Natural::from(3u32), &Natural::from(5u32));
assert_eq!(x, 3);
let mut x = Natural::from(7u32);
x.mod_add_assign(&Natural::from(5u32), &Natural::from(10u32));
assert_eq!(x, 2);
This is equivalent to _fmpz_mod_addN
from fmpz_mod/add.c
, FLINT 2.7.1, where b
is
taken by value, c
and m
are taken by reference, and a == b
.
source§impl<'a> ModAddAssign<Natural, &'a Natural> for Natural
impl<'a> ModAddAssign<Natural, &'a Natural> for Natural
source§fn mod_add_assign(&mut self, other: Natural, m: &'a Natural)
fn mod_add_assign(&mut self, other: Natural, m: &'a Natural)
Adds two Natural
s modulo a third Natural
$m$, in place. The inputs must be already
reduced modulo $m$. The first Natural
on the right-hand side is taken by value and the
second by reference.
$x \gets z$, where $x, y, z < m$ and $x + y \equiv z \mod m$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModAddAssign;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
let mut x = Natural::ZERO;
x.mod_add_assign(Natural::from(3u32), &Natural::from(5u32));
assert_eq!(x, 3);
let mut x = Natural::from(7u32);
x.mod_add_assign(Natural::from(5u32), &Natural::from(10u32));
assert_eq!(x, 2);
This is equivalent to _fmpz_mod_addN
from fmpz_mod/add.c
, FLINT 2.7.1, where b
and c
are taken by value, m
is taken by reference, and a == b
.
source§impl ModAddAssign for Natural
impl ModAddAssign for Natural
source§fn mod_add_assign(&mut self, other: Natural, m: Natural)
fn mod_add_assign(&mut self, other: Natural, m: Natural)
Adds two Natural
s modulo a third Natural
$m$, in place. The inputs must be already
reduced modulo $m$. Both Natural
s on the right-hand side are taken by value.
$x \gets z$, where $x, y, z < m$ and $x + y \equiv z \mod m$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModAddAssign;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
let mut x = Natural::ZERO;
x.mod_add_assign(Natural::from(3u32), Natural::from(5u32));
assert_eq!(x, 3);
let mut x = Natural::from(7u32);
x.mod_add_assign(Natural::from(5u32), Natural::from(10u32));
assert_eq!(x, 2);
This is equivalent to _fmpz_mod_addN
from fmpz_mod/add.c
, FLINT 2.7.1, where b
, c
,
and m
are taken by value and a == b
.
source§impl<'a> ModAssign<&'a Natural> for Natural
impl<'a> ModAssign<&'a Natural> for Natural
source§fn mod_assign(&mut self, other: &'a Natural)
fn mod_assign(&mut self, other: &'a Natural)
Divides a Natural
by another Natural
, taking the second Natural
by reference and
replacing the first by the remainder.
If the quotient were computed, he quotient and remainder would satisfy $x = qy + r$ and $0 \leq r < y$.
$$ x \gets x - y\left \lfloor \frac{x}{y} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_base::num::arithmetic::traits::ModAssign;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 2 * 10 + 3 = 23
let mut x = Natural::from(23u32);
x.mod_assign(&Natural::from(10u32));
assert_eq!(x, 3);
// 810000006723 * 1234567890987 + 530068894399 = 1000000000000000000000000
let mut x = Natural::from_str("1000000000000000000000000").unwrap();
x.mod_assign(&Natural::from_str("1234567890987").unwrap());
assert_eq!(x, 530068894399u64);
source§impl ModAssign for Natural
impl ModAssign for Natural
source§fn mod_assign(&mut self, other: Natural)
fn mod_assign(&mut self, other: Natural)
Divides a Natural
by another Natural
, taking the second Natural
by value and
replacing the first by the remainder.
If the quotient were computed, he quotient and remainder would satisfy $x = qy + r$ and $0 \leq r < y$.
$$ x \gets x - y\left \lfloor \frac{x}{y} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_base::num::arithmetic::traits::ModAssign;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 2 * 10 + 3 = 23
let mut x = Natural::from(23u32);
x.mod_assign(Natural::from(10u32));
assert_eq!(x, 3);
// 810000006723 * 1234567890987 + 530068894399 = 1000000000000000000000000
let mut x = Natural::from_str("1000000000000000000000000").unwrap();
x.mod_assign(Natural::from_str("1234567890987").unwrap());
assert_eq!(x, 530068894399u64);
source§impl<'a, 'b> ModInverse<&'a Natural> for &'b Natural
impl<'a, 'b> ModInverse<&'a Natural> for &'b Natural
source§fn mod_inverse(self, m: &'a Natural) -> Option<Natural>
fn mod_inverse(self, m: &'a Natural) -> Option<Natural>
Computes the multiplicative inverse of a Natural
modulo another Natural
$m$. The
input must be already reduced modulo $m$. Both Natural
s are taken by reference.
Returns None
if $x$ and $m$ are not coprime.
$f(x, m) = y$, where $x, y < m$, $\gcd(x, y) = 1$, and $xy \equiv 1 \mod m$.
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), m.significant_bits())
.
§Panics
Panics if self
is 0 or if self
is greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModInverse;
use malachite_nz::natural::Natural;
assert_eq!(
(&Natural::from(3u32)).mod_inverse(&Natural::from(10u32)),
Some(Natural::from(7u32))
);
assert_eq!((&Natural::from(4u32)).mod_inverse(&Natural::from(10u32)), None);
type Output = Natural
source§impl<'a> ModInverse<&'a Natural> for Natural
impl<'a> ModInverse<&'a Natural> for Natural
source§fn mod_inverse(self, m: &'a Natural) -> Option<Natural>
fn mod_inverse(self, m: &'a Natural) -> Option<Natural>
Computes the multiplicative inverse of a Natural
modulo another Natural
$m$. The
input must be already reduced modulo $m$. The first Natural
is taken by value and the
second by reference.
Returns None
if $x$ and $m$ are not coprime.
$f(x, m) = y$, where $x, y < m$, $\gcd(x, y) = 1$, and $xy \equiv 1 \mod m$.
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), m.significant_bits())
.
§Panics
Panics if self
is 0 or if self
is greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModInverse;
use malachite_nz::natural::Natural;
assert_eq!(
Natural::from(3u32).mod_inverse(&Natural::from(10u32)),
Some(Natural::from(7u32))
);
assert_eq!(Natural::from(4u32).mod_inverse(&Natural::from(10u32)), None);
type Output = Natural
source§impl<'a> ModInverse<Natural> for &'a Natural
impl<'a> ModInverse<Natural> for &'a Natural
source§fn mod_inverse(self, m: Natural) -> Option<Natural>
fn mod_inverse(self, m: Natural) -> Option<Natural>
Computes the multiplicative inverse of a Natural
modulo another Natural
$m$. The
input must be already reduced modulo $m$. The first Natural
s is taken by reference and
the second by value.
Returns None
if $x$ and $m$ are not coprime.
$f(x, m) = y$, where $x, y < m$, $\gcd(x, y) = 1$, and $xy \equiv 1 \mod m$.
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), m.significant_bits())
.
§Panics
Panics if self
is 0 or if self
is greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModInverse;
use malachite_nz::natural::Natural;
assert_eq!(
(&Natural::from(3u32)).mod_inverse(Natural::from(10u32)),
Some(Natural::from(7u32))
);
assert_eq!((&Natural::from(4u32)).mod_inverse(Natural::from(10u32)), None);
type Output = Natural
source§impl ModInverse for Natural
impl ModInverse for Natural
source§fn mod_inverse(self, m: Natural) -> Option<Natural>
fn mod_inverse(self, m: Natural) -> Option<Natural>
Computes the multiplicative inverse of a Natural
modulo another Natural
$m$. The
input must be already reduced modulo $m$. Both Natural
s are taken by value.
Returns None
if $x$ and $m$ are not coprime.
$f(x, m) = y$, where $x, y < m$, $\gcd(x, y) = 1$, and $xy \equiv 1 \mod m$.
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), m.significant_bits())
.
§Panics
Panics if self
is 0 or if self
is greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModInverse;
use malachite_nz::natural::Natural;
assert_eq!(
Natural::from(3u32).mod_inverse(Natural::from(10u32)),
Some(Natural::from(7u32))
);
assert_eq!(Natural::from(4u32).mod_inverse(Natural::from(10u32)), None);
type Output = Natural
source§impl ModIsReduced for Natural
impl ModIsReduced for Natural
source§fn mod_is_reduced(&self, m: &Natural) -> bool
fn mod_is_reduced(&self, m: &Natural) -> bool
Returns whether a Natural
is reduced modulo another Natural
$m$; in other words,
whether it is less than $m$.
$m$ cannot be zero.
$f(x, m) = (x < m)$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if m
is 0.
§Examples
use malachite_base::num::arithmetic::traits::{ModIsReduced, Pow};
use malachite_base::num::basic::traits::{One, Zero};
use malachite_nz::natural::Natural;
assert_eq!(Natural::ZERO.mod_is_reduced(&Natural::from(5u32)), true);
assert_eq!(
Natural::from(10u32).pow(12).mod_is_reduced(&Natural::from(10u32).pow(12)),
false
);
assert_eq!(
Natural::from(10u32).pow(12)
.mod_is_reduced(&(Natural::from(10u32).pow(12) + Natural::ONE)),
true
);
source§impl<'a> ModMul<&'a Natural> for Natural
impl<'a> ModMul<&'a Natural> for Natural
source§fn mod_mul(self, other: &'a Natural, m: Natural) -> Natural
fn mod_mul(self, other: &'a Natural, m: Natural) -> Natural
Multiplies two Natural
s modulo a third Natural
$m$. The inputs must be already
reduced modulo $m$. The first and third Natural
s are taken by value and the second by
reference.
$f(x, y, m) = z$, where $x, y, z < m$ and $xy \equiv z \mod m$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModMul;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(3u32).mod_mul(&Natural::from(4u32), Natural::from(15u32)), 12);
assert_eq!(Natural::from(7u32).mod_mul(&Natural::from(6u32), Natural::from(10u32)), 2);
This is equivalent to _fmpz_mod_mulN
from fmpz_mod/mul.c
, FLINT 2.7.1, where b
and m
are taken by value and c
is taken by reference.
type Output = Natural
source§impl<'a, 'b, 'c> ModMul<&'b Natural, &'c Natural> for &'a Natural
impl<'a, 'b, 'c> ModMul<&'b Natural, &'c Natural> for &'a Natural
source§fn mod_mul(self, other: &'b Natural, m: &'c Natural) -> Natural
fn mod_mul(self, other: &'b Natural, m: &'c Natural) -> Natural
Multiplies two Natural
s modulo a third Natural
$m$. The inputs must be already
reduced modulo $m$. All three Natural
s are taken by reference.
$f(x, y, m) = z$, where $x, y, z < m$ and $xy \equiv z \mod m$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModMul;
use malachite_nz::natural::Natural;
assert_eq!(
(&Natural::from(3u32)).mod_mul(&Natural::from(4u32), &Natural::from(15u32)),
12
);
assert_eq!((&Natural::from(7u32)).mod_mul(&Natural::from(6u32), &Natural::from(10u32)), 2);
This is equivalent to _fmpz_mod_mulN
from fmpz_mod/mul.c
, FLINT 2.7.1, where b
, c
,
and m
are taken by reference.
type Output = Natural
source§impl<'a, 'b> ModMul<&'a Natural, &'b Natural> for Natural
impl<'a, 'b> ModMul<&'a Natural, &'b Natural> for Natural
source§fn mod_mul(self, other: &'a Natural, m: &'b Natural) -> Natural
fn mod_mul(self, other: &'a Natural, m: &'b Natural) -> Natural
Multiplies two Natural
s modulo a third Natural
$m$. The inputs must be already
reduced modulo $m$. The first Natural
is taken by value and the second and third by
reference.
$f(x, y, m) = z$, where $x, y, z < m$ and $xy \equiv z \mod m$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModMul;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(3u32).mod_mul(&Natural::from(4u32), &Natural::from(15u32)), 12);
assert_eq!(Natural::from(7u32).mod_mul(&Natural::from(6u32), &Natural::from(10u32)), 2);
This is equivalent to _fmpz_mod_mulN
from fmpz_mod/mul.c
, FLINT 2.7.1, where b
is
taken by value and c
and m
are taken by reference.
type Output = Natural
source§impl<'a, 'b> ModMul<&'b Natural, Natural> for &'a Natural
impl<'a, 'b> ModMul<&'b Natural, Natural> for &'a Natural
source§fn mod_mul(self, other: &'b Natural, m: Natural) -> Natural
fn mod_mul(self, other: &'b Natural, m: Natural) -> Natural
Multiplies two Natural
s modulo a third Natural
$m$. The inputs must be already
reduced modulo $m$. The first two Natural
s are taken by reference and the third by
value.
$f(x, y, m) = z$, where $x, y, z < m$ and $xy \equiv z \mod m$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModMul;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::from(3u32)).mod_mul(&Natural::from(4u32), Natural::from(15u32)), 12);
assert_eq!((&Natural::from(7u32)).mod_mul(&Natural::from(6u32), Natural::from(10u32)), 2);
This is equivalent to _fmpz_mod_mulN
from fmpz_mod/mul.c
, FLINT 2.7.1, where b
and c
are taken by reference and m
is taken by value.
type Output = Natural
source§impl<'a, 'b> ModMul<Natural, &'b Natural> for &'a Natural
impl<'a, 'b> ModMul<Natural, &'b Natural> for &'a Natural
source§fn mod_mul(self, other: Natural, m: &'b Natural) -> Natural
fn mod_mul(self, other: Natural, m: &'b Natural) -> Natural
Multiplies two Natural
s modulo a third Natural
$m$. The inputs must be already
reduced modulo $m$. The first and third Natural
s are taken by reference and the second
by value.
$f(x, y, m) = z$, where $x, y, z < m$ and $xy \equiv z \mod m$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModMul;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::from(3u32)).mod_mul(Natural::from(4u32), &Natural::from(15u32)), 12);
assert_eq!((&Natural::from(7u32)).mod_mul(Natural::from(6u32), &Natural::from(10u32)), 2);
This is equivalent to _fmpz_mod_mulN
from fmpz_mod/mul.c
, FLINT 2.7.1, where b
and m
are taken by reference and c
is taken by value.
type Output = Natural
source§impl<'a> ModMul<Natural, &'a Natural> for Natural
impl<'a> ModMul<Natural, &'a Natural> for Natural
source§fn mod_mul(self, other: Natural, m: &'a Natural) -> Natural
fn mod_mul(self, other: Natural, m: &'a Natural) -> Natural
Multiplies two Natural
s modulo a third Natural
$m$. The inputs must be already
reduced modulo $m$. The first two Natural
s are taken by value and the third by
reference.
$f(x, y, m) = z$, where $x, y, z < m$ and $xy \equiv z \mod m$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModMul;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(3u32).mod_mul(Natural::from(4u32), &Natural::from(15u32)), 12);
assert_eq!(Natural::from(7u32).mod_mul(Natural::from(6u32), &Natural::from(10u32)), 2);
This is equivalent to _fmpz_mod_mulN
from fmpz_mod/mul.c
, FLINT 2.7.1, where b
and c
are taken by value and m
is taken by reference.
type Output = Natural
source§impl<'a> ModMul<Natural, Natural> for &'a Natural
impl<'a> ModMul<Natural, Natural> for &'a Natural
source§fn mod_mul(self, other: Natural, m: Natural) -> Natural
fn mod_mul(self, other: Natural, m: Natural) -> Natural
Multiplies two Natural
s modulo a third Natural
$m$. The inputs must be already
reduced modulo $m$. The first Natural
is taken by reference and the second and third by
value.
$f(x, y, m) = z$, where $x, y, z < m$ and $xy \equiv z \mod m$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModMul;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::from(3u32)).mod_mul(Natural::from(4u32), Natural::from(15u32)), 12);
assert_eq!((&Natural::from(7u32)).mod_mul(Natural::from(6u32), Natural::from(10u32)), 2);
This is equivalent to _fmpz_mod_mulN
from fmpz_mod/mul.c
, FLINT 2.7.1, where b
is
taken by reference and c
and m
are taken by value.
type Output = Natural
source§impl ModMul for Natural
impl ModMul for Natural
source§fn mod_mul(self, other: Natural, m: Natural) -> Natural
fn mod_mul(self, other: Natural, m: Natural) -> Natural
Multiplies two Natural
s modulo a third Natural
$m$. The inputs must be already
reduced modulo $m$. All three Natural
s are taken by value.
$f(x, y, m) = z$, where $x, y, z < m$ and $xy \equiv z \mod m$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModMul;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(3u32).mod_mul(Natural::from(4u32), Natural::from(15u32)), 12);
assert_eq!(Natural::from(7u32).mod_mul(Natural::from(6u32), Natural::from(10u32)), 2);
This is equivalent to _fmpz_mod_mulN
from fmpz_mod/mul.c
, FLINT 2.7.1, where b
, c
,
and m
are taken by value.
type Output = Natural
source§impl<'a> ModMulAssign<&'a Natural> for Natural
impl<'a> ModMulAssign<&'a Natural> for Natural
source§fn mod_mul_assign(&mut self, other: &'a Natural, m: Natural)
fn mod_mul_assign(&mut self, other: &'a Natural, m: Natural)
Multiplies two Natural
s modulo a third Natural
$m$, in place. The inputs must be
already reduced modulo $m$. The first Natural
on the right-hand side is taken by
reference and the second by value.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModMulAssign;
use malachite_nz::natural::Natural;
let mut x = Natural::from(3u32);
x.mod_mul_assign(&Natural::from(4u32), Natural::from(15u32));
assert_eq!(x, 12);
let mut x = Natural::from(7u32);
x.mod_mul_assign(&Natural::from(6u32), Natural::from(10u32));
assert_eq!(x, 2);
This is equivalent to _fmpz_mod_mulN
from fmpz_mod/mul.c
, FLINT 2.7.1, where b
and m
are taken by value, c
is taken by reference, and a == b
.
source§impl<'a, 'b> ModMulAssign<&'a Natural, &'b Natural> for Natural
impl<'a, 'b> ModMulAssign<&'a Natural, &'b Natural> for Natural
source§fn mod_mul_assign(&mut self, other: &'a Natural, m: &'b Natural)
fn mod_mul_assign(&mut self, other: &'a Natural, m: &'b Natural)
Multiplies two Natural
s modulo a third Natural
$m$, in place. The inputs must be
already reduced modulo $m$. Both Natural
s on the right-hand side are taken by reference.
$x \gets z$, where $x, y, z < m$ and $xy \equiv z \mod m$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModMulAssign;
use malachite_nz::natural::Natural;
let mut x = Natural::from(3u32);
x.mod_mul_assign(&Natural::from(4u32), &Natural::from(15u32));
assert_eq!(x, 12);
let mut x = Natural::from(7u32);
x.mod_mul_assign(&Natural::from(6u32), &Natural::from(10u32));
assert_eq!(x, 2);
This is equivalent to _fmpz_mod_mulN
from fmpz_mod/mul.c
, FLINT 2.7.1, where b
is
taken by value, c
and m
are taken by reference, and a == b
.
source§impl<'a> ModMulAssign<Natural, &'a Natural> for Natural
impl<'a> ModMulAssign<Natural, &'a Natural> for Natural
source§fn mod_mul_assign(&mut self, other: Natural, m: &'a Natural)
fn mod_mul_assign(&mut self, other: Natural, m: &'a Natural)
Multiplies two Natural
s modulo a third Natural
$m$, in place. The inputs must be
already reduced modulo $m$. The first Natural
on the right-hand side is taken by value
and the second by reference.
$x \gets z$, where $x, y, z < m$ and $xy \equiv z \mod m$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModMulAssign;
use malachite_nz::natural::Natural;
let mut x = Natural::from(3u32);
x.mod_mul_assign(Natural::from(4u32), &Natural::from(15u32));
assert_eq!(x, 12);
let mut x = Natural::from(7u32);
x.mod_mul_assign(Natural::from(6u32), &Natural::from(10u32));
assert_eq!(x, 2);
This is equivalent to _fmpz_mod_mulN
from fmpz_mod/mul.c
, FLINT 2.7.1, where b
and c
are taken by value, m
is taken by reference, and a == b
.
source§impl ModMulAssign for Natural
impl ModMulAssign for Natural
source§fn mod_mul_assign(&mut self, other: Natural, m: Natural)
fn mod_mul_assign(&mut self, other: Natural, m: Natural)
Multiplies two Natural
s modulo a third Natural
$m$, in place. The inputs must be
already reduced modulo $m$. Both Natural
s on the right-hand side are taken by value.
$x \gets z$, where $x, y, z < m$ and $xy \equiv z \mod m$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModMulAssign;
use malachite_nz::natural::Natural;
let mut x = Natural::from(3u32);
x.mod_mul_assign(Natural::from(4u32), Natural::from(15u32));
assert_eq!(x, 12);
let mut x = Natural::from(7u32);
x.mod_mul_assign(Natural::from(6u32), Natural::from(10u32));
assert_eq!(x, 2);
This is equivalent to _fmpz_mod_mulN
from fmpz_mod/mul.c
, FLINT 2.7.1, where b
, c
,
and m
are taken by value and a == b
.
source§impl<'a> ModMulPrecomputed<&'a Natural> for Natural
impl<'a> ModMulPrecomputed<&'a Natural> for Natural
source§fn precompute_mod_mul_data(m: &Natural) -> ModMulData
fn precompute_mod_mul_data(m: &Natural) -> ModMulData
Precomputes data for modular multiplication. See mod_mul_precomputed
and
mod_mul_precomputed_assign
.
§Worst-case complexity
Constant time and additional memory.
This is equivalent to part of fmpz_mod_ctx_init
from fmpz_mod/ctx_init.c
, FLINT 2.7.1.
source§fn mod_mul_precomputed(
self,
other: &'a Natural,
m: Natural,
data: &ModMulData
) -> Natural
fn mod_mul_precomputed( self, other: &'a Natural, m: Natural, data: &ModMulData ) -> Natural
Multiplies two Natural
modulo a third Natural
$m$. The inputs must be already
reduced modulo $m$. The first and third Natural
s are taken by value and the second by
reference.
Some precomputed data is provided; this speeds up computations involving several modular
multiplications with the same modulus. The precomputed data should be obtained using
precompute_mod_mul_data
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModMulPrecomputed;
use malachite_nz::natural::Natural;
let data = ModMulPrecomputed::<Natural>::precompute_mod_mul_data(&Natural::from(10u32));
assert_eq!(
Natural::from(6u8).mod_mul_precomputed(
&Natural::from(7u32),
Natural::from(10u32),
&data
),
2
);
assert_eq!(
Natural::from(9u8).mod_mul_precomputed(
&Natural::from(9u32),
Natural::from(10u32),
&data
),
1
);
assert_eq!(
Natural::from(4u8).mod_mul_precomputed(
&Natural::from(7u32),
Natural::from(10u32),
&data
),
8
);
This is equivalent to _fmpz_mod_mulN
from fmpz_mod/mul.c
, FLINT 2.7.1, where b
and m
are taken by value and c
is taken by reference.
type Output = Natural
type Data = ModMulData
source§impl<'a, 'b, 'c> ModMulPrecomputed<&'b Natural, &'c Natural> for &'a Natural
impl<'a, 'b, 'c> ModMulPrecomputed<&'b Natural, &'c Natural> for &'a Natural
source§fn precompute_mod_mul_data(m: &&Natural) -> ModMulData
fn precompute_mod_mul_data(m: &&Natural) -> ModMulData
Precomputes data for modular multiplication. See mod_mul_precomputed
and
mod_mul_precomputed_assign
.
§Worst-case complexity
Constant time and additional memory.
This is equivalent to part of fmpz_mod_ctx_init
from fmpz_mod/ctx_init.c
, FLINT 2.7.1.
source§fn mod_mul_precomputed(
self,
other: &'b Natural,
m: &'c Natural,
data: &ModMulData
) -> Natural
fn mod_mul_precomputed( self, other: &'b Natural, m: &'c Natural, data: &ModMulData ) -> Natural
Multiplies two Natural
modulo a third Natural
$m$. The inputs must be already
reduced modulo $m$. All three Natural
s are taken by reference.
Some precomputed data is provided; this speeds up computations involving several modular
multiplications with the same modulus. The precomputed data should be obtained using
precompute_mod_mul_data
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModMulPrecomputed;
use malachite_nz::natural::Natural;
let data = ModMulPrecomputed::<Natural>::precompute_mod_mul_data(&Natural::from(10u32));
assert_eq!(
(&Natural::from(6u8)).mod_mul_precomputed(
&Natural::from(7u32),
&Natural::from(10u32),
&data
),
2
);
assert_eq!(
(&Natural::from(9u8)).mod_mul_precomputed(
&Natural::from(9u32),
&Natural::from(10u32),
&data
),
1
);
assert_eq!(
(&Natural::from(4u8)).mod_mul_precomputed(
&Natural::from(7u32),
&Natural::from(10u32),
&data
),
8
);
This is equivalent to _fmpz_mod_mulN
from fmpz_mod/mul.c, FLINT 2.7.1, where b
, c
, and
m
are taken by reference.
type Output = Natural
type Data = ModMulData
source§impl<'a, 'b> ModMulPrecomputed<&'a Natural, &'b Natural> for Natural
impl<'a, 'b> ModMulPrecomputed<&'a Natural, &'b Natural> for Natural
source§fn precompute_mod_mul_data(m: &&Natural) -> ModMulData
fn precompute_mod_mul_data(m: &&Natural) -> ModMulData
Precomputes data for modular multiplication. See mod_mul_precomputed
and
mod_mul_precomputed_assign
.
§Worst-case complexity
Constant time and additional memory.
This is equivalent to part of fmpz_mod_ctx_init
from fmpz_mod/ctx_init.c
, FLINT 2.7.1.
source§fn mod_mul_precomputed(
self,
other: &'a Natural,
m: &'b Natural,
data: &ModMulData
) -> Natural
fn mod_mul_precomputed( self, other: &'a Natural, m: &'b Natural, data: &ModMulData ) -> Natural
Multiplies two Natural
modulo a third Natural
$m$. The inputs must be already
reduced modulo $m$. The first Natural
is taken by value and the second and third by
reference.
Some precomputed data is provided; this speeds up computations involving several modular
multiplications with the same modulus. The precomputed data should be obtained using
precompute_mod_mul_data
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModMulPrecomputed;
use malachite_nz::natural::Natural;
let data = ModMulPrecomputed::<Natural>::precompute_mod_mul_data(&Natural::from(10u32));
assert_eq!(
Natural::from(6u8).mod_mul_precomputed(
&Natural::from(7u32),
&Natural::from(10u32),
&data
),
2
);
assert_eq!(
Natural::from(9u8).mod_mul_precomputed(
&Natural::from(9u32),
&Natural::from(10u32),
&data
),
1
);
assert_eq!(
Natural::from(4u8).mod_mul_precomputed(
&Natural::from(7u32),
&Natural::from(10u32),
&data
),
8
);
This is equivalent to _fmpz_mod_mulN
from fmpz_mod/mul.c
, FLINT 2.7.1, where b
is
taken by value and c
and m
are taken by reference.
type Output = Natural
type Data = ModMulData
source§impl<'a, 'b> ModMulPrecomputed<&'b Natural, Natural> for &'a Natural
impl<'a, 'b> ModMulPrecomputed<&'b Natural, Natural> for &'a Natural
source§fn precompute_mod_mul_data(m: &Natural) -> ModMulData
fn precompute_mod_mul_data(m: &Natural) -> ModMulData
Precomputes data for modular multiplication. See mod_mul_precomputed
and
mod_mul_precomputed_assign
.
§Worst-case complexity
Constant time and additional memory.
This is equivalent to part of fmpz_mod_ctx_init
from fmpz_mod/ctx_init.c
, FLINT 2.7.1.
source§fn mod_mul_precomputed(
self,
other: &'b Natural,
m: Natural,
data: &ModMulData
) -> Natural
fn mod_mul_precomputed( self, other: &'b Natural, m: Natural, data: &ModMulData ) -> Natural
Multiplies two Natural
modulo a third Natural
$m$. The inputs must be already
reduced modulo $m$. The first two Natural
s are taken by reference and the third by
value.
Some precomputed data is provided; this speeds up computations involving several modular
multiplications with the same modulus. The precomputed data should be obtained using
precompute_mod_mul_data
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModMulPrecomputed;
use malachite_nz::natural::Natural;
let data = ModMulPrecomputed::<Natural>::precompute_mod_mul_data(&Natural::from(10u32));
assert_eq!(
(&Natural::from(6u8)).mod_mul_precomputed(
&Natural::from(7u32),
Natural::from(10u32),
&data
),
2
);
assert_eq!(
(&Natural::from(9u8)).mod_mul_precomputed(
&Natural::from(9u32),
Natural::from(10u32),
&data
),
1
);
assert_eq!(
(&Natural::from(4u8)).mod_mul_precomputed(
&Natural::from(7u32),
Natural::from(10u32),
&data
),
8
);
This is equivalent to _fmpz_mod_mulN
from fmpz_mod/mul.c
, FLINT 2.7.1, where b
and c
are taken by reference and m
is taken by value.
type Output = Natural
type Data = ModMulData
source§impl<'a, 'b> ModMulPrecomputed<Natural, &'b Natural> for &'a Natural
impl<'a, 'b> ModMulPrecomputed<Natural, &'b Natural> for &'a Natural
source§fn precompute_mod_mul_data(m: &&Natural) -> ModMulData
fn precompute_mod_mul_data(m: &&Natural) -> ModMulData
Precomputes data for modular multiplication. See mod_mul_precomputed
and
mod_mul_precomputed_assign
.
§Worst-case complexity
Constant time and additional memory.
This is equivalent to part of fmpz_mod_ctx_init
from fmpz_mod/ctx_init.c
, FLINT 2.7.1.
source§fn mod_mul_precomputed(
self,
other: Natural,
m: &'b Natural,
data: &ModMulData
) -> Natural
fn mod_mul_precomputed( self, other: Natural, m: &'b Natural, data: &ModMulData ) -> Natural
Multiplies two Natural
modulo a third Natural
$m$. The inputs must be already
reduced modulo $m$. The first and third Natural
s are taken by reference and the second
by value.
Some precomputed data is provided; this speeds up computations involving several modular
multiplications with the same modulus. The precomputed data should be obtained using
precompute_mod_mul_data
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::ModMulPrecomputed;
use malachite_nz::natural::Natural;
let data = ModMulPrecomputed::<Natural>::precompute_mod_mul_data(&Natural::from(10u32));
assert_eq!(
(&Natural::from(6u8)).mod_mul_precomputed(
Natural::from(7u32),
&Natural::from(10u32),
&data
),
2
);
assert_eq!(
(&Natural::from(9u8)).mod_mul_precomputed(
Natural::from(9u32),
&Natural::from(10u32),
&data
),
1
);
assert_eq!(
(&Natural::from(4u8)).mod_mul_precomputed(
Natural::from(7u32),
&Natural::from(10u32),
&data
),
8
);
This is equivalent to _fmpz_mod_mulN
from fmpz_mod/mul.c
, FLINT 2.7.1, where b
and m
are taken by reference and c
is taken by value.
type Output = Natural
type Data = ModMulData
source§impl<'a> ModMulPrecomputed<Natural, &'a Natural> for Natural
impl<'a> ModMulPrecomputed<Natural, &'a Natural> for Natural
source§fn precompute_mod_mul_data(m: &&Natural) -> ModMulData
fn precompute_mod_mul_data(m: &&Natural) -> ModMulData
Precomputes data for modular multiplication. See mod_mul_precomputed
and
mod_mul_precomputed_assign
.
§Worst-case complexity
Constant time and additional memory.
This is equivalent to part of fmpz_mod_ctx_init
from fmpz_mod/ctx_init.c
, FLINT 2.7.1.
source§fn mod_mul_precomputed(
self,
other: Natural,
m: &'a Natural,
data: &ModMulData
) -> Natural
fn mod_mul_precomputed( self, other: Natural, m: &'a Natural, data: &ModMulData ) -> Natural
Multiplies two Natural
modulo a third Natural
$m$. The inputs must be already
reduced modulo $m$. The first two Natural
s are taken by value and the third by
reference.
Some precomputed data is provided; this speeds up computations involving several modular
multiplications with the same modulus. The precomputed data should be obtained using
precompute_mod_mul_data
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModMulPrecomputed;
use malachite_nz::natural::Natural;
let data = ModMulPrecomputed::<Natural>::precompute_mod_mul_data(&Natural::from(10u32));
assert_eq!(
Natural::from(6u8).mod_mul_precomputed(
Natural::from(7u32),
&Natural::from(10u32),
&data
),
2
);
assert_eq!(
Natural::from(9u8).mod_mul_precomputed(
Natural::from(9u32),
&Natural::from(10u32),
&data
),
1
);
assert_eq!(
Natural::from(4u8).mod_mul_precomputed(
Natural::from(7u32),
&Natural::from(10u32),
&data
),
8
);
This is equivalent to _fmpz_mod_mulN
from fmpz_mod/mul.c
, FLINT 2.7.1, where b
and c
are taken by value and m
is taken by reference.
type Output = Natural
type Data = ModMulData
source§impl<'a> ModMulPrecomputed<Natural, Natural> for &'a Natural
impl<'a> ModMulPrecomputed<Natural, Natural> for &'a Natural
source§fn precompute_mod_mul_data(m: &Natural) -> ModMulData
fn precompute_mod_mul_data(m: &Natural) -> ModMulData
Precomputes data for modular multiplication. See mod_mul_precomputed
and
mod_mul_precomputed_assign
.
§Worst-case complexity
Constant time and additional memory.
This is equivalent to part of fmpz_mod_ctx_init
from fmpz_mod/ctx_init.c
, FLINT 2.7.1.
source§fn mod_mul_precomputed(
self,
other: Natural,
m: Natural,
data: &ModMulData
) -> Natural
fn mod_mul_precomputed( self, other: Natural, m: Natural, data: &ModMulData ) -> Natural
Multiplies two Natural
modulo a third Natural
$m$. The inputs must be already
reduced modulo $m$. The first Natural
is taken by reference and the second and third by
value.
Some precomputed data is provided; this speeds up computations involving several modular
multiplications with the same modulus. The precomputed data should be obtained using
precompute_mod_mul_data
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModMulPrecomputed;
use malachite_nz::natural::Natural;
let data = ModMulPrecomputed::<Natural>::precompute_mod_mul_data(&Natural::from(10u32));
assert_eq!(
(&Natural::from(6u8)).mod_mul_precomputed(
Natural::from(7u32),
Natural::from(10u32),
&data
),
2
);
assert_eq!(
(&Natural::from(9u8)).mod_mul_precomputed(
Natural::from(9u32),
Natural::from(10u32),
&data
),
1
);
assert_eq!(
(&Natural::from(4u8)).mod_mul_precomputed(
Natural::from(7u32),
Natural::from(10u32),
&data
),
8
);
This is equivalent to _fmpz_mod_mulN
from fmpz_mod/mul.c
, FLINT 2.7.1, where b
is
taken by reference and c
and m
are taken by value.
type Output = Natural
type Data = ModMulData
source§impl ModMulPrecomputed for Natural
impl ModMulPrecomputed for Natural
source§fn precompute_mod_mul_data(m: &Natural) -> ModMulData
fn precompute_mod_mul_data(m: &Natural) -> ModMulData
Precomputes data for modular multiplication. See mod_mul_precomputed
and
mod_mul_precomputed_assign
.
§Worst-case complexity
Constant time and additional memory.
This is equivalent to part of fmpz_mod_ctx_init
from fmpz_mod/ctx_init.c
, FLINT 2.7.1.
source§fn mod_mul_precomputed(
self,
other: Natural,
m: Natural,
data: &ModMulData
) -> Natural
fn mod_mul_precomputed( self, other: Natural, m: Natural, data: &ModMulData ) -> Natural
Multiplies two Natural
modulo a third Natural
$m$. The inputs must be already
reduced modulo $m$. All three Natural
s are taken by value.
Some precomputed data is provided; this speeds up computations involving several modular
multiplications with the same modulus. The precomputed data should be obtained using
precompute_mod_mul_data
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModMulPrecomputed;
use malachite_nz::natural::Natural;
let data = ModMulPrecomputed::<Natural>::precompute_mod_mul_data(&Natural::from(10u32));
assert_eq!(
Natural::from(6u8).mod_mul_precomputed(
Natural::from(7u32),
Natural::from(10u32),
&data
),
2
);
assert_eq!(
Natural::from(9u8).mod_mul_precomputed(
Natural::from(9u32),
Natural::from(10u32),
&data
),
1
);
assert_eq!(
Natural::from(4u8).mod_mul_precomputed(
Natural::from(7u32),
Natural::from(10u32),
&data
),
8
);
This is equivalent to _fmpz_mod_mulN
from fmpz_mod/mul.c
, FLINT 2.7.1, where b
, c
,
and m
are taken by value.
type Output = Natural
type Data = ModMulData
source§impl<'a> ModMulPrecomputedAssign<&'a Natural> for Natural
impl<'a> ModMulPrecomputedAssign<&'a Natural> for Natural
source§fn mod_mul_precomputed_assign(
&mut self,
other: &'a Natural,
m: Natural,
data: &ModMulData
)
fn mod_mul_precomputed_assign( &mut self, other: &'a Natural, m: Natural, data: &ModMulData )
Multiplies two Natural
s modulo a third Natural
$m$, in place. The inputs must be
already reduced modulo $m$. The first Natural
on the right-hand side is taken by
reference and the second by value.
Some precomputed data is provided; this speeds up computations involving several modular
multiplications with the same modulus. The precomputed data should be obtained using
precompute_mod_mul_data
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::{ModMulPrecomputed, ModMulPrecomputedAssign};
use malachite_nz::natural::Natural;
let data = ModMulPrecomputed::<Natural>::precompute_mod_mul_data(&Natural::from(10u32));
let mut x = Natural::from(6u8);
x.mod_mul_precomputed_assign(&Natural::from(7u32), Natural::from(10u32), &data);
assert_eq!(x, 2);
let mut x = Natural::from(9u8);
x.mod_mul_precomputed_assign(&Natural::from(9u32), Natural::from(10u32), &data);
assert_eq!(x, 1);
let mut x = Natural::from(4u8);
x.mod_mul_precomputed_assign(&Natural::from(7u32), Natural::from(10u32), &data);
assert_eq!(x, 8);
This is equivalent to _fmpz_mod_mulN
from fmpz_mod/mul.c
, FLINT 2.7.1, where b
and m
are taken by value, c
is taken by reference, and a == b
.
source§impl<'a, 'b> ModMulPrecomputedAssign<&'a Natural, &'b Natural> for Natural
impl<'a, 'b> ModMulPrecomputedAssign<&'a Natural, &'b Natural> for Natural
source§fn mod_mul_precomputed_assign(
&mut self,
other: &'a Natural,
m: &'b Natural,
data: &ModMulData
)
fn mod_mul_precomputed_assign( &mut self, other: &'a Natural, m: &'b Natural, data: &ModMulData )
Multiplies two Natural
s modulo a third Natural
$m$, in place. The inputs must be
already reduced modulo $m$. Both Natural
s on the right-hand side are taken by reference.
Some precomputed data is provided; this speeds up computations involving several modular
multiplications with the same modulus. The precomputed data should be obtained using
precompute_mod_mul_data
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::{ModMulPrecomputed, ModMulPrecomputedAssign};
use malachite_nz::natural::Natural;
let data = ModMulPrecomputed::<Natural>::precompute_mod_mul_data(&Natural::from(10u32));
let mut x = Natural::from(6u8);
x.mod_mul_precomputed_assign(&Natural::from(7u32), &Natural::from(10u32), &data);
assert_eq!(x, 2);
let mut x = Natural::from(9u8);
x.mod_mul_precomputed_assign(&Natural::from(9u32), &Natural::from(10u32), &data);
assert_eq!(x, 1);
let mut x = Natural::from(4u8);
x.mod_mul_precomputed_assign(&Natural::from(7u32), &Natural::from(10u32), &data);
assert_eq!(x, 8);
This is equivalent to _fmpz_mod_mulN
from fmpz_mod/mul.c
, FLINT 2.7.1, where b
is
taken by value, c
and m
are taken by reference, and a == b
.
source§impl<'a> ModMulPrecomputedAssign<Natural, &'a Natural> for Natural
impl<'a> ModMulPrecomputedAssign<Natural, &'a Natural> for Natural
source§fn mod_mul_precomputed_assign(
&mut self,
other: Natural,
m: &'a Natural,
data: &ModMulData
)
fn mod_mul_precomputed_assign( &mut self, other: Natural, m: &'a Natural, data: &ModMulData )
Multiplies two Natural
s modulo a third Natural
$m$, in place. The inputs must be
already reduced modulo $m$. The first Natural
on the right-hand side is taken by value
and the second by reference.
Some precomputed data is provided; this speeds up computations involving several modular
multiplications with the same modulus. The precomputed data should be obtained using
precompute_mod_mul_data
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::{ModMulPrecomputed, ModMulPrecomputedAssign};
use malachite_nz::natural::Natural;
let data = ModMulPrecomputed::<Natural>::precompute_mod_mul_data(&Natural::from(10u32));
let mut x = Natural::from(6u8);
x.mod_mul_precomputed_assign(Natural::from(7u32), &Natural::from(10u32), &data);
assert_eq!(x, 2);
let mut x = Natural::from(9u8);
x.mod_mul_precomputed_assign(Natural::from(9u32), &Natural::from(10u32), &data);
assert_eq!(x, 1);
let mut x = Natural::from(4u8);
x.mod_mul_precomputed_assign(Natural::from(7u32), &Natural::from(10u32), &data);
assert_eq!(x, 8);
This is equivalent to _fmpz_mod_mulN
from fmpz_mod/mul.c
, FLINT 2.7.1, where b
and c
are taken by value, m
is taken by reference, and a == b
.
source§impl ModMulPrecomputedAssign for Natural
impl ModMulPrecomputedAssign for Natural
source§fn mod_mul_precomputed_assign(
&mut self,
other: Natural,
m: Natural,
data: &ModMulData
)
fn mod_mul_precomputed_assign( &mut self, other: Natural, m: Natural, data: &ModMulData )
Multiplies two Natural
s modulo a third Natural
$m$, in place. The inputs must be
already reduced modulo $m$. Both Natural
s on the right-hand side are taken by value.
Some precomputed data is provided; this speeds up computations involving several modular
multiplications with the same modulus. The precomputed data should be obtained using
precompute_mod_mul_data
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::{ModMulPrecomputed, ModMulPrecomputedAssign};
use malachite_nz::natural::Natural;
let data = ModMulPrecomputed::<Natural>::precompute_mod_mul_data(&Natural::from(10u32));
let mut x = Natural::from(6u8);
x.mod_mul_precomputed_assign(Natural::from(7u32), Natural::from(10u32), &data);
assert_eq!(x, 2);
let mut x = Natural::from(9u8);
x.mod_mul_precomputed_assign(Natural::from(9u32), Natural::from(10u32), &data);
assert_eq!(x, 1);
let mut x = Natural::from(4u8);
x.mod_mul_precomputed_assign(Natural::from(7u32), Natural::from(10u32), &data);
assert_eq!(x, 8);
This is equivalent to _fmpz_mod_mulN
from fmpz_mod/mul.c
, FLINT 2.7.1, where b
, c
,
and m
are taken by value and a == b
.
source§impl<'a, 'b> ModNeg<&'b Natural> for &'a Natural
impl<'a, 'b> ModNeg<&'b Natural> for &'a Natural
source§fn mod_neg(self, m: &'b Natural) -> Natural
fn mod_neg(self, m: &'b Natural) -> Natural
Negates a Natural
modulo another Natural
$m$. The input must be already reduced
modulo $m$. Both Natural
s are taken by reference.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::{ModNeg, Pow};
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::ZERO).mod_neg(&Natural::from(5u32)), 0);
assert_eq!((&Natural::from(7u32)).mod_neg(&Natural::from(10u32)), 3);
assert_eq!(
(&Natural::from(7u32)).mod_neg(&Natural::from(10u32).pow(12)),
999999999993u64
);
type Output = Natural
source§impl<'a> ModNeg<&'a Natural> for Natural
impl<'a> ModNeg<&'a Natural> for Natural
source§fn mod_neg(self, m: &'a Natural) -> Natural
fn mod_neg(self, m: &'a Natural) -> Natural
Negates a Natural
modulo another Natural
$m$. The input must be already reduced
modulo $m$. The first Natural
is taken by value and the second by reference.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::{ModNeg, Pow};
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!(Natural::ZERO.mod_neg(&Natural::from(5u32)), 0);
assert_eq!(Natural::from(7u32).mod_neg(&Natural::from(10u32)), 3);
assert_eq!(Natural::from(7u32).mod_neg(&Natural::from(10u32).pow(12)), 999999999993u64);
type Output = Natural
source§impl<'a> ModNeg<Natural> for &'a Natural
impl<'a> ModNeg<Natural> for &'a Natural
source§fn mod_neg(self, m: Natural) -> Natural
fn mod_neg(self, m: Natural) -> Natural
Negates a Natural
modulo another Natural
$m$. The input must be already reduced
modulo $m$. The first Natural
is taken by reference and the second by value.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::{ModNeg, Pow};
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::ZERO).mod_neg(Natural::from(5u32)), 0);
assert_eq!((&Natural::from(7u32)).mod_neg(Natural::from(10u32)), 3);
assert_eq!((&Natural::from(7u32)).mod_neg(Natural::from(10u32).pow(12)), 999999999993u64);
type Output = Natural
source§impl ModNeg for Natural
impl ModNeg for Natural
source§fn mod_neg(self, m: Natural) -> Natural
fn mod_neg(self, m: Natural) -> Natural
Negates a Natural
modulo another Natural
$m$. The input must be already reduced
modulo $m$. Both Natural
s are taken by value.
$f(x, m) = y$, where $x, y < m$ and $-x \equiv y \mod m$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::{ModNeg, Pow};
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!(Natural::ZERO.mod_neg(Natural::from(5u32)), 0);
assert_eq!(Natural::from(7u32).mod_neg(Natural::from(10u32)), 3);
assert_eq!(Natural::from(7u32).mod_neg(Natural::from(10u32).pow(12)), 999999999993u64);
type Output = Natural
source§impl<'a> ModNegAssign<&'a Natural> for Natural
impl<'a> ModNegAssign<&'a Natural> for Natural
source§fn mod_neg_assign(&mut self, m: &'a Natural)
fn mod_neg_assign(&mut self, m: &'a Natural)
Negates a Natural
modulo another Natural
$m$. The input must be already reduced
modulo $m$. The Natural
on the right-hand side is taken by reference.
$x \gets y$, where $x, y < m$ and $-x \equiv y \mod m$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::{ModNegAssign, Pow};
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
let mut n = Natural::ZERO;
n.mod_neg_assign(&Natural::from(5u32));
assert_eq!(n, 0);
let mut n = Natural::from(7u32);
n.mod_neg_assign(&Natural::from(10u32));
assert_eq!(n, 3);
let mut n = Natural::from(7u32);
n.mod_neg_assign(&Natural::from(10u32).pow(12));
assert_eq!(n, 999999999993u64);
source§impl ModNegAssign for Natural
impl ModNegAssign for Natural
source§fn mod_neg_assign(&mut self, m: Natural)
fn mod_neg_assign(&mut self, m: Natural)
Negates a Natural
modulo another Natural
$m$. The input must be already reduced
modulo $m$. The Natural
on the right-hand side is taken by value.
$x \gets y$, where $x, y < m$ and $-x \equiv y \mod m$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::{ModNegAssign, Pow};
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
let mut n = Natural::ZERO;
n.mod_neg_assign(Natural::from(5u32));
assert_eq!(n, 0);
let mut n = Natural::from(7u32);
n.mod_neg_assign(Natural::from(10u32));
assert_eq!(n, 3);
let mut n = Natural::from(7u32);
n.mod_neg_assign(Natural::from(10u32).pow(12));
assert_eq!(n, 999999999993u64);
source§impl<'a> ModPow<&'a Natural> for Natural
impl<'a> ModPow<&'a Natural> for Natural
source§fn mod_pow(self, exp: &'a Natural, m: Natural) -> Natural
fn mod_pow(self, exp: &'a Natural, m: Natural) -> Natural
Raises a Natural
to a Natural
power modulo a third Natural
$m$. The base must be
already reduced modulo $m$. The first and third Natural
s are taken by value and the
second by reference.
$f(x, n, m) = y$, where $x, y < m$ and $x^n \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$ is
exp.significant_bits()
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModPow;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(4u32).mod_pow(&Natural::from(13u32), Natural::from(497u32)), 445);
assert_eq!(Natural::from(10u32).mod_pow(&Natural::from(1000u32), Natural::from(30u32)), 10);
type Output = Natural
source§impl<'a, 'b, 'c> ModPow<&'b Natural, &'c Natural> for &'a Natural
impl<'a, 'b, 'c> ModPow<&'b Natural, &'c Natural> for &'a Natural
source§fn mod_pow(self, exp: &'b Natural, m: &'c Natural) -> Natural
fn mod_pow(self, exp: &'b Natural, m: &'c Natural) -> Natural
Raises a Natural
to a Natural
power modulo a third Natural
$m$. The base must be
already reduced modulo $m$. All three Natural
s are taken by reference.
$f(x, n, m) = y$, where $x, y < m$ and $x^n \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$ is
exp.significant_bits()
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModPow;
use malachite_nz::natural::Natural;
assert_eq!(
(&Natural::from(4u32)).mod_pow(&Natural::from(13u32), &Natural::from(497u32)),
445
);
assert_eq!(
(&Natural::from(10u32)).mod_pow(&Natural::from(1000u32), &Natural::from(30u32)),
10
);
type Output = Natural
source§impl<'a, 'b> ModPow<&'a Natural, &'b Natural> for Natural
impl<'a, 'b> ModPow<&'a Natural, &'b Natural> for Natural
source§fn mod_pow(self, exp: &'a Natural, m: &'b Natural) -> Natural
fn mod_pow(self, exp: &'a Natural, m: &'b Natural) -> Natural
Raises a Natural
to a Natural
power modulo a third Natural
$m$. The base must be
already reduced modulo $m$. The first Natural
is taken by value and the second and third
by reference.
$f(x, n, m) = y$, where $x, y < m$ and $x^n \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$ is
exp.significant_bits()
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModPow;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(4u32).mod_pow(&Natural::from(13u32), &Natural::from(497u32)), 445);
assert_eq!(
Natural::from(10u32).mod_pow(&Natural::from(1000u32), &Natural::from(30u32)),
10
);
type Output = Natural
source§impl<'a, 'b> ModPow<&'b Natural, Natural> for &'a Natural
impl<'a, 'b> ModPow<&'b Natural, Natural> for &'a Natural
source§fn mod_pow(self, exp: &'b Natural, m: Natural) -> Natural
fn mod_pow(self, exp: &'b Natural, m: Natural) -> Natural
Raises a Natural
to a Natural
power modulo a third Natural
$m$. The base must be
already reduced modulo $m$. The first two Natural
s are taken by reference and the third
by value.
$f(x, n, m) = y$, where $x, y < m$ and $x^n \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$ is
exp.significant_bits()
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModPow;
use malachite_nz::natural::Natural;
assert_eq!(
(&Natural::from(4u32)).mod_pow(&Natural::from(13u32), Natural::from(497u32)),
445
);
assert_eq!(
(&Natural::from(10u32)).mod_pow(&Natural::from(1000u32), Natural::from(30u32)),
10
);
type Output = Natural
source§impl<'a, 'b> ModPow<Natural, &'b Natural> for &'a Natural
impl<'a, 'b> ModPow<Natural, &'b Natural> for &'a Natural
source§fn mod_pow(self, exp: Natural, m: &'b Natural) -> Natural
fn mod_pow(self, exp: Natural, m: &'b Natural) -> Natural
Raises a Natural
to a Natural
power modulo a third Natural
$m$. The base must be
already reduced modulo $m$. The first and third Natural
s are taken by reference and the
second by value.
$f(x, n, m) = y$, where $x, y < m$ and $x^n \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$ is
exp.significant_bits()
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModPow;
use malachite_nz::natural::Natural;
assert_eq!(
(&Natural::from(4u32)).mod_pow(Natural::from(13u32), &Natural::from(497u32)),
445
);
assert_eq!(
(&Natural::from(10u32)).mod_pow(Natural::from(1000u32), &Natural::from(30u32)),
10
);
type Output = Natural
source§impl<'a> ModPow<Natural, &'a Natural> for Natural
impl<'a> ModPow<Natural, &'a Natural> for Natural
source§fn mod_pow(self, exp: Natural, m: &'a Natural) -> Natural
fn mod_pow(self, exp: Natural, m: &'a Natural) -> Natural
Raises a Natural
to a Natural
power modulo a third Natural
$m$. The base must be
already reduced modulo $m$. The first two Natural
s are taken by value and the third by
reference.
$f(x, n, m) = y$, where $x, y < m$ and $x^n \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$ is
exp.significant_bits()
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModPow;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(4u32).mod_pow(Natural::from(13u32), &Natural::from(497u32)), 445);
assert_eq!(Natural::from(10u32).mod_pow(Natural::from(1000u32), &Natural::from(30u32)), 10);
type Output = Natural
source§impl<'a> ModPow<Natural, Natural> for &'a Natural
impl<'a> ModPow<Natural, Natural> for &'a Natural
source§fn mod_pow(self, exp: Natural, m: Natural) -> Natural
fn mod_pow(self, exp: Natural, m: Natural) -> Natural
Raises a Natural
to a Natural
power modulo a third Natural
$m$. The base must be
already reduced modulo $m$. The first Natural
is taken by reference and the second and
third by value.
$f(x, n, m) = y$, where $x, y < m$ and $x^n \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$ is
exp.significant_bits()
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModPow;
use malachite_nz::natural::Natural;
assert_eq!(
(&Natural::from(4u32)).mod_pow(Natural::from(13u32), Natural::from(497u32)),
445
);
assert_eq!(
(&Natural::from(10u32)).mod_pow(Natural::from(1000u32), Natural::from(30u32)),
10
);
type Output = Natural
source§impl ModPow for Natural
impl ModPow for Natural
source§fn mod_pow(self, exp: Natural, m: Natural) -> Natural
fn mod_pow(self, exp: Natural, m: Natural) -> Natural
Raises a Natural
to a Natural
power modulo a third Natural
$m$. The base must be
already reduced modulo $m$. All three Natural
s are taken by value.
$f(x, n, m) = y$, where $x, y < m$ and $x^n \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$ is
exp.significant_bits()
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModPow;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(4u32).mod_pow(Natural::from(13u32), Natural::from(497u32)), 445);
assert_eq!(Natural::from(10u32).mod_pow(Natural::from(1000u32), Natural::from(30u32)), 10);
type Output = Natural
source§impl<'a> ModPowAssign<&'a Natural> for Natural
impl<'a> ModPowAssign<&'a Natural> for Natural
source§fn mod_pow_assign(&mut self, exp: &'a Natural, m: Natural)
fn mod_pow_assign(&mut self, exp: &'a Natural, m: Natural)
Raises a Natural
to a Natural
power modulo a third Natural
$m$, in place. The
base must be already reduced modulo $m$. The first Natural
on the right-hand side is
taken by reference and the second by value.
$x \gets y$, where $x, y < m$ and $x^n \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$ is
exp.significant_bits()
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModPowAssign;
use malachite_nz::natural::Natural;
let mut x = Natural::from(4u32);
x.mod_pow_assign(&Natural::from(13u32), Natural::from(497u32));
assert_eq!(x, 445);
let mut x = Natural::from(10u32);
x.mod_pow_assign(&Natural::from(1000u32), Natural::from(30u32));
assert_eq!(x, 10);
source§impl<'a, 'b> ModPowAssign<&'a Natural, &'b Natural> for Natural
impl<'a, 'b> ModPowAssign<&'a Natural, &'b Natural> for Natural
source§fn mod_pow_assign(&mut self, exp: &'a Natural, m: &'b Natural)
fn mod_pow_assign(&mut self, exp: &'a Natural, m: &'b Natural)
Raises a Natural
to a Natural
power modulo a third Natural
$m$, in place. The
base must be already reduced modulo $m$. Both Natural
s on the right-hand side are taken
by reference.
$x \gets y$, where $x, y < m$ and $x^n \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$ is
exp.significant_bits()
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModPowAssign;
use malachite_nz::natural::Natural;
let mut x = Natural::from(4u32);
x.mod_pow_assign(&Natural::from(13u32), &Natural::from(497u32));
assert_eq!(x, 445);
let mut x = Natural::from(10u32);
x.mod_pow_assign(&Natural::from(1000u32), &Natural::from(30u32));
assert_eq!(x, 10);
source§impl<'a> ModPowAssign<Natural, &'a Natural> for Natural
impl<'a> ModPowAssign<Natural, &'a Natural> for Natural
source§fn mod_pow_assign(&mut self, exp: Natural, m: &'a Natural)
fn mod_pow_assign(&mut self, exp: Natural, m: &'a Natural)
Raises a Natural
to a Natural
power modulo a third Natural
$m$, in place. The
base must be already reduced modulo $m$. The first Natural
on the right-hand side is
taken by value and the second by reference.
$x \gets y$, where $x, y < m$ and $x^n \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$ is
exp.significant_bits()
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModPowAssign;
use malachite_nz::natural::Natural;
let mut x = Natural::from(4u32);
x.mod_pow_assign(Natural::from(13u32), &Natural::from(497u32));
assert_eq!(x, 445);
let mut x = Natural::from(10u32);
x.mod_pow_assign(Natural::from(1000u32), &Natural::from(30u32));
assert_eq!(x, 10);
source§impl ModPowAssign for Natural
impl ModPowAssign for Natural
source§fn mod_pow_assign(&mut self, exp: Natural, m: Natural)
fn mod_pow_assign(&mut self, exp: Natural, m: Natural)
Raises a Natural
to a Natural
power modulo a third Natural
$m$, in place. The
base must be already reduced modulo $m$. Both Natural
s on the right-hand side are taken
by value.
$x \gets y$, where $x, y < m$ and $x^n \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$ is
exp.significant_bits()
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModPowAssign;
use malachite_nz::natural::Natural;
let mut x = Natural::from(4u32);
x.mod_pow_assign(Natural::from(13u32), Natural::from(497u32));
assert_eq!(x, 445);
let mut x = Natural::from(10u32);
x.mod_pow_assign(Natural::from(1000u32), Natural::from(30u32));
assert_eq!(x, 10);
source§impl<'a> ModPowerOf2 for &'a Natural
impl<'a> ModPowerOf2 for &'a Natural
source§fn mod_power_of_2(self, pow: u64) -> Natural
fn mod_power_of_2(self, pow: u64) -> Natural
Divides a Natural
by $2^k$, returning just the remainder. The Natural
is taken by
reference.
If the quotient were computed, the quotient and remainder would satisfy $x = q2^k + r$ and $0 \leq r < 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Examples
use malachite_base::num::arithmetic::traits::ModPowerOf2;
use malachite_nz::natural::Natural;
// 1 * 2^8 + 4 = 260
assert_eq!((&Natural::from(260u32)).mod_power_of_2(8), 4);
// 100 * 2^4 + 11 = 1611
assert_eq!((&Natural::from(1611u32)).mod_power_of_2(4), 11);
type Output = Natural
source§impl ModPowerOf2 for Natural
impl ModPowerOf2 for Natural
source§fn mod_power_of_2(self, pow: u64) -> Natural
fn mod_power_of_2(self, pow: u64) -> Natural
Divides a Natural
by $2^k$, returning just the remainder. The Natural
is taken by
value.
If the quotient were computed, the quotient and remainder would satisfy $x = q2^k + r$ and $0 \leq r < 2^k$.
$$ f(x, k) = x - 2^k\left \lfloor \frac{x}{2^k} \right \rfloor. $$
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::arithmetic::traits::ModPowerOf2;
use malachite_nz::natural::Natural;
// 1 * 2^8 + 4 = 260
assert_eq!(Natural::from(260u32).mod_power_of_2(8), 4);
// 100 * 2^4 + 11 = 1611
assert_eq!(Natural::from(1611u32).mod_power_of_2(4), 11);
type Output = Natural
source§impl<'a, 'b> ModPowerOf2Add<&'a Natural> for &'b Natural
impl<'a, 'b> ModPowerOf2Add<&'a Natural> for &'b Natural
source§fn mod_power_of_2_add(self, other: &'a Natural, pow: u64) -> Natural
fn mod_power_of_2_add(self, other: &'a Natural, pow: u64) -> Natural
Adds two Natural
s modulo $2^k$. The inputs must be already reduced modulo $2^k$. Both
Natural
s are taken by reference.
$f(x, y, k) = z$, where $x, y, z < 2^k$ and $x + y \equiv z \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Panics
Panics if self
or other
are greater than or equal to $2^k$.
§Examples
use malachite_base::num::arithmetic::traits::ModPowerOf2Add;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::ZERO).mod_power_of_2_add(&Natural::from(2u32), 5), 2);
assert_eq!((&Natural::from(10u32)).mod_power_of_2_add(&Natural::from(14u32), 4), 8);
type Output = Natural
source§impl<'a> ModPowerOf2Add<&'a Natural> for Natural
impl<'a> ModPowerOf2Add<&'a Natural> for Natural
source§fn mod_power_of_2_add(self, other: &'a Natural, pow: u64) -> Natural
fn mod_power_of_2_add(self, other: &'a Natural, pow: u64) -> Natural
Adds two Natural
s modulo $2^k$. The inputs must be already reduced modulo $2^k$. The
first Natural
is taken by value and the second by reference.
$f(x, y, k) = z$, where $x, y, z < 2^k$ and $x + y \equiv z \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to $2^k$.
§Examples
use malachite_base::num::arithmetic::traits::ModPowerOf2Add;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!(Natural::ZERO.mod_power_of_2_add(&Natural::from(2u32), 5), 2);
assert_eq!(Natural::from(10u32).mod_power_of_2_add(&Natural::from(14u32), 4), 8);
type Output = Natural
source§impl<'a> ModPowerOf2Add<Natural> for &'a Natural
impl<'a> ModPowerOf2Add<Natural> for &'a Natural
source§fn mod_power_of_2_add(self, other: Natural, pow: u64) -> Natural
fn mod_power_of_2_add(self, other: Natural, pow: u64) -> Natural
Adds two Natural
s modulo $2^k$. The inputs must be already reduced modulo $2^k$. The
first Natural
is taken by reference and the second by value.
$f(x, y, k) = z$, where $x, y, z < 2^k$ and $x + y \equiv z \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to $2^k$.
§Examples
use malachite_base::num::arithmetic::traits::ModPowerOf2Add;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::ZERO).mod_power_of_2_add(Natural::from(2u32), 5), 2);
assert_eq!((&Natural::from(10u32)).mod_power_of_2_add(Natural::from(14u32), 4), 8);
type Output = Natural
source§impl ModPowerOf2Add for Natural
impl ModPowerOf2Add for Natural
source§fn mod_power_of_2_add(self, other: Natural, pow: u64) -> Natural
fn mod_power_of_2_add(self, other: Natural, pow: u64) -> Natural
Adds two Natural
s modulo $2^k$. The inputs must be already reduced modulo $2^k$. Both
Natural
s are taken by value.
$f(x, y, k) = z$, where $x, y, z < 2^k$ and $x + y \equiv z \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits())
.
§Panics
Panics if self
or other
are greater than or equal to $2^k$.
§Examples
use malachite_base::num::arithmetic::traits::ModPowerOf2Add;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!(Natural::ZERO.mod_power_of_2_add(Natural::from(2u32), 5), 2);
assert_eq!(Natural::from(10u32).mod_power_of_2_add(Natural::from(14u32), 4), 8);
type Output = Natural
source§impl<'a> ModPowerOf2AddAssign<&'a Natural> for Natural
impl<'a> ModPowerOf2AddAssign<&'a Natural> for Natural
source§fn mod_power_of_2_add_assign(&mut self, other: &'a Natural, pow: u64)
fn mod_power_of_2_add_assign(&mut self, other: &'a Natural, pow: u64)
Adds two Natural
s modulo $2^k$, in place. The inputs must be already reduced modulo
$2^k$. The Natural
on the right-hand side is taken by reference.
$x \gets z$, where $x, y, z < 2^k$ and $x + y \equiv z \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is other.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to $2^k$.
§Examples
use malachite_base::num::arithmetic::traits::ModPowerOf2AddAssign;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
let mut x = Natural::ZERO;
x.mod_power_of_2_add_assign(&Natural::from(2u32), 5);
assert_eq!(x, 2);
let mut x = Natural::from(10u32);
x.mod_power_of_2_add_assign(&Natural::from(14u32), 4);
assert_eq!(x, 8);
source§impl ModPowerOf2AddAssign for Natural
impl ModPowerOf2AddAssign for Natural
source§fn mod_power_of_2_add_assign(&mut self, other: Natural, pow: u64)
fn mod_power_of_2_add_assign(&mut self, other: Natural, pow: u64)
Adds two Natural
s modulo $2^k$, in place. The inputs must be already reduced modulo
$2^k$. The Natural
on the right-hand side is taken by value.
$x \gets z$, where $x, y, z < 2^k$ and $x + y \equiv z \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits())
.
§Panics
Panics if self
or other
are greater than or equal to $2^k$.
§Examples
use malachite_base::num::arithmetic::traits::ModPowerOf2AddAssign;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
let mut x = Natural::ZERO;
x.mod_power_of_2_add_assign(Natural::from(2u32), 5);
assert_eq!(x, 2);
let mut x = Natural::from(10u32);
x.mod_power_of_2_add_assign(Natural::from(14u32), 4);
assert_eq!(x, 8);
source§impl ModPowerOf2Assign for Natural
impl ModPowerOf2Assign for Natural
source§fn mod_power_of_2_assign(&mut self, pow: u64)
fn mod_power_of_2_assign(&mut self, pow: u64)
Divides a Natural
by $2^k$, replacing the Natural
by the remainder.
If the quotient were computed, the quotient and remainder would satisfy $x = q2^k + r$ and $0 \leq r < 2^k$.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::arithmetic::traits::ModPowerOf2Assign;
use malachite_nz::natural::Natural;
// 1 * 2^8 + 4 = 260
let mut x = Natural::from(260u32);
x.mod_power_of_2_assign(8);
assert_eq!(x, 4);
// 100 * 2^4 + 11 = 1611
let mut x = Natural::from(1611u32);
x.mod_power_of_2_assign(4);
assert_eq!(x, 11);
source§impl<'a> ModPowerOf2Inverse for &'a Natural
impl<'a> ModPowerOf2Inverse for &'a Natural
source§fn mod_power_of_2_inverse(self, pow: u64) -> Option<Natural>
fn mod_power_of_2_inverse(self, pow: u64) -> Option<Natural>
Computes the multiplicative inverse of a Natural
modulo $2^k$. The input must be already
reduced modulo $2^k$. The Natural
is taken by reference.
Returns None
if $x$ is even.
$f(x, k) = y$, where $x, y < 2^k$, $x$ is odd, and $xy \equiv 1 \mod 2^k$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is 0 or if self
is greater than or equal to $2^k$.
§Examples
use malachite_base::num::arithmetic::traits::ModPowerOf2Inverse;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::from(3u32)).mod_power_of_2_inverse(8), Some(Natural::from(171u32)));
assert_eq!((&Natural::from(4u32)).mod_power_of_2_inverse(8), None);
type Output = Natural
source§impl ModPowerOf2Inverse for Natural
impl ModPowerOf2Inverse for Natural
source§fn mod_power_of_2_inverse(self, pow: u64) -> Option<Natural>
fn mod_power_of_2_inverse(self, pow: u64) -> Option<Natural>
Computes the multiplicative inverse of a Natural
modulo $2^k$. The input must be already
reduced modulo $2^k$. The Natural
is taken by value.
Returns None
if $x$ is even.
$f(x, k) = y$, where $x, y < 2^k$, $x$ is odd, and $xy \equiv 1 \mod 2^k$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is 0 or if self
is greater than or equal to $2^k$.
§Examples
use malachite_base::num::arithmetic::traits::ModPowerOf2Inverse;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(3u32).mod_power_of_2_inverse(8), Some(Natural::from(171u32)));
assert_eq!(Natural::from(4u32).mod_power_of_2_inverse(8), None);
type Output = Natural
source§impl ModPowerOf2IsReduced for Natural
impl ModPowerOf2IsReduced for Natural
source§fn mod_power_of_2_is_reduced(&self, pow: u64) -> bool
fn mod_power_of_2_is_reduced(&self, pow: u64) -> bool
Returns whether a Natural
is reduced modulo 2^k$; in other words, whether it has no more
than $k$ significant bits.
$f(x, k) = (x < 2^k)$.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::arithmetic::traits::{ModPowerOf2IsReduced, Pow};
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!(Natural::ZERO.mod_power_of_2_is_reduced(5), true);
assert_eq!(Natural::from(10u32).pow(12).mod_power_of_2_is_reduced(39), false);
assert_eq!(Natural::from(10u32).pow(12).mod_power_of_2_is_reduced(40), true);
source§impl<'a, 'b> ModPowerOf2Mul<&'b Natural> for &'a Natural
impl<'a, 'b> ModPowerOf2Mul<&'b Natural> for &'a Natural
source§fn mod_power_of_2_mul(self, other: &'b Natural, pow: u64) -> Natural
fn mod_power_of_2_mul(self, other: &'b Natural, pow: u64) -> Natural
Multiplies two Natural
s modulo $2^k$. The inputs must be already reduced modulo $2^k$.
Both Natural
s are taken by reference.
$f(x, y, k) = z$, where $x, y, z < 2^k$ and $xy \equiv z \mod 2^k$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
or other
are greater than or equal to $2^k$.
§Examples
use malachite_base::num::arithmetic::traits::ModPowerOf2Mul;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::from(3u32)).mod_power_of_2_mul(&Natural::from(2u32), 5), 6);
assert_eq!((&Natural::from(10u32)).mod_power_of_2_mul(&Natural::from(14u32), 4), 12);
type Output = Natural
source§impl<'a> ModPowerOf2Mul<&'a Natural> for Natural
impl<'a> ModPowerOf2Mul<&'a Natural> for Natural
source§fn mod_power_of_2_mul(self, other: &'a Natural, pow: u64) -> Natural
fn mod_power_of_2_mul(self, other: &'a Natural, pow: u64) -> Natural
Multiplies two Natural
s modulo $2^k$. The inputs must be already reduced modulo $2^k$.
The first Natural
is taken by value and the second by reference.
$f(x, y, k) = z$, where $x, y, z < 2^k$ and $xy \equiv z \mod 2^k$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
or other
are greater than or equal to $2^k$.
§Examples
use malachite_base::num::arithmetic::traits::ModPowerOf2Mul;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(3u32).mod_power_of_2_mul(&Natural::from(2u32), 5), 6);
assert_eq!(Natural::from(10u32).mod_power_of_2_mul(&Natural::from(14u32), 4), 12);
type Output = Natural
source§impl<'a> ModPowerOf2Mul<Natural> for &'a Natural
impl<'a> ModPowerOf2Mul<Natural> for &'a Natural
source§fn mod_power_of_2_mul(self, other: Natural, pow: u64) -> Natural
fn mod_power_of_2_mul(self, other: Natural, pow: u64) -> Natural
Multiplies two Natural
s modulo $2^k$. The inputs must be already reduced modulo $2^k$.
The first Natural
is taken by reference and the second by value.
$f(x, y, k) = z$, where $x, y, z < 2^k$ and $xy \equiv z \mod 2^k$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
or other
are greater than or equal to $2^k$.
§Examples
use malachite_base::num::arithmetic::traits::ModPowerOf2Mul;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::from(3u32)).mod_power_of_2_mul(Natural::from(2u32), 5), 6);
assert_eq!((&Natural::from(10u32)).mod_power_of_2_mul(Natural::from(14u32), 4), 12);
type Output = Natural
source§impl ModPowerOf2Mul for Natural
impl ModPowerOf2Mul for Natural
source§fn mod_power_of_2_mul(self, other: Natural, pow: u64) -> Natural
fn mod_power_of_2_mul(self, other: Natural, pow: u64) -> Natural
Multiplies two Natural
s modulo $2^k$. The inputs must be already reduced modulo $2^k$.
Both Natural
s are taken by value.
$f(x, y, k) = z$, where $x, y, z < 2^k$ and $xy \equiv z \mod 2^k$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
or other
are greater than or equal to $2^k$.
§Examples
use malachite_base::num::arithmetic::traits::ModPowerOf2Mul;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(3u32).mod_power_of_2_mul(Natural::from(2u32), 5), 6);
assert_eq!(Natural::from(10u32).mod_power_of_2_mul(Natural::from(14u32), 4), 12);
type Output = Natural
source§impl<'a> ModPowerOf2MulAssign<&'a Natural> for Natural
impl<'a> ModPowerOf2MulAssign<&'a Natural> for Natural
source§fn mod_power_of_2_mul_assign(&mut self, other: &'a Natural, pow: u64)
fn mod_power_of_2_mul_assign(&mut self, other: &'a Natural, pow: u64)
Multiplies two Natural
s modulo $2^k$, in place. The inputs must be already reduced
modulo $2^k$. The Natural
on the right-hand side is taken by reference.
$x \gets z$, where $x, y, z < 2^k$ and $x + y \equiv z \mod 2^k$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
or other
are greater than or equal to $2^k$.
§Examples
use malachite_base::num::arithmetic::traits::ModPowerOf2MulAssign;
use malachite_nz::natural::Natural;
let mut x = Natural::from(3u32);
x.mod_power_of_2_mul_assign(&Natural::from(2u32), 5);
assert_eq!(x, 6);
let mut x = Natural::from(10u32);
x.mod_power_of_2_mul_assign(&Natural::from(14u32), 4);
assert_eq!(x, 12);
source§impl ModPowerOf2MulAssign for Natural
impl ModPowerOf2MulAssign for Natural
source§fn mod_power_of_2_mul_assign(&mut self, other: Natural, pow: u64)
fn mod_power_of_2_mul_assign(&mut self, other: Natural, pow: u64)
Multiplies two Natural
s modulo $2^k$, in place. The inputs must be already reduced
modulo $2^k$. The Natural
on the right-hand side is taken by value.
$x \gets z$, where $x, y, z < 2^k$ and $x + y \equiv z \mod 2^k$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
or other
are greater than or equal to $2^k$.
§Examples
use malachite_base::num::arithmetic::traits::ModPowerOf2MulAssign;
use malachite_nz::natural::Natural;
let mut x = Natural::from(3u32);
x.mod_power_of_2_mul_assign(Natural::from(2u32), 5);
assert_eq!(x, 6);
let mut x = Natural::from(10u32);
x.mod_power_of_2_mul_assign(Natural::from(14u32), 4);
assert_eq!(x, 12);
source§impl<'a> ModPowerOf2Neg for &'a Natural
impl<'a> ModPowerOf2Neg for &'a Natural
source§fn mod_power_of_2_neg(self, pow: u64) -> Natural
fn mod_power_of_2_neg(self, pow: u64) -> Natural
Negates a Natural
modulo $2^k$. The input must be already reduced modulo $2^k$. The
Natural
is taken by reference.
$f(x, k) = y$, where $x, y < 2^k$ and $-x \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
use malachite_base::num::arithmetic::traits::ModPowerOf2Neg;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::ZERO).mod_power_of_2_neg(5), 0);
assert_eq!((&Natural::ZERO).mod_power_of_2_neg(100), 0);
assert_eq!((&Natural::from(100u32)).mod_power_of_2_neg(8), 156);
assert_eq!(
(&Natural::from(100u32)).mod_power_of_2_neg(100).to_string(),
"1267650600228229401496703205276"
);
type Output = Natural
source§impl ModPowerOf2Neg for Natural
impl ModPowerOf2Neg for Natural
source§fn mod_power_of_2_neg(self, pow: u64) -> Natural
fn mod_power_of_2_neg(self, pow: u64) -> Natural
Negates a Natural
modulo $2^k$. The input must be already reduced modulo $2^k$. The
Natural
is taken by value.
$f(x, k) = y$, where $x, y < 2^k$ and $-x \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
use malachite_base::num::arithmetic::traits::ModPowerOf2Neg;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!(Natural::ZERO.mod_power_of_2_neg(5), 0);
assert_eq!(Natural::ZERO.mod_power_of_2_neg(100), 0);
assert_eq!(Natural::from(100u32).mod_power_of_2_neg(8), 156);
assert_eq!(
Natural::from(100u32).mod_power_of_2_neg(100).to_string(),
"1267650600228229401496703205276"
);
type Output = Natural
source§impl ModPowerOf2NegAssign for Natural
impl ModPowerOf2NegAssign for Natural
source§fn mod_power_of_2_neg_assign(&mut self, pow: u64)
fn mod_power_of_2_neg_assign(&mut self, pow: u64)
Negates a Natural
modulo $2^k$, in place. The input must be already reduced modulo
$2^k$.
$x \gets y$, where $x, y < 2^p$ and $-x \equiv y \mod 2^p$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
use malachite_base::num::arithmetic::traits::ModPowerOf2NegAssign;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
let mut n = Natural::ZERO;
n.mod_power_of_2_neg_assign(5);
assert_eq!(n, 0);
let mut n = Natural::ZERO;
n.mod_power_of_2_neg_assign(100);
assert_eq!(n, 0);
let mut n = Natural::from(100u32);
n.mod_power_of_2_neg_assign(8);
assert_eq!(n, 156);
let mut n = Natural::from(100u32);
n.mod_power_of_2_neg_assign(100);
assert_eq!(n.to_string(), "1267650600228229401496703205276");
source§impl<'a, 'b> ModPowerOf2Pow<&'b Natural> for &'a Natural
impl<'a, 'b> ModPowerOf2Pow<&'b Natural> for &'a Natural
source§fn mod_power_of_2_pow(self, exp: &Natural, pow: u64) -> Natural
fn mod_power_of_2_pow(self, exp: &Natural, pow: u64) -> Natural
Raises a Natural
to a Natural
power modulo $2^k$. The base must be already reduced
modulo $2^k$. Both Natural
s are taken by reference.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is pow
, and $m$ is
exp.significant_bits()
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
use malachite_base::num::arithmetic::traits::ModPowerOf2Pow;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::from(3u32)).mod_power_of_2_pow(&Natural::from(10u32), 8), 169);
assert_eq!(
(&Natural::from(11u32)).mod_power_of_2_pow(&Natural::from(1000u32), 30),
289109473
);
type Output = Natural
source§impl<'a> ModPowerOf2Pow<&'a Natural> for Natural
impl<'a> ModPowerOf2Pow<&'a Natural> for Natural
source§fn mod_power_of_2_pow(self, exp: &Natural, pow: u64) -> Natural
fn mod_power_of_2_pow(self, exp: &Natural, pow: u64) -> Natural
Raises a Natural
to a Natural
power modulo $2^k$. The base must be already reduced
modulo $2^k$. The first Natural
is taken by value and the second by reference.
$f(x, n, k) = y$, where $x, y < 2^k$ and $x^n \equiv y \mod 2^k$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is pow
, and $m$ is
exp.significant_bits()
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
use malachite_base::num::arithmetic::traits::ModPowerOf2Pow;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(3u32).mod_power_of_2_pow(&Natural::from(10u32), 8), 169);
assert_eq!(
Natural::from(11u32).mod_power_of_2_pow(&Natural::from(1000u32), 30),
289109473
);
type Output = Natural
source§impl<'a> ModPowerOf2Pow<Natural> for &'a Natural
impl<'a> ModPowerOf2Pow<Natural> for &'a Natural
source§fn mod_power_of_2_pow(self, exp: Natural, pow: u64) -> Natural
fn mod_power_of_2_pow(self, exp: Natural, pow: u64) -> Natural
Raises a Natural
to a Natural
power modulo $2^k$. The base must be already reduced
modulo $2^k$. The first Natural
is taken by reference and the second by value.
$f(x, n, k) = y$, where $x, y < 2^k$ and $x^n \equiv y \mod 2^k$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is pow
, and $m$ is
exp.significant_bits()
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
use malachite_base::num::arithmetic::traits::ModPowerOf2Pow;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::from(3u32)).mod_power_of_2_pow(Natural::from(10u32), 8), 169);
assert_eq!(
(&Natural::from(11u32)).mod_power_of_2_pow(Natural::from(1000u32), 30),
289109473
);
type Output = Natural
source§impl ModPowerOf2Pow for Natural
impl ModPowerOf2Pow for Natural
source§fn mod_power_of_2_pow(self, exp: Natural, pow: u64) -> Natural
fn mod_power_of_2_pow(self, exp: Natural, pow: u64) -> Natural
Raises a Natural
to a Natural
power modulo $2^k$. The base must be already reduced
modulo $2^k$. Both Natural
s are taken by value.
$f(x, n, k) = y$, where $x, y < 2^k$ and $x^n \equiv y \mod 2^k$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is pow
, and $m$ is
exp.significant_bits()
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
use malachite_base::num::arithmetic::traits::ModPowerOf2Pow;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(3u32).mod_power_of_2_pow(Natural::from(10u32), 8), 169);
assert_eq!(
Natural::from(11u32).mod_power_of_2_pow(Natural::from(1000u32), 30),
289109473
);
type Output = Natural
source§impl<'a> ModPowerOf2PowAssign<&'a Natural> for Natural
impl<'a> ModPowerOf2PowAssign<&'a Natural> for Natural
source§fn mod_power_of_2_pow_assign(&mut self, exp: &Natural, pow: u64)
fn mod_power_of_2_pow_assign(&mut self, exp: &Natural, pow: u64)
Raises a Natural
to a Natural
power modulo $2^k$, in place. The base must be already
reduced modulo $2^k$. The Natural
on the right-hand side is taken by reference.
$x \gets y$, where $x, y < 2^k$ and $x^n \equiv y \mod 2^k$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is pow
, and $m$ is
exp.significant_bits()
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
use malachite_base::num::arithmetic::traits::ModPowerOf2PowAssign;
use malachite_nz::natural::Natural;
let mut x = Natural::from(3u32);
x.mod_power_of_2_pow_assign(&Natural::from(10u32), 8);
assert_eq!(x, 169);
let mut x = Natural::from(11u32);
x.mod_power_of_2_pow_assign(&Natural::from(1000u32), 30);
assert_eq!(x, 289109473);
source§impl ModPowerOf2PowAssign for Natural
impl ModPowerOf2PowAssign for Natural
source§fn mod_power_of_2_pow_assign(&mut self, exp: Natural, pow: u64)
fn mod_power_of_2_pow_assign(&mut self, exp: Natural, pow: u64)
Raises a Natural
to a Natural
power modulo $2^k$, in place. The base must be already
reduced modulo $2^k$. The Natural
on the right-hand side is taken by value.
$x \gets y$, where $x, y < 2^k$ and $x^n \equiv y \mod 2^k$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is pow
, and $m$ is
exp.significant_bits()
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
use malachite_base::num::arithmetic::traits::ModPowerOf2PowAssign;
use malachite_nz::natural::Natural;
let mut x = Natural::from(3u32);
x.mod_power_of_2_pow_assign(Natural::from(10u32), 8);
assert_eq!(x, 169);
let mut x = Natural::from(11u32);
x.mod_power_of_2_pow_assign(Natural::from(1000u32), 30);
assert_eq!(x, 289109473);
source§impl<'a> ModPowerOf2Shl<i128> for &'a Natural
impl<'a> ModPowerOf2Shl<i128> for &'a Natural
source§fn mod_power_of_2_shl(self, bits: i128, pow: u64) -> Natural
fn mod_power_of_2_shl(self, bits: i128, pow: u64) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo $2^k$. The
Natural
must be already reduced modulo $2^k$. The Natural
is taken by
reference.
$f(x, n, k) = y$, where $x, y < 2^k$ and $\lfloor 2^nx \rfloor \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
type Output = Natural
source§impl ModPowerOf2Shl<i128> for Natural
impl ModPowerOf2Shl<i128> for Natural
source§fn mod_power_of_2_shl(self, bits: i128, pow: u64) -> Natural
fn mod_power_of_2_shl(self, bits: i128, pow: u64) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo $2^k$. The
Natural
must be already reduced modulo $2^k$. The Natural
is taken by value.
$f(x, n, k) = y$, where $x, y < 2^k$ and $\lfloor 2^nx \rfloor \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
type Output = Natural
source§impl<'a> ModPowerOf2Shl<i16> for &'a Natural
impl<'a> ModPowerOf2Shl<i16> for &'a Natural
source§fn mod_power_of_2_shl(self, bits: i16, pow: u64) -> Natural
fn mod_power_of_2_shl(self, bits: i16, pow: u64) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo $2^k$. The
Natural
must be already reduced modulo $2^k$. The Natural
is taken by
reference.
$f(x, n, k) = y$, where $x, y < 2^k$ and $\lfloor 2^nx \rfloor \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
type Output = Natural
source§impl ModPowerOf2Shl<i16> for Natural
impl ModPowerOf2Shl<i16> for Natural
source§fn mod_power_of_2_shl(self, bits: i16, pow: u64) -> Natural
fn mod_power_of_2_shl(self, bits: i16, pow: u64) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo $2^k$. The
Natural
must be already reduced modulo $2^k$. The Natural
is taken by value.
$f(x, n, k) = y$, where $x, y < 2^k$ and $\lfloor 2^nx \rfloor \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
type Output = Natural
source§impl<'a> ModPowerOf2Shl<i32> for &'a Natural
impl<'a> ModPowerOf2Shl<i32> for &'a Natural
source§fn mod_power_of_2_shl(self, bits: i32, pow: u64) -> Natural
fn mod_power_of_2_shl(self, bits: i32, pow: u64) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo $2^k$. The
Natural
must be already reduced modulo $2^k$. The Natural
is taken by
reference.
$f(x, n, k) = y$, where $x, y < 2^k$ and $\lfloor 2^nx \rfloor \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
type Output = Natural
source§impl ModPowerOf2Shl<i32> for Natural
impl ModPowerOf2Shl<i32> for Natural
source§fn mod_power_of_2_shl(self, bits: i32, pow: u64) -> Natural
fn mod_power_of_2_shl(self, bits: i32, pow: u64) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo $2^k$. The
Natural
must be already reduced modulo $2^k$. The Natural
is taken by value.
$f(x, n, k) = y$, where $x, y < 2^k$ and $\lfloor 2^nx \rfloor \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
type Output = Natural
source§impl<'a> ModPowerOf2Shl<i64> for &'a Natural
impl<'a> ModPowerOf2Shl<i64> for &'a Natural
source§fn mod_power_of_2_shl(self, bits: i64, pow: u64) -> Natural
fn mod_power_of_2_shl(self, bits: i64, pow: u64) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo $2^k$. The
Natural
must be already reduced modulo $2^k$. The Natural
is taken by
reference.
$f(x, n, k) = y$, where $x, y < 2^k$ and $\lfloor 2^nx \rfloor \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
type Output = Natural
source§impl ModPowerOf2Shl<i64> for Natural
impl ModPowerOf2Shl<i64> for Natural
source§fn mod_power_of_2_shl(self, bits: i64, pow: u64) -> Natural
fn mod_power_of_2_shl(self, bits: i64, pow: u64) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo $2^k$. The
Natural
must be already reduced modulo $2^k$. The Natural
is taken by value.
$f(x, n, k) = y$, where $x, y < 2^k$ and $\lfloor 2^nx \rfloor \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
type Output = Natural
source§impl<'a> ModPowerOf2Shl<i8> for &'a Natural
impl<'a> ModPowerOf2Shl<i8> for &'a Natural
source§fn mod_power_of_2_shl(self, bits: i8, pow: u64) -> Natural
fn mod_power_of_2_shl(self, bits: i8, pow: u64) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo $2^k$. The
Natural
must be already reduced modulo $2^k$. The Natural
is taken by
reference.
$f(x, n, k) = y$, where $x, y < 2^k$ and $\lfloor 2^nx \rfloor \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
type Output = Natural
source§impl ModPowerOf2Shl<i8> for Natural
impl ModPowerOf2Shl<i8> for Natural
source§fn mod_power_of_2_shl(self, bits: i8, pow: u64) -> Natural
fn mod_power_of_2_shl(self, bits: i8, pow: u64) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo $2^k$. The
Natural
must be already reduced modulo $2^k$. The Natural
is taken by value.
$f(x, n, k) = y$, where $x, y < 2^k$ and $\lfloor 2^nx \rfloor \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
type Output = Natural
source§impl<'a> ModPowerOf2Shl<isize> for &'a Natural
impl<'a> ModPowerOf2Shl<isize> for &'a Natural
source§fn mod_power_of_2_shl(self, bits: isize, pow: u64) -> Natural
fn mod_power_of_2_shl(self, bits: isize, pow: u64) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo $2^k$. The
Natural
must be already reduced modulo $2^k$. The Natural
is taken by
reference.
$f(x, n, k) = y$, where $x, y < 2^k$ and $\lfloor 2^nx \rfloor \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
type Output = Natural
source§impl ModPowerOf2Shl<isize> for Natural
impl ModPowerOf2Shl<isize> for Natural
source§fn mod_power_of_2_shl(self, bits: isize, pow: u64) -> Natural
fn mod_power_of_2_shl(self, bits: isize, pow: u64) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo $2^k$. The
Natural
must be already reduced modulo $2^k$. The Natural
is taken by value.
$f(x, n, k) = y$, where $x, y < 2^k$ and $\lfloor 2^nx \rfloor \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
type Output = Natural
source§impl<'a> ModPowerOf2Shl<u128> for &'a Natural
impl<'a> ModPowerOf2Shl<u128> for &'a Natural
source§fn mod_power_of_2_shl(self, bits: u128, pow: u64) -> Natural
fn mod_power_of_2_shl(self, bits: u128, pow: u64) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo $2^k$. The
Natural
must be already reduced modulo $2^k$. The Natural
is taken by
reference.
$f(x, n, k) = y$, where $x, y < 2^k$ and $2^nx \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
type Output = Natural
source§impl ModPowerOf2Shl<u128> for Natural
impl ModPowerOf2Shl<u128> for Natural
source§fn mod_power_of_2_shl(self, bits: u128, pow: u64) -> Natural
fn mod_power_of_2_shl(self, bits: u128, pow: u64) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo $2^k$. The
Natural
must be already reduced modulo $2^k$. The Natural
is taken by value.
$f(x, n, k) = y$, where $x, y < 2^k$ and $2^nx \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
type Output = Natural
source§impl<'a> ModPowerOf2Shl<u16> for &'a Natural
impl<'a> ModPowerOf2Shl<u16> for &'a Natural
source§fn mod_power_of_2_shl(self, bits: u16, pow: u64) -> Natural
fn mod_power_of_2_shl(self, bits: u16, pow: u64) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo $2^k$. The
Natural
must be already reduced modulo $2^k$. The Natural
is taken by
reference.
$f(x, n, k) = y$, where $x, y < 2^k$ and $2^nx \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
type Output = Natural
source§impl ModPowerOf2Shl<u16> for Natural
impl ModPowerOf2Shl<u16> for Natural
source§fn mod_power_of_2_shl(self, bits: u16, pow: u64) -> Natural
fn mod_power_of_2_shl(self, bits: u16, pow: u64) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo $2^k$. The
Natural
must be already reduced modulo $2^k$. The Natural
is taken by value.
$f(x, n, k) = y$, where $x, y < 2^k$ and $2^nx \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
type Output = Natural
source§impl<'a> ModPowerOf2Shl<u32> for &'a Natural
impl<'a> ModPowerOf2Shl<u32> for &'a Natural
source§fn mod_power_of_2_shl(self, bits: u32, pow: u64) -> Natural
fn mod_power_of_2_shl(self, bits: u32, pow: u64) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo $2^k$. The
Natural
must be already reduced modulo $2^k$. The Natural
is taken by
reference.
$f(x, n, k) = y$, where $x, y < 2^k$ and $2^nx \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
type Output = Natural
source§impl ModPowerOf2Shl<u32> for Natural
impl ModPowerOf2Shl<u32> for Natural
source§fn mod_power_of_2_shl(self, bits: u32, pow: u64) -> Natural
fn mod_power_of_2_shl(self, bits: u32, pow: u64) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo $2^k$. The
Natural
must be already reduced modulo $2^k$. The Natural
is taken by value.
$f(x, n, k) = y$, where $x, y < 2^k$ and $2^nx \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
type Output = Natural
source§impl<'a> ModPowerOf2Shl<u64> for &'a Natural
impl<'a> ModPowerOf2Shl<u64> for &'a Natural
source§fn mod_power_of_2_shl(self, bits: u64, pow: u64) -> Natural
fn mod_power_of_2_shl(self, bits: u64, pow: u64) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo $2^k$. The
Natural
must be already reduced modulo $2^k$. The Natural
is taken by
reference.
$f(x, n, k) = y$, where $x, y < 2^k$ and $2^nx \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
type Output = Natural
source§impl ModPowerOf2Shl<u64> for Natural
impl ModPowerOf2Shl<u64> for Natural
source§fn mod_power_of_2_shl(self, bits: u64, pow: u64) -> Natural
fn mod_power_of_2_shl(self, bits: u64, pow: u64) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo $2^k$. The
Natural
must be already reduced modulo $2^k$. The Natural
is taken by value.
$f(x, n, k) = y$, where $x, y < 2^k$ and $2^nx \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
type Output = Natural
source§impl<'a> ModPowerOf2Shl<u8> for &'a Natural
impl<'a> ModPowerOf2Shl<u8> for &'a Natural
source§fn mod_power_of_2_shl(self, bits: u8, pow: u64) -> Natural
fn mod_power_of_2_shl(self, bits: u8, pow: u64) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo $2^k$. The
Natural
must be already reduced modulo $2^k$. The Natural
is taken by
reference.
$f(x, n, k) = y$, where $x, y < 2^k$ and $2^nx \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
type Output = Natural
source§impl ModPowerOf2Shl<u8> for Natural
impl ModPowerOf2Shl<u8> for Natural
source§fn mod_power_of_2_shl(self, bits: u8, pow: u64) -> Natural
fn mod_power_of_2_shl(self, bits: u8, pow: u64) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo $2^k$. The
Natural
must be already reduced modulo $2^k$. The Natural
is taken by value.
$f(x, n, k) = y$, where $x, y < 2^k$ and $2^nx \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
type Output = Natural
source§impl<'a> ModPowerOf2Shl<usize> for &'a Natural
impl<'a> ModPowerOf2Shl<usize> for &'a Natural
source§fn mod_power_of_2_shl(self, bits: usize, pow: u64) -> Natural
fn mod_power_of_2_shl(self, bits: usize, pow: u64) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo $2^k$. The
Natural
must be already reduced modulo $2^k$. The Natural
is taken by
reference.
$f(x, n, k) = y$, where $x, y < 2^k$ and $2^nx \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
type Output = Natural
source§impl ModPowerOf2Shl<usize> for Natural
impl ModPowerOf2Shl<usize> for Natural
source§fn mod_power_of_2_shl(self, bits: usize, pow: u64) -> Natural
fn mod_power_of_2_shl(self, bits: usize, pow: u64) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo $2^k$. The
Natural
must be already reduced modulo $2^k$. The Natural
is taken by value.
$f(x, n, k) = y$, where $x, y < 2^k$ and $2^nx \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
type Output = Natural
source§impl ModPowerOf2ShlAssign<i128> for Natural
impl ModPowerOf2ShlAssign<i128> for Natural
source§fn mod_power_of_2_shl_assign(&mut self, bits: i128, pow: u64)
fn mod_power_of_2_shl_assign(&mut self, bits: i128, pow: u64)
Left-shifts a Natural
(multiplies it by a power of 2) modulo $2^k$, in place.
The Natural
must be already reduced modulo $2^k$.
$x \gets y$, where $x, y < 2^k$ and $\lfloor 2^nx \rfloor \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
source§impl ModPowerOf2ShlAssign<i16> for Natural
impl ModPowerOf2ShlAssign<i16> for Natural
source§fn mod_power_of_2_shl_assign(&mut self, bits: i16, pow: u64)
fn mod_power_of_2_shl_assign(&mut self, bits: i16, pow: u64)
Left-shifts a Natural
(multiplies it by a power of 2) modulo $2^k$, in place.
The Natural
must be already reduced modulo $2^k$.
$x \gets y$, where $x, y < 2^k$ and $\lfloor 2^nx \rfloor \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
source§impl ModPowerOf2ShlAssign<i32> for Natural
impl ModPowerOf2ShlAssign<i32> for Natural
source§fn mod_power_of_2_shl_assign(&mut self, bits: i32, pow: u64)
fn mod_power_of_2_shl_assign(&mut self, bits: i32, pow: u64)
Left-shifts a Natural
(multiplies it by a power of 2) modulo $2^k$, in place.
The Natural
must be already reduced modulo $2^k$.
$x \gets y$, where $x, y < 2^k$ and $\lfloor 2^nx \rfloor \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
source§impl ModPowerOf2ShlAssign<i64> for Natural
impl ModPowerOf2ShlAssign<i64> for Natural
source§fn mod_power_of_2_shl_assign(&mut self, bits: i64, pow: u64)
fn mod_power_of_2_shl_assign(&mut self, bits: i64, pow: u64)
Left-shifts a Natural
(multiplies it by a power of 2) modulo $2^k$, in place.
The Natural
must be already reduced modulo $2^k$.
$x \gets y$, where $x, y < 2^k$ and $\lfloor 2^nx \rfloor \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
source§impl ModPowerOf2ShlAssign<i8> for Natural
impl ModPowerOf2ShlAssign<i8> for Natural
source§fn mod_power_of_2_shl_assign(&mut self, bits: i8, pow: u64)
fn mod_power_of_2_shl_assign(&mut self, bits: i8, pow: u64)
Left-shifts a Natural
(multiplies it by a power of 2) modulo $2^k$, in place.
The Natural
must be already reduced modulo $2^k$.
$x \gets y$, where $x, y < 2^k$ and $\lfloor 2^nx \rfloor \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
source§impl ModPowerOf2ShlAssign<isize> for Natural
impl ModPowerOf2ShlAssign<isize> for Natural
source§fn mod_power_of_2_shl_assign(&mut self, bits: isize, pow: u64)
fn mod_power_of_2_shl_assign(&mut self, bits: isize, pow: u64)
Left-shifts a Natural
(multiplies it by a power of 2) modulo $2^k$, in place.
The Natural
must be already reduced modulo $2^k$.
$x \gets y$, where $x, y < 2^k$ and $\lfloor 2^nx \rfloor \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
source§impl ModPowerOf2ShlAssign<u128> for Natural
impl ModPowerOf2ShlAssign<u128> for Natural
source§fn mod_power_of_2_shl_assign(&mut self, bits: u128, pow: u64)
fn mod_power_of_2_shl_assign(&mut self, bits: u128, pow: u64)
Left-shifts a Natural
(multiplies it by a power of 2) modulo $2^k$, in place.
The Natural
must be already reduced modulo $2^k$.
$x \gets y$, where $x, y < 2^k$ and $2^nx \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
source§impl ModPowerOf2ShlAssign<u16> for Natural
impl ModPowerOf2ShlAssign<u16> for Natural
source§fn mod_power_of_2_shl_assign(&mut self, bits: u16, pow: u64)
fn mod_power_of_2_shl_assign(&mut self, bits: u16, pow: u64)
Left-shifts a Natural
(multiplies it by a power of 2) modulo $2^k$, in place.
The Natural
must be already reduced modulo $2^k$.
$x \gets y$, where $x, y < 2^k$ and $2^nx \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
source§impl ModPowerOf2ShlAssign<u32> for Natural
impl ModPowerOf2ShlAssign<u32> for Natural
source§fn mod_power_of_2_shl_assign(&mut self, bits: u32, pow: u64)
fn mod_power_of_2_shl_assign(&mut self, bits: u32, pow: u64)
Left-shifts a Natural
(multiplies it by a power of 2) modulo $2^k$, in place.
The Natural
must be already reduced modulo $2^k$.
$x \gets y$, where $x, y < 2^k$ and $2^nx \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
source§impl ModPowerOf2ShlAssign<u64> for Natural
impl ModPowerOf2ShlAssign<u64> for Natural
source§fn mod_power_of_2_shl_assign(&mut self, bits: u64, pow: u64)
fn mod_power_of_2_shl_assign(&mut self, bits: u64, pow: u64)
Left-shifts a Natural
(multiplies it by a power of 2) modulo $2^k$, in place.
The Natural
must be already reduced modulo $2^k$.
$x \gets y$, where $x, y < 2^k$ and $2^nx \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
source§impl ModPowerOf2ShlAssign<u8> for Natural
impl ModPowerOf2ShlAssign<u8> for Natural
source§fn mod_power_of_2_shl_assign(&mut self, bits: u8, pow: u64)
fn mod_power_of_2_shl_assign(&mut self, bits: u8, pow: u64)
Left-shifts a Natural
(multiplies it by a power of 2) modulo $2^k$, in place.
The Natural
must be already reduced modulo $2^k$.
$x \gets y$, where $x, y < 2^k$ and $2^nx \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
source§impl ModPowerOf2ShlAssign<usize> for Natural
impl ModPowerOf2ShlAssign<usize> for Natural
source§fn mod_power_of_2_shl_assign(&mut self, bits: usize, pow: u64)
fn mod_power_of_2_shl_assign(&mut self, bits: usize, pow: u64)
Left-shifts a Natural
(multiplies it by a power of 2) modulo $2^k$, in place.
The Natural
must be already reduced modulo $2^k$.
$x \gets y$, where $x, y < 2^k$ and $2^nx \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
source§impl<'a> ModPowerOf2Shr<i128> for &'a Natural
impl<'a> ModPowerOf2Shr<i128> for &'a Natural
source§fn mod_power_of_2_shr(self, bits: i128, pow: u64) -> Natural
fn mod_power_of_2_shr(self, bits: i128, pow: u64) -> Natural
Right-shifts a Natural
(divides it by a power of 2) modulo $2^k$. The
Natural
must be already reduced modulo $2^k$. The Natural
is taken by
reference.
$f(x, n, k) = y$, where $x, y < 2^k$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
type Output = Natural
source§impl ModPowerOf2Shr<i128> for Natural
impl ModPowerOf2Shr<i128> for Natural
source§fn mod_power_of_2_shr(self, bits: i128, pow: u64) -> Natural
fn mod_power_of_2_shr(self, bits: i128, pow: u64) -> Natural
Right-shifts a Natural
(divides it by a power of 2) modulo $2^k$. The
Natural
must be already reduced modulo $2^k$. The Natural
is taken by value.
$f(x, n, k) = y$, where $x, y < 2^k$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
type Output = Natural
source§impl<'a> ModPowerOf2Shr<i16> for &'a Natural
impl<'a> ModPowerOf2Shr<i16> for &'a Natural
source§fn mod_power_of_2_shr(self, bits: i16, pow: u64) -> Natural
fn mod_power_of_2_shr(self, bits: i16, pow: u64) -> Natural
Right-shifts a Natural
(divides it by a power of 2) modulo $2^k$. The
Natural
must be already reduced modulo $2^k$. The Natural
is taken by
reference.
$f(x, n, k) = y$, where $x, y < 2^k$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
type Output = Natural
source§impl ModPowerOf2Shr<i16> for Natural
impl ModPowerOf2Shr<i16> for Natural
source§fn mod_power_of_2_shr(self, bits: i16, pow: u64) -> Natural
fn mod_power_of_2_shr(self, bits: i16, pow: u64) -> Natural
Right-shifts a Natural
(divides it by a power of 2) modulo $2^k$. The
Natural
must be already reduced modulo $2^k$. The Natural
is taken by value.
$f(x, n, k) = y$, where $x, y < 2^k$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
type Output = Natural
source§impl<'a> ModPowerOf2Shr<i32> for &'a Natural
impl<'a> ModPowerOf2Shr<i32> for &'a Natural
source§fn mod_power_of_2_shr(self, bits: i32, pow: u64) -> Natural
fn mod_power_of_2_shr(self, bits: i32, pow: u64) -> Natural
Right-shifts a Natural
(divides it by a power of 2) modulo $2^k$. The
Natural
must be already reduced modulo $2^k$. The Natural
is taken by
reference.
$f(x, n, k) = y$, where $x, y < 2^k$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
type Output = Natural
source§impl ModPowerOf2Shr<i32> for Natural
impl ModPowerOf2Shr<i32> for Natural
source§fn mod_power_of_2_shr(self, bits: i32, pow: u64) -> Natural
fn mod_power_of_2_shr(self, bits: i32, pow: u64) -> Natural
Right-shifts a Natural
(divides it by a power of 2) modulo $2^k$. The
Natural
must be already reduced modulo $2^k$. The Natural
is taken by value.
$f(x, n, k) = y$, where $x, y < 2^k$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
type Output = Natural
source§impl<'a> ModPowerOf2Shr<i64> for &'a Natural
impl<'a> ModPowerOf2Shr<i64> for &'a Natural
source§fn mod_power_of_2_shr(self, bits: i64, pow: u64) -> Natural
fn mod_power_of_2_shr(self, bits: i64, pow: u64) -> Natural
Right-shifts a Natural
(divides it by a power of 2) modulo $2^k$. The
Natural
must be already reduced modulo $2^k$. The Natural
is taken by
reference.
$f(x, n, k) = y$, where $x, y < 2^k$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
type Output = Natural
source§impl ModPowerOf2Shr<i64> for Natural
impl ModPowerOf2Shr<i64> for Natural
source§fn mod_power_of_2_shr(self, bits: i64, pow: u64) -> Natural
fn mod_power_of_2_shr(self, bits: i64, pow: u64) -> Natural
Right-shifts a Natural
(divides it by a power of 2) modulo $2^k$. The
Natural
must be already reduced modulo $2^k$. The Natural
is taken by value.
$f(x, n, k) = y$, where $x, y < 2^k$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
type Output = Natural
source§impl<'a> ModPowerOf2Shr<i8> for &'a Natural
impl<'a> ModPowerOf2Shr<i8> for &'a Natural
source§fn mod_power_of_2_shr(self, bits: i8, pow: u64) -> Natural
fn mod_power_of_2_shr(self, bits: i8, pow: u64) -> Natural
Right-shifts a Natural
(divides it by a power of 2) modulo $2^k$. The
Natural
must be already reduced modulo $2^k$. The Natural
is taken by
reference.
$f(x, n, k) = y$, where $x, y < 2^k$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
type Output = Natural
source§impl ModPowerOf2Shr<i8> for Natural
impl ModPowerOf2Shr<i8> for Natural
source§fn mod_power_of_2_shr(self, bits: i8, pow: u64) -> Natural
fn mod_power_of_2_shr(self, bits: i8, pow: u64) -> Natural
Right-shifts a Natural
(divides it by a power of 2) modulo $2^k$. The
Natural
must be already reduced modulo $2^k$. The Natural
is taken by value.
$f(x, n, k) = y$, where $x, y < 2^k$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
type Output = Natural
source§impl<'a> ModPowerOf2Shr<isize> for &'a Natural
impl<'a> ModPowerOf2Shr<isize> for &'a Natural
source§fn mod_power_of_2_shr(self, bits: isize, pow: u64) -> Natural
fn mod_power_of_2_shr(self, bits: isize, pow: u64) -> Natural
Right-shifts a Natural
(divides it by a power of 2) modulo $2^k$. The
Natural
must be already reduced modulo $2^k$. The Natural
is taken by
reference.
$f(x, n, k) = y$, where $x, y < 2^k$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
type Output = Natural
source§impl ModPowerOf2Shr<isize> for Natural
impl ModPowerOf2Shr<isize> for Natural
source§fn mod_power_of_2_shr(self, bits: isize, pow: u64) -> Natural
fn mod_power_of_2_shr(self, bits: isize, pow: u64) -> Natural
Right-shifts a Natural
(divides it by a power of 2) modulo $2^k$. The
Natural
must be already reduced modulo $2^k$. The Natural
is taken by value.
$f(x, n, k) = y$, where $x, y < 2^k$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
type Output = Natural
source§impl ModPowerOf2ShrAssign<i128> for Natural
impl ModPowerOf2ShrAssign<i128> for Natural
source§fn mod_power_of_2_shr_assign(&mut self, bits: i128, pow: u64)
fn mod_power_of_2_shr_assign(&mut self, bits: i128, pow: u64)
Right-shifts a Natural
(divides it by a power of 2) modulo $2^k$, in place. The
Natural
must be already reduced modulo $2^k$.
$x \gets y$, where $x, y < 2^k$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
source§impl ModPowerOf2ShrAssign<i16> for Natural
impl ModPowerOf2ShrAssign<i16> for Natural
source§fn mod_power_of_2_shr_assign(&mut self, bits: i16, pow: u64)
fn mod_power_of_2_shr_assign(&mut self, bits: i16, pow: u64)
Right-shifts a Natural
(divides it by a power of 2) modulo $2^k$, in place. The
Natural
must be already reduced modulo $2^k$.
$x \gets y$, where $x, y < 2^k$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
source§impl ModPowerOf2ShrAssign<i32> for Natural
impl ModPowerOf2ShrAssign<i32> for Natural
source§fn mod_power_of_2_shr_assign(&mut self, bits: i32, pow: u64)
fn mod_power_of_2_shr_assign(&mut self, bits: i32, pow: u64)
Right-shifts a Natural
(divides it by a power of 2) modulo $2^k$, in place. The
Natural
must be already reduced modulo $2^k$.
$x \gets y$, where $x, y < 2^k$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
source§impl ModPowerOf2ShrAssign<i64> for Natural
impl ModPowerOf2ShrAssign<i64> for Natural
source§fn mod_power_of_2_shr_assign(&mut self, bits: i64, pow: u64)
fn mod_power_of_2_shr_assign(&mut self, bits: i64, pow: u64)
Right-shifts a Natural
(divides it by a power of 2) modulo $2^k$, in place. The
Natural
must be already reduced modulo $2^k$.
$x \gets y$, where $x, y < 2^k$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
source§impl ModPowerOf2ShrAssign<i8> for Natural
impl ModPowerOf2ShrAssign<i8> for Natural
source§fn mod_power_of_2_shr_assign(&mut self, bits: i8, pow: u64)
fn mod_power_of_2_shr_assign(&mut self, bits: i8, pow: u64)
Right-shifts a Natural
(divides it by a power of 2) modulo $2^k$, in place. The
Natural
must be already reduced modulo $2^k$.
$x \gets y$, where $x, y < 2^k$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
source§impl ModPowerOf2ShrAssign<isize> for Natural
impl ModPowerOf2ShrAssign<isize> for Natural
source§fn mod_power_of_2_shr_assign(&mut self, bits: isize, pow: u64)
fn mod_power_of_2_shr_assign(&mut self, bits: isize, pow: u64)
Right-shifts a Natural
(divides it by a power of 2) modulo $2^k$, in place. The
Natural
must be already reduced modulo $2^k$.
$x \gets y$, where $x, y < 2^k$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
See here.
source§impl<'a> ModPowerOf2Square for &'a Natural
impl<'a> ModPowerOf2Square for &'a Natural
source§fn mod_power_of_2_square(self, pow: u64) -> Natural
fn mod_power_of_2_square(self, pow: u64) -> Natural
Squares a Natural
modulo $2^k$. The input must be already reduced modulo $2^k$. The
Natural
is taken by reference.
$f(x, k) = y$, where $x, y < 2^k$ and $x^2 \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
use malachite_base::num::arithmetic::traits::ModPowerOf2Square;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!((&Natural::ZERO).mod_power_of_2_square(2), 0);
assert_eq!((&Natural::from(5u32)).mod_power_of_2_square(3), 1);
assert_eq!(
(&Natural::from_str("12345678987654321").unwrap())
.mod_power_of_2_square(64).to_string(),
"16556040056090124897"
);
type Output = Natural
source§impl ModPowerOf2Square for Natural
impl ModPowerOf2Square for Natural
source§fn mod_power_of_2_square(self, pow: u64) -> Natural
fn mod_power_of_2_square(self, pow: u64) -> Natural
Squares a Natural
modulo $2^k$. The input must be already reduced modulo $2^k$. The
Natural
is taken by value.
$f(x, k) = y$, where $x, y < 2^k$ and $x^2 \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
use malachite_base::num::arithmetic::traits::ModPowerOf2Square;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!(Natural::ZERO.mod_power_of_2_square(2), 0);
assert_eq!(Natural::from(5u32).mod_power_of_2_square(3), 1);
assert_eq!(
Natural::from_str("12345678987654321").unwrap().mod_power_of_2_square(64).to_string(),
"16556040056090124897"
);
type Output = Natural
source§impl ModPowerOf2SquareAssign for Natural
impl ModPowerOf2SquareAssign for Natural
source§fn mod_power_of_2_square_assign(&mut self, pow: u64)
fn mod_power_of_2_square_assign(&mut self, pow: u64)
Squares a Natural
modulo $2^k$, in place. The input must be already reduced modulo
$2^k$.
$x \gets y$, where $x, y < 2^k$ and $x^2 \equiv y \mod 2^k$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
is greater than or equal to $2^k$.
§Examples
use malachite_base::num::arithmetic::traits::ModPowerOf2SquareAssign;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
use core::str::FromStr;
let mut n = Natural::ZERO;
n.mod_power_of_2_square_assign(2);
assert_eq!(n, 0);
let mut n = Natural::from(5u32);
n.mod_power_of_2_square_assign(3);
assert_eq!(n, 1);
let mut n = Natural::from_str("12345678987654321").unwrap();
n.mod_power_of_2_square_assign(64);
assert_eq!(n.to_string(), "16556040056090124897");
source§impl<'a, 'b> ModPowerOf2Sub<&'a Natural> for &'b Natural
impl<'a, 'b> ModPowerOf2Sub<&'a Natural> for &'b Natural
source§fn mod_power_of_2_sub(self, other: &'a Natural, pow: u64) -> Natural
fn mod_power_of_2_sub(self, other: &'a Natural, pow: u64) -> Natural
Subtracts two Natural
modulo $2^k$. The inputs must be already reduced modulo $2^k$.
Both Natural
s are taken by reference.
$f(x, y, k) = z$, where $x, y, z < 2^k$ and $x - y \equiv z \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
or other
are greater than or equal to $2^k$.
§Examples
use malachite_base::num::arithmetic::traits::ModPowerOf2Sub;
use malachite_base::num::basic::traits::Two;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::from(10u32)).mod_power_of_2_sub(&Natural::TWO, 4), 8);
assert_eq!((&Natural::from(56u32)).mod_power_of_2_sub(&Natural::from(123u32), 9), 445);
type Output = Natural
source§impl<'a> ModPowerOf2Sub<&'a Natural> for Natural
impl<'a> ModPowerOf2Sub<&'a Natural> for Natural
source§fn mod_power_of_2_sub(self, other: &'a Natural, pow: u64) -> Natural
fn mod_power_of_2_sub(self, other: &'a Natural, pow: u64) -> Natural
Subtracts two Natural
s modulo $2^k$. The inputs must be already reduced modulo $2^k$.
The first Natural
is taken by value and the second by reference.
$f(x, y, k) = z$, where $x, y, z < 2^k$ and $x - y \equiv z \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
or other
are greater than or equal to $2^k$.
§Examples
use malachite_base::num::arithmetic::traits::ModPowerOf2Sub;
use malachite_base::num::basic::traits::Two;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(10u32).mod_power_of_2_sub(&Natural::TWO, 4), 8);
assert_eq!(Natural::from(56u32).mod_power_of_2_sub(&Natural::from(123u32), 9), 445);
type Output = Natural
source§impl<'a> ModPowerOf2Sub<Natural> for &'a Natural
impl<'a> ModPowerOf2Sub<Natural> for &'a Natural
source§fn mod_power_of_2_sub(self, other: Natural, pow: u64) -> Natural
fn mod_power_of_2_sub(self, other: Natural, pow: u64) -> Natural
Subtracts two Natural
s modulo $2^k$. The inputs must be already reduced modulo $2^k$.
The first Natural
is taken by reference and the second by value.
$f(x, y, k) = z$, where $x, y, z < 2^k$ and $x - y \equiv z \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
or other
are greater than or equal to $2^k$.
§Examples
use malachite_base::num::arithmetic::traits::ModPowerOf2Sub;
use malachite_base::num::basic::traits::Two;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::from(10u32)).mod_power_of_2_sub(Natural::TWO, 4), 8);
assert_eq!((&Natural::from(56u32)).mod_power_of_2_sub(Natural::from(123u32), 9), 445);
type Output = Natural
source§impl ModPowerOf2Sub for Natural
impl ModPowerOf2Sub for Natural
source§fn mod_power_of_2_sub(self, other: Natural, pow: u64) -> Natural
fn mod_power_of_2_sub(self, other: Natural, pow: u64) -> Natural
Subtracts two Natural
s modulo $2^k$. The inputs must be already reduced modulo $2^k$.
Both Natural
s are taken by value.
$f(x, y, k) = z$, where $x, y, z < 2^k$ and $x - y \equiv z \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
or other
are greater than or equal to $2^k$.
§Examples
use malachite_base::num::arithmetic::traits::ModPowerOf2Sub;
use malachite_base::num::basic::traits::Two;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(10u32).mod_power_of_2_sub(Natural::TWO, 4), 8);
assert_eq!(Natural::from(56u32).mod_power_of_2_sub(Natural::from(123u32), 9), 445);
type Output = Natural
source§impl<'a> ModPowerOf2SubAssign<&'a Natural> for Natural
impl<'a> ModPowerOf2SubAssign<&'a Natural> for Natural
source§fn mod_power_of_2_sub_assign(&mut self, other: &'a Natural, pow: u64)
fn mod_power_of_2_sub_assign(&mut self, other: &'a Natural, pow: u64)
Subtracts two Natural
modulo $2^k$, in place. The inputs must be already reduced modulo
$2^k$. The Natural
on the right-hand side is taken by reference.
$x \gets z$, where $x, y, z < 2^k$ and $x - y \equiv z \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
or other
are greater than or equal to $2^k$.
§Examples
use malachite_base::num::arithmetic::traits::ModPowerOf2SubAssign;
use malachite_base::num::basic::traits::Two;
use malachite_nz::natural::Natural;
let mut x = Natural::from(10u32);
x.mod_power_of_2_sub_assign(&Natural::TWO, 4);
assert_eq!(x, 8);
let mut x = Natural::from(56u32);
x.mod_power_of_2_sub_assign(&Natural::from(123u32), 9);
assert_eq!(x, 445);
source§impl ModPowerOf2SubAssign for Natural
impl ModPowerOf2SubAssign for Natural
source§fn mod_power_of_2_sub_assign(&mut self, other: Natural, pow: u64)
fn mod_power_of_2_sub_assign(&mut self, other: Natural, pow: u64)
Subtracts two Natural
modulo $2^k$, in place. The inputs must be already reduced modulo
$2^k$. The Natural
on the right-hand side is taken by value.
$x \gets z$, where $x, y, z < 2^k$ and $x - y \equiv z \mod 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Panics
Panics if self
or other
are greater than or equal to $2^k$.
§Examples
use malachite_base::num::arithmetic::traits::ModPowerOf2SubAssign;
use malachite_base::num::basic::traits::Two;
use malachite_nz::natural::Natural;
let mut x = Natural::from(10u32);
x.mod_power_of_2_sub_assign(Natural::TWO, 4);
assert_eq!(x, 8);
let mut x = Natural::from(56u32);
x.mod_power_of_2_sub_assign(Natural::from(123u32), 9);
assert_eq!(x, 445);
source§impl ModShl<i128> for Natural
impl ModShl<i128> for Natural
source§fn mod_shl(self, bits: i128, m: Natural) -> Natural
fn mod_shl(self, bits: i128, m: Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. Both Natural
s are
taken by value.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^nx \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a, 'b> ModShl<i128, &'b Natural> for &'a Natural
impl<'a, 'b> ModShl<i128, &'b Natural> for &'a Natural
source§fn mod_shl(self, bits: i128, m: &'b Natural) -> Natural
fn mod_shl(self, bits: i128, m: &'b Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. Both Natural
s are
taken by reference.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^nx \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a> ModShl<i128, &'a Natural> for Natural
impl<'a> ModShl<i128, &'a Natural> for Natural
source§fn mod_shl(self, bits: i128, m: &'a Natural) -> Natural
fn mod_shl(self, bits: i128, m: &'a Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. The first Natural
is taken by value and the second by reference.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^nx \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a> ModShl<i128, Natural> for &'a Natural
impl<'a> ModShl<i128, Natural> for &'a Natural
source§fn mod_shl(self, bits: i128, m: Natural) -> Natural
fn mod_shl(self, bits: i128, m: Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. The first Natural
is taken by reference and the second by value.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^nx \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl ModShl<i16> for Natural
impl ModShl<i16> for Natural
source§fn mod_shl(self, bits: i16, m: Natural) -> Natural
fn mod_shl(self, bits: i16, m: Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. Both Natural
s are
taken by value.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^nx \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a, 'b> ModShl<i16, &'b Natural> for &'a Natural
impl<'a, 'b> ModShl<i16, &'b Natural> for &'a Natural
source§fn mod_shl(self, bits: i16, m: &'b Natural) -> Natural
fn mod_shl(self, bits: i16, m: &'b Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. Both Natural
s are
taken by reference.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^nx \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a> ModShl<i16, &'a Natural> for Natural
impl<'a> ModShl<i16, &'a Natural> for Natural
source§fn mod_shl(self, bits: i16, m: &'a Natural) -> Natural
fn mod_shl(self, bits: i16, m: &'a Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. The first Natural
is taken by value and the second by reference.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^nx \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a> ModShl<i16, Natural> for &'a Natural
impl<'a> ModShl<i16, Natural> for &'a Natural
source§fn mod_shl(self, bits: i16, m: Natural) -> Natural
fn mod_shl(self, bits: i16, m: Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. The first Natural
is taken by reference and the second by value.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^nx \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl ModShl<i32> for Natural
impl ModShl<i32> for Natural
source§fn mod_shl(self, bits: i32, m: Natural) -> Natural
fn mod_shl(self, bits: i32, m: Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. Both Natural
s are
taken by value.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^nx \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a, 'b> ModShl<i32, &'b Natural> for &'a Natural
impl<'a, 'b> ModShl<i32, &'b Natural> for &'a Natural
source§fn mod_shl(self, bits: i32, m: &'b Natural) -> Natural
fn mod_shl(self, bits: i32, m: &'b Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. Both Natural
s are
taken by reference.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^nx \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a> ModShl<i32, &'a Natural> for Natural
impl<'a> ModShl<i32, &'a Natural> for Natural
source§fn mod_shl(self, bits: i32, m: &'a Natural) -> Natural
fn mod_shl(self, bits: i32, m: &'a Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. The first Natural
is taken by value and the second by reference.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^nx \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a> ModShl<i32, Natural> for &'a Natural
impl<'a> ModShl<i32, Natural> for &'a Natural
source§fn mod_shl(self, bits: i32, m: Natural) -> Natural
fn mod_shl(self, bits: i32, m: Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. The first Natural
is taken by reference and the second by value.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^nx \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl ModShl<i64> for Natural
impl ModShl<i64> for Natural
source§fn mod_shl(self, bits: i64, m: Natural) -> Natural
fn mod_shl(self, bits: i64, m: Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. Both Natural
s are
taken by value.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^nx \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a, 'b> ModShl<i64, &'b Natural> for &'a Natural
impl<'a, 'b> ModShl<i64, &'b Natural> for &'a Natural
source§fn mod_shl(self, bits: i64, m: &'b Natural) -> Natural
fn mod_shl(self, bits: i64, m: &'b Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. Both Natural
s are
taken by reference.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^nx \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a> ModShl<i64, &'a Natural> for Natural
impl<'a> ModShl<i64, &'a Natural> for Natural
source§fn mod_shl(self, bits: i64, m: &'a Natural) -> Natural
fn mod_shl(self, bits: i64, m: &'a Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. The first Natural
is taken by value and the second by reference.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^nx \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a> ModShl<i64, Natural> for &'a Natural
impl<'a> ModShl<i64, Natural> for &'a Natural
source§fn mod_shl(self, bits: i64, m: Natural) -> Natural
fn mod_shl(self, bits: i64, m: Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. The first Natural
is taken by reference and the second by value.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^nx \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl ModShl<i8> for Natural
impl ModShl<i8> for Natural
source§fn mod_shl(self, bits: i8, m: Natural) -> Natural
fn mod_shl(self, bits: i8, m: Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. Both Natural
s are
taken by value.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^nx \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a, 'b> ModShl<i8, &'b Natural> for &'a Natural
impl<'a, 'b> ModShl<i8, &'b Natural> for &'a Natural
source§fn mod_shl(self, bits: i8, m: &'b Natural) -> Natural
fn mod_shl(self, bits: i8, m: &'b Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. Both Natural
s are
taken by reference.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^nx \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a> ModShl<i8, &'a Natural> for Natural
impl<'a> ModShl<i8, &'a Natural> for Natural
source§fn mod_shl(self, bits: i8, m: &'a Natural) -> Natural
fn mod_shl(self, bits: i8, m: &'a Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. The first Natural
is taken by value and the second by reference.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^nx \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a> ModShl<i8, Natural> for &'a Natural
impl<'a> ModShl<i8, Natural> for &'a Natural
source§fn mod_shl(self, bits: i8, m: Natural) -> Natural
fn mod_shl(self, bits: i8, m: Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. The first Natural
is taken by reference and the second by value.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^nx \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl ModShl<isize> for Natural
impl ModShl<isize> for Natural
source§fn mod_shl(self, bits: isize, m: Natural) -> Natural
fn mod_shl(self, bits: isize, m: Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. Both Natural
s are
taken by value.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^nx \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a, 'b> ModShl<isize, &'b Natural> for &'a Natural
impl<'a, 'b> ModShl<isize, &'b Natural> for &'a Natural
source§fn mod_shl(self, bits: isize, m: &'b Natural) -> Natural
fn mod_shl(self, bits: isize, m: &'b Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. Both Natural
s are
taken by reference.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^nx \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a> ModShl<isize, &'a Natural> for Natural
impl<'a> ModShl<isize, &'a Natural> for Natural
source§fn mod_shl(self, bits: isize, m: &'a Natural) -> Natural
fn mod_shl(self, bits: isize, m: &'a Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. The first Natural
is taken by value and the second by reference.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^nx \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a> ModShl<isize, Natural> for &'a Natural
impl<'a> ModShl<isize, Natural> for &'a Natural
source§fn mod_shl(self, bits: isize, m: Natural) -> Natural
fn mod_shl(self, bits: isize, m: Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. The first Natural
is taken by reference and the second by value.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^nx \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl ModShl<u128> for Natural
impl ModShl<u128> for Natural
source§fn mod_shl(self, bits: u128, m: Natural) -> Natural
fn mod_shl(self, bits: u128, m: Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. Both Natural
s are
taken by value.
$f(x, n, m) = y$, where $x, y < m$ and $2^nx \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a, 'b> ModShl<u128, &'b Natural> for &'a Natural
impl<'a, 'b> ModShl<u128, &'b Natural> for &'a Natural
source§fn mod_shl(self, bits: u128, m: &'b Natural) -> Natural
fn mod_shl(self, bits: u128, m: &'b Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. Both Natural
s are
taken by reference.
$f(x, n, m) = y$, where $x, y < m$ and $2^nx \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a> ModShl<u128, &'a Natural> for Natural
impl<'a> ModShl<u128, &'a Natural> for Natural
source§fn mod_shl(self, bits: u128, m: &'a Natural) -> Natural
fn mod_shl(self, bits: u128, m: &'a Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. The first Natural
is taken by value and the second by reference.
$f(x, n, m) = y$, where $x, y < m$ and $2^nx \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a> ModShl<u128, Natural> for &'a Natural
impl<'a> ModShl<u128, Natural> for &'a Natural
source§fn mod_shl(self, bits: u128, m: Natural) -> Natural
fn mod_shl(self, bits: u128, m: Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. The first Natural
is taken by reference and the second by value.
$f(x, n, m) = y$, where $x, y < m$ and $2^nx \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl ModShl<u16> for Natural
impl ModShl<u16> for Natural
source§fn mod_shl(self, bits: u16, m: Natural) -> Natural
fn mod_shl(self, bits: u16, m: Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. Both Natural
s are
taken by value.
$f(x, n, m) = y$, where $x, y < m$ and $2^nx \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a, 'b> ModShl<u16, &'b Natural> for &'a Natural
impl<'a, 'b> ModShl<u16, &'b Natural> for &'a Natural
source§fn mod_shl(self, bits: u16, m: &'b Natural) -> Natural
fn mod_shl(self, bits: u16, m: &'b Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. Both Natural
s are
taken by reference.
$f(x, n, m) = y$, where $x, y < m$ and $2^nx \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a> ModShl<u16, &'a Natural> for Natural
impl<'a> ModShl<u16, &'a Natural> for Natural
source§fn mod_shl(self, bits: u16, m: &'a Natural) -> Natural
fn mod_shl(self, bits: u16, m: &'a Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. The first Natural
is taken by value and the second by reference.
$f(x, n, m) = y$, where $x, y < m$ and $2^nx \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a> ModShl<u16, Natural> for &'a Natural
impl<'a> ModShl<u16, Natural> for &'a Natural
source§fn mod_shl(self, bits: u16, m: Natural) -> Natural
fn mod_shl(self, bits: u16, m: Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. The first Natural
is taken by reference and the second by value.
$f(x, n, m) = y$, where $x, y < m$ and $2^nx \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl ModShl<u32> for Natural
impl ModShl<u32> for Natural
source§fn mod_shl(self, bits: u32, m: Natural) -> Natural
fn mod_shl(self, bits: u32, m: Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. Both Natural
s are
taken by value.
$f(x, n, m) = y$, where $x, y < m$ and $2^nx \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a, 'b> ModShl<u32, &'b Natural> for &'a Natural
impl<'a, 'b> ModShl<u32, &'b Natural> for &'a Natural
source§fn mod_shl(self, bits: u32, m: &'b Natural) -> Natural
fn mod_shl(self, bits: u32, m: &'b Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. Both Natural
s are
taken by reference.
$f(x, n, m) = y$, where $x, y < m$ and $2^nx \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a> ModShl<u32, &'a Natural> for Natural
impl<'a> ModShl<u32, &'a Natural> for Natural
source§fn mod_shl(self, bits: u32, m: &'a Natural) -> Natural
fn mod_shl(self, bits: u32, m: &'a Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. The first Natural
is taken by value and the second by reference.
$f(x, n, m) = y$, where $x, y < m$ and $2^nx \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a> ModShl<u32, Natural> for &'a Natural
impl<'a> ModShl<u32, Natural> for &'a Natural
source§fn mod_shl(self, bits: u32, m: Natural) -> Natural
fn mod_shl(self, bits: u32, m: Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. The first Natural
is taken by reference and the second by value.
$f(x, n, m) = y$, where $x, y < m$ and $2^nx \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl ModShl<u64> for Natural
impl ModShl<u64> for Natural
source§fn mod_shl(self, bits: u64, m: Natural) -> Natural
fn mod_shl(self, bits: u64, m: Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. Both Natural
s are
taken by value.
$f(x, n, m) = y$, where $x, y < m$ and $2^nx \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a, 'b> ModShl<u64, &'b Natural> for &'a Natural
impl<'a, 'b> ModShl<u64, &'b Natural> for &'a Natural
source§fn mod_shl(self, bits: u64, m: &'b Natural) -> Natural
fn mod_shl(self, bits: u64, m: &'b Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. Both Natural
s are
taken by reference.
$f(x, n, m) = y$, where $x, y < m$ and $2^nx \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a> ModShl<u64, &'a Natural> for Natural
impl<'a> ModShl<u64, &'a Natural> for Natural
source§fn mod_shl(self, bits: u64, m: &'a Natural) -> Natural
fn mod_shl(self, bits: u64, m: &'a Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. The first Natural
is taken by value and the second by reference.
$f(x, n, m) = y$, where $x, y < m$ and $2^nx \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a> ModShl<u64, Natural> for &'a Natural
impl<'a> ModShl<u64, Natural> for &'a Natural
source§fn mod_shl(self, bits: u64, m: Natural) -> Natural
fn mod_shl(self, bits: u64, m: Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. The first Natural
is taken by reference and the second by value.
$f(x, n, m) = y$, where $x, y < m$ and $2^nx \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl ModShl<u8> for Natural
impl ModShl<u8> for Natural
source§fn mod_shl(self, bits: u8, m: Natural) -> Natural
fn mod_shl(self, bits: u8, m: Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. Both Natural
s are
taken by value.
$f(x, n, m) = y$, where $x, y < m$ and $2^nx \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a, 'b> ModShl<u8, &'b Natural> for &'a Natural
impl<'a, 'b> ModShl<u8, &'b Natural> for &'a Natural
source§fn mod_shl(self, bits: u8, m: &'b Natural) -> Natural
fn mod_shl(self, bits: u8, m: &'b Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. Both Natural
s are
taken by reference.
$f(x, n, m) = y$, where $x, y < m$ and $2^nx \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a> ModShl<u8, &'a Natural> for Natural
impl<'a> ModShl<u8, &'a Natural> for Natural
source§fn mod_shl(self, bits: u8, m: &'a Natural) -> Natural
fn mod_shl(self, bits: u8, m: &'a Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. The first Natural
is taken by value and the second by reference.
$f(x, n, m) = y$, where $x, y < m$ and $2^nx \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a> ModShl<u8, Natural> for &'a Natural
impl<'a> ModShl<u8, Natural> for &'a Natural
source§fn mod_shl(self, bits: u8, m: Natural) -> Natural
fn mod_shl(self, bits: u8, m: Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. The first Natural
is taken by reference and the second by value.
$f(x, n, m) = y$, where $x, y < m$ and $2^nx \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl ModShl<usize> for Natural
impl ModShl<usize> for Natural
source§fn mod_shl(self, bits: usize, m: Natural) -> Natural
fn mod_shl(self, bits: usize, m: Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. Both Natural
s are
taken by value.
$f(x, n, m) = y$, where $x, y < m$ and $2^nx \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a, 'b> ModShl<usize, &'b Natural> for &'a Natural
impl<'a, 'b> ModShl<usize, &'b Natural> for &'a Natural
source§fn mod_shl(self, bits: usize, m: &'b Natural) -> Natural
fn mod_shl(self, bits: usize, m: &'b Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. Both Natural
s are
taken by reference.
$f(x, n, m) = y$, where $x, y < m$ and $2^nx \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a> ModShl<usize, &'a Natural> for Natural
impl<'a> ModShl<usize, &'a Natural> for Natural
source§fn mod_shl(self, bits: usize, m: &'a Natural) -> Natural
fn mod_shl(self, bits: usize, m: &'a Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. The first Natural
is taken by value and the second by reference.
$f(x, n, m) = y$, where $x, y < m$ and $2^nx \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a> ModShl<usize, Natural> for &'a Natural
impl<'a> ModShl<usize, Natural> for &'a Natural
source§fn mod_shl(self, bits: usize, m: Natural) -> Natural
fn mod_shl(self, bits: usize, m: Natural) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. The first Natural
is taken by reference and the second by value.
$f(x, n, m) = y$, where $x, y < m$ and $2^nx \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl ModShlAssign<i128> for Natural
impl ModShlAssign<i128> for Natural
source§fn mod_shl_assign(&mut self, bits: i128, m: Natural)
fn mod_shl_assign(&mut self, bits: i128, m: Natural)
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$, in place. The first Natural
must be already reduced modulo $m$. The
Natural
on the right-hand side is taken by value.
$x \gets y$, where $x, y < m$ and $\lfloor 2^nx \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
source§impl<'a> ModShlAssign<i128, &'a Natural> for Natural
impl<'a> ModShlAssign<i128, &'a Natural> for Natural
source§fn mod_shl_assign(&mut self, bits: i128, m: &'a Natural)
fn mod_shl_assign(&mut self, bits: i128, m: &'a Natural)
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$, in place. The first Natural
must be already reduced modulo $m$. The
Natural
on the right-hand side is taken by reference.
$x \gets y$, where $x, y < m$ and $\lfloor 2^nx \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
source§impl ModShlAssign<i16> for Natural
impl ModShlAssign<i16> for Natural
source§fn mod_shl_assign(&mut self, bits: i16, m: Natural)
fn mod_shl_assign(&mut self, bits: i16, m: Natural)
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$, in place. The first Natural
must be already reduced modulo $m$. The
Natural
on the right-hand side is taken by value.
$x \gets y$, where $x, y < m$ and $\lfloor 2^nx \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
source§impl<'a> ModShlAssign<i16, &'a Natural> for Natural
impl<'a> ModShlAssign<i16, &'a Natural> for Natural
source§fn mod_shl_assign(&mut self, bits: i16, m: &'a Natural)
fn mod_shl_assign(&mut self, bits: i16, m: &'a Natural)
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$, in place. The first Natural
must be already reduced modulo $m$. The
Natural
on the right-hand side is taken by reference.
$x \gets y$, where $x, y < m$ and $\lfloor 2^nx \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
source§impl ModShlAssign<i32> for Natural
impl ModShlAssign<i32> for Natural
source§fn mod_shl_assign(&mut self, bits: i32, m: Natural)
fn mod_shl_assign(&mut self, bits: i32, m: Natural)
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$, in place. The first Natural
must be already reduced modulo $m$. The
Natural
on the right-hand side is taken by value.
$x \gets y$, where $x, y < m$ and $\lfloor 2^nx \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
source§impl<'a> ModShlAssign<i32, &'a Natural> for Natural
impl<'a> ModShlAssign<i32, &'a Natural> for Natural
source§fn mod_shl_assign(&mut self, bits: i32, m: &'a Natural)
fn mod_shl_assign(&mut self, bits: i32, m: &'a Natural)
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$, in place. The first Natural
must be already reduced modulo $m$. The
Natural
on the right-hand side is taken by reference.
$x \gets y$, where $x, y < m$ and $\lfloor 2^nx \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
source§impl ModShlAssign<i64> for Natural
impl ModShlAssign<i64> for Natural
source§fn mod_shl_assign(&mut self, bits: i64, m: Natural)
fn mod_shl_assign(&mut self, bits: i64, m: Natural)
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$, in place. The first Natural
must be already reduced modulo $m$. The
Natural
on the right-hand side is taken by value.
$x \gets y$, where $x, y < m$ and $\lfloor 2^nx \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
source§impl<'a> ModShlAssign<i64, &'a Natural> for Natural
impl<'a> ModShlAssign<i64, &'a Natural> for Natural
source§fn mod_shl_assign(&mut self, bits: i64, m: &'a Natural)
fn mod_shl_assign(&mut self, bits: i64, m: &'a Natural)
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$, in place. The first Natural
must be already reduced modulo $m$. The
Natural
on the right-hand side is taken by reference.
$x \gets y$, where $x, y < m$ and $\lfloor 2^nx \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
source§impl ModShlAssign<i8> for Natural
impl ModShlAssign<i8> for Natural
source§fn mod_shl_assign(&mut self, bits: i8, m: Natural)
fn mod_shl_assign(&mut self, bits: i8, m: Natural)
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$, in place. The first Natural
must be already reduced modulo $m$. The
Natural
on the right-hand side is taken by value.
$x \gets y$, where $x, y < m$ and $\lfloor 2^nx \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
source§impl<'a> ModShlAssign<i8, &'a Natural> for Natural
impl<'a> ModShlAssign<i8, &'a Natural> for Natural
source§fn mod_shl_assign(&mut self, bits: i8, m: &'a Natural)
fn mod_shl_assign(&mut self, bits: i8, m: &'a Natural)
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$, in place. The first Natural
must be already reduced modulo $m$. The
Natural
on the right-hand side is taken by reference.
$x \gets y$, where $x, y < m$ and $\lfloor 2^nx \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
source§impl ModShlAssign<isize> for Natural
impl ModShlAssign<isize> for Natural
source§fn mod_shl_assign(&mut self, bits: isize, m: Natural)
fn mod_shl_assign(&mut self, bits: isize, m: Natural)
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$, in place. The first Natural
must be already reduced modulo $m$. The
Natural
on the right-hand side is taken by value.
$x \gets y$, where $x, y < m$ and $\lfloor 2^nx \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
source§impl<'a> ModShlAssign<isize, &'a Natural> for Natural
impl<'a> ModShlAssign<isize, &'a Natural> for Natural
source§fn mod_shl_assign(&mut self, bits: isize, m: &'a Natural)
fn mod_shl_assign(&mut self, bits: isize, m: &'a Natural)
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$, in place. The first Natural
must be already reduced modulo $m$. The
Natural
on the right-hand side is taken by reference.
$x \gets y$, where $x, y < m$ and $\lfloor 2^nx \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
source§impl ModShlAssign<u128> for Natural
impl ModShlAssign<u128> for Natural
source§fn mod_shl_assign(&mut self, bits: u128, m: Natural)
fn mod_shl_assign(&mut self, bits: u128, m: Natural)
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$, in place. The first Natural
must be already reduced modulo $m$. The
Natural
on the right-hand side is taken by value.
$x \gets y$, where $x, y < m$ and $2^nx \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
source§impl<'a> ModShlAssign<u128, &'a Natural> for Natural
impl<'a> ModShlAssign<u128, &'a Natural> for Natural
source§fn mod_shl_assign(&mut self, bits: u128, m: &'a Natural)
fn mod_shl_assign(&mut self, bits: u128, m: &'a Natural)
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$, in place. The first Natural
must be already reduced modulo $m$. The
Natural
on the right-hand side is taken by reference.
$x \gets y$, where $x, y < m$ and $2^nx \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
source§impl ModShlAssign<u16> for Natural
impl ModShlAssign<u16> for Natural
source§fn mod_shl_assign(&mut self, bits: u16, m: Natural)
fn mod_shl_assign(&mut self, bits: u16, m: Natural)
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$, in place. The first Natural
must be already reduced modulo $m$. The
Natural
on the right-hand side is taken by value.
$x \gets y$, where $x, y < m$ and $2^nx \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
source§impl<'a> ModShlAssign<u16, &'a Natural> for Natural
impl<'a> ModShlAssign<u16, &'a Natural> for Natural
source§fn mod_shl_assign(&mut self, bits: u16, m: &'a Natural)
fn mod_shl_assign(&mut self, bits: u16, m: &'a Natural)
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$, in place. The first Natural
must be already reduced modulo $m$. The
Natural
on the right-hand side is taken by reference.
$x \gets y$, where $x, y < m$ and $2^nx \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
source§impl ModShlAssign<u32> for Natural
impl ModShlAssign<u32> for Natural
source§fn mod_shl_assign(&mut self, bits: u32, m: Natural)
fn mod_shl_assign(&mut self, bits: u32, m: Natural)
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$, in place. The first Natural
must be already reduced modulo $m$. The
Natural
on the right-hand side is taken by value.
$x \gets y$, where $x, y < m$ and $2^nx \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
source§impl<'a> ModShlAssign<u32, &'a Natural> for Natural
impl<'a> ModShlAssign<u32, &'a Natural> for Natural
source§fn mod_shl_assign(&mut self, bits: u32, m: &'a Natural)
fn mod_shl_assign(&mut self, bits: u32, m: &'a Natural)
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$, in place. The first Natural
must be already reduced modulo $m$. The
Natural
on the right-hand side is taken by reference.
$x \gets y$, where $x, y < m$ and $2^nx \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
source§impl ModShlAssign<u64> for Natural
impl ModShlAssign<u64> for Natural
source§fn mod_shl_assign(&mut self, bits: u64, m: Natural)
fn mod_shl_assign(&mut self, bits: u64, m: Natural)
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$, in place. The first Natural
must be already reduced modulo $m$. The
Natural
on the right-hand side is taken by value.
$x \gets y$, where $x, y < m$ and $2^nx \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
source§impl<'a> ModShlAssign<u64, &'a Natural> for Natural
impl<'a> ModShlAssign<u64, &'a Natural> for Natural
source§fn mod_shl_assign(&mut self, bits: u64, m: &'a Natural)
fn mod_shl_assign(&mut self, bits: u64, m: &'a Natural)
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$, in place. The first Natural
must be already reduced modulo $m$. The
Natural
on the right-hand side is taken by reference.
$x \gets y$, where $x, y < m$ and $2^nx \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
source§impl ModShlAssign<u8> for Natural
impl ModShlAssign<u8> for Natural
source§fn mod_shl_assign(&mut self, bits: u8, m: Natural)
fn mod_shl_assign(&mut self, bits: u8, m: Natural)
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$, in place. The first Natural
must be already reduced modulo $m$. The
Natural
on the right-hand side is taken by value.
$x \gets y$, where $x, y < m$ and $2^nx \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
source§impl<'a> ModShlAssign<u8, &'a Natural> for Natural
impl<'a> ModShlAssign<u8, &'a Natural> for Natural
source§fn mod_shl_assign(&mut self, bits: u8, m: &'a Natural)
fn mod_shl_assign(&mut self, bits: u8, m: &'a Natural)
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$, in place. The first Natural
must be already reduced modulo $m$. The
Natural
on the right-hand side is taken by reference.
$x \gets y$, where $x, y < m$ and $2^nx \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
source§impl ModShlAssign<usize> for Natural
impl ModShlAssign<usize> for Natural
source§fn mod_shl_assign(&mut self, bits: usize, m: Natural)
fn mod_shl_assign(&mut self, bits: usize, m: Natural)
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$, in place. The first Natural
must be already reduced modulo $m$. The
Natural
on the right-hand side is taken by value.
$x \gets y$, where $x, y < m$ and $2^nx \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
source§impl<'a> ModShlAssign<usize, &'a Natural> for Natural
impl<'a> ModShlAssign<usize, &'a Natural> for Natural
source§fn mod_shl_assign(&mut self, bits: usize, m: &'a Natural)
fn mod_shl_assign(&mut self, bits: usize, m: &'a Natural)
Left-shifts a Natural
(multiplies it by a power of 2) modulo another Natural
$m$, in place. The first Natural
must be already reduced modulo $m$. The
Natural
on the right-hand side is taken by reference.
$x \gets y$, where $x, y < m$ and $2^nx \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
source§impl ModShr<i128> for Natural
impl ModShr<i128> for Natural
source§fn mod_shr(self, bits: i128, m: Natural) -> Natural
fn mod_shr(self, bits: i128, m: Natural) -> Natural
Right-shifts a Natural
(divides it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. Both Natural
s are
taken by value.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a, 'b> ModShr<i128, &'b Natural> for &'a Natural
impl<'a, 'b> ModShr<i128, &'b Natural> for &'a Natural
source§fn mod_shr(self, bits: i128, m: &'b Natural) -> Natural
fn mod_shr(self, bits: i128, m: &'b Natural) -> Natural
Right-shifts a Natural
(divides it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. Both Natural
s are
taken by reference.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a> ModShr<i128, &'a Natural> for Natural
impl<'a> ModShr<i128, &'a Natural> for Natural
source§fn mod_shr(self, bits: i128, m: &'a Natural) -> Natural
fn mod_shr(self, bits: i128, m: &'a Natural) -> Natural
Right-shifts a Natural
(divides it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. The first Natural
is taken by value and the second by reference.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a> ModShr<i128, Natural> for &'a Natural
impl<'a> ModShr<i128, Natural> for &'a Natural
source§fn mod_shr(self, bits: i128, m: Natural) -> Natural
fn mod_shr(self, bits: i128, m: Natural) -> Natural
Right-shifts a Natural
(divides it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. The first Natural
is taken by reference and the second by value.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl ModShr<i16> for Natural
impl ModShr<i16> for Natural
source§fn mod_shr(self, bits: i16, m: Natural) -> Natural
fn mod_shr(self, bits: i16, m: Natural) -> Natural
Right-shifts a Natural
(divides it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. Both Natural
s are
taken by value.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a, 'b> ModShr<i16, &'b Natural> for &'a Natural
impl<'a, 'b> ModShr<i16, &'b Natural> for &'a Natural
source§fn mod_shr(self, bits: i16, m: &'b Natural) -> Natural
fn mod_shr(self, bits: i16, m: &'b Natural) -> Natural
Right-shifts a Natural
(divides it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. Both Natural
s are
taken by reference.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a> ModShr<i16, &'a Natural> for Natural
impl<'a> ModShr<i16, &'a Natural> for Natural
source§fn mod_shr(self, bits: i16, m: &'a Natural) -> Natural
fn mod_shr(self, bits: i16, m: &'a Natural) -> Natural
Right-shifts a Natural
(divides it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. The first Natural
is taken by value and the second by reference.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a> ModShr<i16, Natural> for &'a Natural
impl<'a> ModShr<i16, Natural> for &'a Natural
source§fn mod_shr(self, bits: i16, m: Natural) -> Natural
fn mod_shr(self, bits: i16, m: Natural) -> Natural
Right-shifts a Natural
(divides it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. The first Natural
is taken by reference and the second by value.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl ModShr<i32> for Natural
impl ModShr<i32> for Natural
source§fn mod_shr(self, bits: i32, m: Natural) -> Natural
fn mod_shr(self, bits: i32, m: Natural) -> Natural
Right-shifts a Natural
(divides it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. Both Natural
s are
taken by value.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a, 'b> ModShr<i32, &'b Natural> for &'a Natural
impl<'a, 'b> ModShr<i32, &'b Natural> for &'a Natural
source§fn mod_shr(self, bits: i32, m: &'b Natural) -> Natural
fn mod_shr(self, bits: i32, m: &'b Natural) -> Natural
Right-shifts a Natural
(divides it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. Both Natural
s are
taken by reference.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a> ModShr<i32, &'a Natural> for Natural
impl<'a> ModShr<i32, &'a Natural> for Natural
source§fn mod_shr(self, bits: i32, m: &'a Natural) -> Natural
fn mod_shr(self, bits: i32, m: &'a Natural) -> Natural
Right-shifts a Natural
(divides it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. The first Natural
is taken by value and the second by reference.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a> ModShr<i32, Natural> for &'a Natural
impl<'a> ModShr<i32, Natural> for &'a Natural
source§fn mod_shr(self, bits: i32, m: Natural) -> Natural
fn mod_shr(self, bits: i32, m: Natural) -> Natural
Right-shifts a Natural
(divides it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. The first Natural
is taken by reference and the second by value.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl ModShr<i64> for Natural
impl ModShr<i64> for Natural
source§fn mod_shr(self, bits: i64, m: Natural) -> Natural
fn mod_shr(self, bits: i64, m: Natural) -> Natural
Right-shifts a Natural
(divides it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. Both Natural
s are
taken by value.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a, 'b> ModShr<i64, &'b Natural> for &'a Natural
impl<'a, 'b> ModShr<i64, &'b Natural> for &'a Natural
source§fn mod_shr(self, bits: i64, m: &'b Natural) -> Natural
fn mod_shr(self, bits: i64, m: &'b Natural) -> Natural
Right-shifts a Natural
(divides it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. Both Natural
s are
taken by reference.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a> ModShr<i64, &'a Natural> for Natural
impl<'a> ModShr<i64, &'a Natural> for Natural
source§fn mod_shr(self, bits: i64, m: &'a Natural) -> Natural
fn mod_shr(self, bits: i64, m: &'a Natural) -> Natural
Right-shifts a Natural
(divides it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. The first Natural
is taken by value and the second by reference.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a> ModShr<i64, Natural> for &'a Natural
impl<'a> ModShr<i64, Natural> for &'a Natural
source§fn mod_shr(self, bits: i64, m: Natural) -> Natural
fn mod_shr(self, bits: i64, m: Natural) -> Natural
Right-shifts a Natural
(divides it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. The first Natural
is taken by reference and the second by value.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl ModShr<i8> for Natural
impl ModShr<i8> for Natural
source§fn mod_shr(self, bits: i8, m: Natural) -> Natural
fn mod_shr(self, bits: i8, m: Natural) -> Natural
Right-shifts a Natural
(divides it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. Both Natural
s are
taken by value.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a, 'b> ModShr<i8, &'b Natural> for &'a Natural
impl<'a, 'b> ModShr<i8, &'b Natural> for &'a Natural
source§fn mod_shr(self, bits: i8, m: &'b Natural) -> Natural
fn mod_shr(self, bits: i8, m: &'b Natural) -> Natural
Right-shifts a Natural
(divides it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. Both Natural
s are
taken by reference.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a> ModShr<i8, &'a Natural> for Natural
impl<'a> ModShr<i8, &'a Natural> for Natural
source§fn mod_shr(self, bits: i8, m: &'a Natural) -> Natural
fn mod_shr(self, bits: i8, m: &'a Natural) -> Natural
Right-shifts a Natural
(divides it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. The first Natural
is taken by value and the second by reference.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a> ModShr<i8, Natural> for &'a Natural
impl<'a> ModShr<i8, Natural> for &'a Natural
source§fn mod_shr(self, bits: i8, m: Natural) -> Natural
fn mod_shr(self, bits: i8, m: Natural) -> Natural
Right-shifts a Natural
(divides it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. The first Natural
is taken by reference and the second by value.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl ModShr<isize> for Natural
impl ModShr<isize> for Natural
source§fn mod_shr(self, bits: isize, m: Natural) -> Natural
fn mod_shr(self, bits: isize, m: Natural) -> Natural
Right-shifts a Natural
(divides it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. Both Natural
s are
taken by value.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a, 'b> ModShr<isize, &'b Natural> for &'a Natural
impl<'a, 'b> ModShr<isize, &'b Natural> for &'a Natural
source§fn mod_shr(self, bits: isize, m: &'b Natural) -> Natural
fn mod_shr(self, bits: isize, m: &'b Natural) -> Natural
Right-shifts a Natural
(divides it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. Both Natural
s are
taken by reference.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a> ModShr<isize, &'a Natural> for Natural
impl<'a> ModShr<isize, &'a Natural> for Natural
source§fn mod_shr(self, bits: isize, m: &'a Natural) -> Natural
fn mod_shr(self, bits: isize, m: &'a Natural) -> Natural
Right-shifts a Natural
(divides it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. The first Natural
is taken by value and the second by reference.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl<'a> ModShr<isize, Natural> for &'a Natural
impl<'a> ModShr<isize, Natural> for &'a Natural
source§fn mod_shr(self, bits: isize, m: Natural) -> Natural
fn mod_shr(self, bits: isize, m: Natural) -> Natural
Right-shifts a Natural
(divides it by a power of 2) modulo another Natural
$m$. The first Natural
must be already reduced modulo $m$. The first Natural
is taken by reference and the second by value.
$f(x, n, m) = y$, where $x, y < m$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
type Output = Natural
source§impl ModShrAssign<i128> for Natural
impl ModShrAssign<i128> for Natural
source§fn mod_shr_assign(&mut self, bits: i128, m: Natural)
fn mod_shr_assign(&mut self, bits: i128, m: Natural)
Right-shifts a Natural
(divides it by a power of 2) modulo another Natural
$m$, in place. The first Natural
must be already reduced modulo $m$. The
Natural
on the right-hand side is taken by value.
$x \gets y$, where $x, y < m$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
source§impl<'a> ModShrAssign<i128, &'a Natural> for Natural
impl<'a> ModShrAssign<i128, &'a Natural> for Natural
source§fn mod_shr_assign(&mut self, bits: i128, m: &'a Natural)
fn mod_shr_assign(&mut self, bits: i128, m: &'a Natural)
Right-shifts a Natural
(divides it by a power of 2) modulo another Natural
$m$, in place. The first Natural
must be already reduced modulo $m$. The
Natural
on the right-hand side is taken by reference.
$x \gets y$, where $x, y < m$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
source§impl ModShrAssign<i16> for Natural
impl ModShrAssign<i16> for Natural
source§fn mod_shr_assign(&mut self, bits: i16, m: Natural)
fn mod_shr_assign(&mut self, bits: i16, m: Natural)
Right-shifts a Natural
(divides it by a power of 2) modulo another Natural
$m$, in place. The first Natural
must be already reduced modulo $m$. The
Natural
on the right-hand side is taken by value.
$x \gets y$, where $x, y < m$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
source§impl<'a> ModShrAssign<i16, &'a Natural> for Natural
impl<'a> ModShrAssign<i16, &'a Natural> for Natural
source§fn mod_shr_assign(&mut self, bits: i16, m: &'a Natural)
fn mod_shr_assign(&mut self, bits: i16, m: &'a Natural)
Right-shifts a Natural
(divides it by a power of 2) modulo another Natural
$m$, in place. The first Natural
must be already reduced modulo $m$. The
Natural
on the right-hand side is taken by reference.
$x \gets y$, where $x, y < m$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
source§impl ModShrAssign<i32> for Natural
impl ModShrAssign<i32> for Natural
source§fn mod_shr_assign(&mut self, bits: i32, m: Natural)
fn mod_shr_assign(&mut self, bits: i32, m: Natural)
Right-shifts a Natural
(divides it by a power of 2) modulo another Natural
$m$, in place. The first Natural
must be already reduced modulo $m$. The
Natural
on the right-hand side is taken by value.
$x \gets y$, where $x, y < m$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
source§impl<'a> ModShrAssign<i32, &'a Natural> for Natural
impl<'a> ModShrAssign<i32, &'a Natural> for Natural
source§fn mod_shr_assign(&mut self, bits: i32, m: &'a Natural)
fn mod_shr_assign(&mut self, bits: i32, m: &'a Natural)
Right-shifts a Natural
(divides it by a power of 2) modulo another Natural
$m$, in place. The first Natural
must be already reduced modulo $m$. The
Natural
on the right-hand side is taken by reference.
$x \gets y$, where $x, y < m$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
source§impl ModShrAssign<i64> for Natural
impl ModShrAssign<i64> for Natural
source§fn mod_shr_assign(&mut self, bits: i64, m: Natural)
fn mod_shr_assign(&mut self, bits: i64, m: Natural)
Right-shifts a Natural
(divides it by a power of 2) modulo another Natural
$m$, in place. The first Natural
must be already reduced modulo $m$. The
Natural
on the right-hand side is taken by value.
$x \gets y$, where $x, y < m$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
source§impl<'a> ModShrAssign<i64, &'a Natural> for Natural
impl<'a> ModShrAssign<i64, &'a Natural> for Natural
source§fn mod_shr_assign(&mut self, bits: i64, m: &'a Natural)
fn mod_shr_assign(&mut self, bits: i64, m: &'a Natural)
Right-shifts a Natural
(divides it by a power of 2) modulo another Natural
$m$, in place. The first Natural
must be already reduced modulo $m$. The
Natural
on the right-hand side is taken by reference.
$x \gets y$, where $x, y < m$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
source§impl ModShrAssign<i8> for Natural
impl ModShrAssign<i8> for Natural
source§fn mod_shr_assign(&mut self, bits: i8, m: Natural)
fn mod_shr_assign(&mut self, bits: i8, m: Natural)
Right-shifts a Natural
(divides it by a power of 2) modulo another Natural
$m$, in place. The first Natural
must be already reduced modulo $m$. The
Natural
on the right-hand side is taken by value.
$x \gets y$, where $x, y < m$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
source§impl<'a> ModShrAssign<i8, &'a Natural> for Natural
impl<'a> ModShrAssign<i8, &'a Natural> for Natural
source§fn mod_shr_assign(&mut self, bits: i8, m: &'a Natural)
fn mod_shr_assign(&mut self, bits: i8, m: &'a Natural)
Right-shifts a Natural
(divides it by a power of 2) modulo another Natural
$m$, in place. The first Natural
must be already reduced modulo $m$. The
Natural
on the right-hand side is taken by reference.
$x \gets y$, where $x, y < m$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
source§impl ModShrAssign<isize> for Natural
impl ModShrAssign<isize> for Natural
source§fn mod_shr_assign(&mut self, bits: isize, m: Natural)
fn mod_shr_assign(&mut self, bits: isize, m: Natural)
Right-shifts a Natural
(divides it by a power of 2) modulo another Natural
$m$, in place. The first Natural
must be already reduced modulo $m$. The
Natural
on the right-hand side is taken by value.
$x \gets y$, where $x, y < m$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
source§impl<'a> ModShrAssign<isize, &'a Natural> for Natural
impl<'a> ModShrAssign<isize, &'a Natural> for Natural
source§fn mod_shr_assign(&mut self, bits: isize, m: &'a Natural)
fn mod_shr_assign(&mut self, bits: isize, m: &'a Natural)
Right-shifts a Natural
(divides it by a power of 2) modulo another Natural
$m$, in place. The first Natural
must be already reduced modulo $m$. The
Natural
on the right-hand side is taken by reference.
$x \gets y$, where $x, y < m$ and $\lfloor 2^{-n}x \rfloor \equiv y \mod m$.
§Worst-case complexity
$T(n, m) = O(mn \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is m.significant_bits()
, and $m$
is bits
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
See here.
source§impl<'a, 'b> ModSquare<&'b Natural> for &'a Natural
impl<'a, 'b> ModSquare<&'b Natural> for &'a Natural
source§fn mod_square(self, m: &'b Natural) -> Natural
fn mod_square(self, m: &'b Natural) -> Natural
Squares a Natural
modulo another Natural
$m$. The input must be already reduced
modulo $m$. Both Natural
s are taken by reference.
$f(x, m) = y$, where $x, y < m$ and $x^2 \equiv y \mod m$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModSquare;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::from(2u32)).mod_square(&Natural::from(10u32)), 4);
assert_eq!((&Natural::from(100u32)).mod_square(&Natural::from(497u32)), 60);
type Output = Natural
source§impl<'a> ModSquare<&'a Natural> for Natural
impl<'a> ModSquare<&'a Natural> for Natural
source§fn mod_square(self, m: &'a Natural) -> Natural
fn mod_square(self, m: &'a Natural) -> Natural
Squares a Natural
modulo another Natural
$m$. The input must be already reduced
modulo $m$. The first Natural
is taken by value and the second by reference.
$f(x, m) = y$, where $x, y < m$ and $x^2 \equiv y \mod m$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModSquare;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(2u32).mod_square(&Natural::from(10u32)), 4);
assert_eq!(Natural::from(100u32).mod_square(&Natural::from(497u32)), 60);
type Output = Natural
source§impl<'a> ModSquare<Natural> for &'a Natural
impl<'a> ModSquare<Natural> for &'a Natural
source§fn mod_square(self, m: Natural) -> Natural
fn mod_square(self, m: Natural) -> Natural
Squares a Natural
modulo another Natural
$m$. The input must be already reduced
modulo $m$. The first Natural
is taken by reference and the second by value.
$f(x, m) = y$, where $x, y < m$ and $x^2 \equiv y \mod m$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModSquare;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::from(2u32)).mod_square(Natural::from(10u32)), 4);
assert_eq!((&Natural::from(100u32)).mod_square(Natural::from(497u32)), 60);
type Output = Natural
source§impl ModSquare for Natural
impl ModSquare for Natural
source§fn mod_square(self, m: Natural) -> Natural
fn mod_square(self, m: Natural) -> Natural
Squares a Natural
modulo another Natural
$m$. The input must be already reduced
modulo $m$. Both Natural
s are taken by value.
$f(x, m) = y$, where $x, y < m$ and $x^2 \equiv y \mod m$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModSquare;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(2u32).mod_square(Natural::from(10u32)), 4);
assert_eq!(Natural::from(100u32).mod_square(Natural::from(497u32)), 60);
type Output = Natural
source§impl<'a> ModSquareAssign<&'a Natural> for Natural
impl<'a> ModSquareAssign<&'a Natural> for Natural
source§fn mod_square_assign(&mut self, m: &'a Natural)
fn mod_square_assign(&mut self, m: &'a Natural)
Squares a Natural
modulo another Natural
$m$, in place. The input must be already
reduced modulo $m$. The Natural
on the right-hand side is taken by reference.
$x \gets y$, where $x, y < m$ and $x^2 \equiv y \mod m$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModSquareAssign;
use malachite_nz::natural::Natural;
let mut x = Natural::from(2u32);
x.mod_square_assign(&Natural::from(10u32));
assert_eq!(x, 4);
let mut x = Natural::from(100u32);
x.mod_square_assign(&Natural::from(497u32));
assert_eq!(x, 60);
source§impl ModSquareAssign for Natural
impl ModSquareAssign for Natural
source§fn mod_square_assign(&mut self, m: Natural)
fn mod_square_assign(&mut self, m: Natural)
Squares a Natural
modulo another Natural
$m$, in place. The input must be already
reduced modulo $m$. The Natural
on the right-hand side is taken by value.
$x \gets y$, where $x, y < m$ and $x^2 \equiv y \mod m$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
is greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModSquareAssign;
use malachite_nz::natural::Natural;
let mut x = Natural::from(2u32);
x.mod_square_assign(Natural::from(10u32));
assert_eq!(x, 4);
let mut x = Natural::from(100u32);
x.mod_square_assign(Natural::from(497u32));
assert_eq!(x, 60);
source§impl<'a> ModSub<&'a Natural> for Natural
impl<'a> ModSub<&'a Natural> for Natural
source§fn mod_sub(self, other: &'a Natural, m: Natural) -> Natural
fn mod_sub(self, other: &'a Natural, m: Natural) -> Natural
Subtracts two Natural
s modulo a third Natural
$m$. The inputs must be already
reduced modulo $m$. The first and third Natural
s are taken by value and the second by
reference.
$f(x, y, m) = z$, where $x, y, z < m$ and $x - y \equiv z \mod m$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModSub;
use malachite_nz::natural::Natural;
assert_eq!(
Natural::from(4u32).mod_sub(&Natural::from(3u32), Natural::from(5u32)).to_string(),
"1"
);
assert_eq!(
Natural::from(7u32).mod_sub(&Natural::from(9u32), Natural::from(10u32)).to_string(),
"8"
);
This isequivalent to _fmpz_mod_subN
from fmpz_mod/sub.c
, FLINT 2.7.1, where b
and m
are taken by value and c
is taken by reference.
type Output = Natural
source§impl<'a, 'b, 'c> ModSub<&'b Natural, &'c Natural> for &'a Natural
impl<'a, 'b, 'c> ModSub<&'b Natural, &'c Natural> for &'a Natural
source§fn mod_sub(self, other: &'b Natural, m: &'c Natural) -> Natural
fn mod_sub(self, other: &'b Natural, m: &'c Natural) -> Natural
Subtracts two Natural
s modulo a third Natural
$m$. The inputs must be already
reduced modulo $m$. All three Natural
s are taken by reference.
$f(x, y, m) = z$, where $x, y, z < m$ and $x - y \equiv z \mod m$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModSub;
use malachite_nz::natural::Natural;
assert_eq!(
(&Natural::from(4u32)).mod_sub(&Natural::from(3u32), &Natural::from(5u32)).to_string(),
"1"
);
assert_eq!(
(&Natural::from(7u32)).mod_sub(&Natural::from(9u32), &Natural::from(10u32)).to_string(),
"8"
);
This is equivalent to _fmpz_mod_subN
from fmpz_mod/sub.c
, FLINT 2.7.1, where b
, c
,
and m
are taken by reference.
type Output = Natural
source§impl<'a, 'b> ModSub<&'a Natural, &'b Natural> for Natural
impl<'a, 'b> ModSub<&'a Natural, &'b Natural> for Natural
source§fn mod_sub(self, other: &'a Natural, m: &'b Natural) -> Natural
fn mod_sub(self, other: &'a Natural, m: &'b Natural) -> Natural
Subtracts two Natural
s modulo a third Natural
$m$. The inputs must be already
reduced modulo $m$. The first Natural
is taken by value and the second and third by
reference.
$f(x, y, m) = z$, where $x, y, z < m$ and $x - y \equiv z \mod m$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModSub;
use malachite_nz::natural::Natural;
assert_eq!(
Natural::from(4u32).mod_sub(&Natural::from(3u32), &Natural::from(5u32)).to_string(),
"1"
);
assert_eq!(
Natural::from(7u32).mod_sub(&Natural::from(9u32), &Natural::from(10u32)).to_string(),
"8"
);
This is equivalent to _fmpz_mod_subN
from fmpz_mod/sub.c
, FLINT 2.7.1, where b
is
taken by value and c
and m
are taken by reference.
type Output = Natural
source§impl<'a, 'b> ModSub<&'b Natural, Natural> for &'a Natural
impl<'a, 'b> ModSub<&'b Natural, Natural> for &'a Natural
source§fn mod_sub(self, other: &'b Natural, m: Natural) -> Natural
fn mod_sub(self, other: &'b Natural, m: Natural) -> Natural
Subtracts two Natural
s modulo a third Natural
$m$. The inputs must be already
reduced modulo $m$. The first two Natural
s are taken by reference and the third by
value.
$f(x, y, m) = z$, where $x, y, z < m$ and $x - y \equiv z \mod m$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModSub;
use malachite_nz::natural::Natural;
assert_eq!(
(&Natural::from(4u32)).mod_sub(&Natural::from(3u32), Natural::from(5u32)).to_string(),
"1"
);
assert_eq!(
(&Natural::from(7u32)).mod_sub(&Natural::from(9u32), Natural::from(10u32)).to_string(),
"8"
);
This is equivalent to _fmpz_mod_subN
from fmpz_mod/sub.c
, FLINT 2.7.1, where b
and c
are taken by reference and m
is taken by value.
type Output = Natural
source§impl<'a, 'b> ModSub<Natural, &'b Natural> for &'a Natural
impl<'a, 'b> ModSub<Natural, &'b Natural> for &'a Natural
source§fn mod_sub(self, other: Natural, m: &'b Natural) -> Natural
fn mod_sub(self, other: Natural, m: &'b Natural) -> Natural
Subtracts two Natural
s modulo a third Natural
$m$. The inputs must be already
reduced modulo $m$. The first and third Natural
s are taken by reference and the second
by value.
$f(x, y, m) = z$, where $x, y, z < m$ and $x - y \equiv z \mod m$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModSub;
use malachite_nz::natural::Natural;
assert_eq!(
(&Natural::from(4u32)).mod_sub(Natural::from(3u32), &Natural::from(5u32)).to_string(),
"1"
);
assert_eq!(
(&Natural::from(7u32)).mod_sub(Natural::from(9u32), &Natural::from(10u32)).to_string(),
"8"
);
This is equivalent to _fmpz_mod_subN
from fmpz_mod/sub.c
, FLINT 2.7.1, where b
and m
are taken by reference and c
is taken by value.
type Output = Natural
source§impl<'a> ModSub<Natural, &'a Natural> for Natural
impl<'a> ModSub<Natural, &'a Natural> for Natural
source§fn mod_sub(self, other: Natural, m: &'a Natural) -> Natural
fn mod_sub(self, other: Natural, m: &'a Natural) -> Natural
Subtracts two Natural
s modulo a third Natural
$m$. The inputs must be already
reduced modulo $m$. The first two Natural
s are taken by value and the third by
reference.
$f(x, y, m) = z$, where $x, y, z < m$ and $x - y \equiv z \mod m$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModSub;
use malachite_nz::natural::Natural;
assert_eq!(
Natural::from(4u32).mod_sub(Natural::from(3u32), &Natural::from(5u32)).to_string(),
"1"
);
assert_eq!(
Natural::from(7u32).mod_sub(Natural::from(9u32), &Natural::from(10u32)).to_string(),
"8"
);
This is equivalent to _fmpz_mod_subN
from fmpz_mod/sub.c
, FLINT 2.7.1, where b
and c
are taken by value and m
is taken by reference.
type Output = Natural
source§impl<'a> ModSub<Natural, Natural> for &'a Natural
impl<'a> ModSub<Natural, Natural> for &'a Natural
source§fn mod_sub(self, other: Natural, m: Natural) -> Natural
fn mod_sub(self, other: Natural, m: Natural) -> Natural
Subtracts two Natural
s modulo a third Natural
$m$. The inputs must be already
reduced modulo $m$. The first Natural
is taken by reference and the second and third by
value.
$f(x, y, m) = z$, where $x, y, z < m$ and $x - y \equiv z \mod m$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModSub;
use malachite_nz::natural::Natural;
assert_eq!(
(&Natural::from(4u32)).mod_sub(Natural::from(3u32), Natural::from(5u32)).to_string(),
"1"
);
assert_eq!(
(&Natural::from(7u32)).mod_sub(Natural::from(9u32), Natural::from(10u32)).to_string(),
"8"
);
This is equivalent to _fmpz_mod_subN
from fmpz_mod/sub.c
, FLINT 2.7.1, where b
is
taken by reference and c
and m
are taken by value.
type Output = Natural
source§impl ModSub for Natural
impl ModSub for Natural
source§fn mod_sub(self, other: Natural, m: Natural) -> Natural
fn mod_sub(self, other: Natural, m: Natural) -> Natural
Subtracts two Natural
s modulo a third Natural
$m$. The inputs must be already
reduced modulo $m$. All three Natural
s are taken by value.
$f(x, y, m) = z$, where $x, y, z < m$ and $x - y \equiv z \mod m$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModSub;
use malachite_nz::natural::Natural;
assert_eq!(
Natural::from(4u32).mod_sub(Natural::from(3u32), Natural::from(5u32)).to_string(),
"1"
);
assert_eq!(
Natural::from(7u32).mod_sub(Natural::from(9u32), Natural::from(10u32)).to_string(),
"8"
);
This is equivalent to _fmpz_mod_subN
from fmpz_mod/sub.c
, FLINT 2.7.1, where b
, c
,
and m
are taken by value.
type Output = Natural
source§impl<'a> ModSubAssign<&'a Natural> for Natural
impl<'a> ModSubAssign<&'a Natural> for Natural
source§fn mod_sub_assign(&mut self, other: &'a Natural, m: Natural)
fn mod_sub_assign(&mut self, other: &'a Natural, m: Natural)
Subtracts two Natural
s modulo a third Natural
$m$, in place. The inputs must be
already reduced modulo $m$. The first Natural
on the right-hand side is taken by
reference and the second by value.
$x \gets z$, where $x, y, z < m$ and $x - y \equiv z \mod m$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModSubAssign;
use malachite_nz::natural::Natural;
let mut x = Natural::from(4u32);
x.mod_sub_assign(&Natural::from(3u32), Natural::from(5u32));
assert_eq!(x.to_string(), "1");
let mut x = Natural::from(7u32);
x.mod_sub_assign(&Natural::from(9u32), Natural::from(10u32));
assert_eq!(x.to_string(), "8");
This is equivalent to _fmpz_mod_subN
from fmpz_mod/sub.c
, FLINT 2.7.1, where b
and m
are taken by value, c
is taken by reference, and a == b
.
source§impl<'a, 'b> ModSubAssign<&'a Natural, &'b Natural> for Natural
impl<'a, 'b> ModSubAssign<&'a Natural, &'b Natural> for Natural
source§fn mod_sub_assign(&mut self, other: &'a Natural, m: &'b Natural)
fn mod_sub_assign(&mut self, other: &'a Natural, m: &'b Natural)
Subtracts two Natural
s modulo a third Natural
$m$, in place. The inputs must be
already reduced modulo $m$. Both Natural
s on the right-hand side are taken by reference.
$x \gets z$, where $x, y, z < m$ and $x - y \equiv z \mod m$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModSubAssign;
use malachite_nz::natural::Natural;
let mut x = Natural::from(4u32);
x.mod_sub_assign(&Natural::from(3u32), &Natural::from(5u32));
assert_eq!(x.to_string(), "1");
let mut x = Natural::from(7u32);
x.mod_sub_assign(&Natural::from(9u32), &Natural::from(10u32));
assert_eq!(x.to_string(), "8");
This is equivalent to _fmpz_mod_subN
from fmpz_mod/sub.c
, FLINT 2.7.1, where b
is
taken by value, c
and m
are taken by reference, and a == b
.
source§impl<'a> ModSubAssign<Natural, &'a Natural> for Natural
impl<'a> ModSubAssign<Natural, &'a Natural> for Natural
source§fn mod_sub_assign(&mut self, other: Natural, m: &'a Natural)
fn mod_sub_assign(&mut self, other: Natural, m: &'a Natural)
Subtracts two Natural
s modulo a third Natural
$m$, in place. The inputs must be
already reduced modulo $m$. The first Natural
on the right-hand side is taken by value
and the second by reference.
$x \gets z$, where $x, y, z < m$ and $x - y \equiv z \mod m$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModSubAssign;
use malachite_nz::natural::Natural;
let mut x = Natural::from(4u32);
x.mod_sub_assign(Natural::from(3u32), &Natural::from(5u32));
assert_eq!(x.to_string(), "1");
let mut x = Natural::from(7u32);
x.mod_sub_assign(Natural::from(9u32), &Natural::from(10u32));
assert_eq!(x.to_string(), "8");
This is equivalent to _fmpz_mod_subN
from fmpz_mod/sub.c
, FLINT 2.7.1, where b
and c
are taken by value, m
is taken by reference, and a == b
.
source§impl ModSubAssign for Natural
impl ModSubAssign for Natural
source§fn mod_sub_assign(&mut self, other: Natural, m: Natural)
fn mod_sub_assign(&mut self, other: Natural, m: Natural)
Subtracts two Natural
s modulo a third Natural
$m$, in place. The inputs must be
already reduced modulo $m$. Both Natural
s on the right-hand side are taken by value.
$x \gets z$, where $x, y, z < m$ and $x - y \equiv z \mod m$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is m.significant_bits()
.
§Panics
Panics if self
or other
are greater than or equal to m
.
§Examples
use malachite_base::num::arithmetic::traits::ModSubAssign;
use malachite_nz::natural::Natural;
let mut x = Natural::from(4u32);
x.mod_sub_assign(Natural::from(3u32), Natural::from(5u32));
assert_eq!(x.to_string(), "1");
let mut x = Natural::from(7u32);
x.mod_sub_assign(Natural::from(9u32), Natural::from(10u32));
assert_eq!(x.to_string(), "8");
This is equivalent to _fmpz_mod_subN
from fmpz_mod/sub.c
, FLINT 2.7.1, where b
, c
,
and m
are taken by value and a == b
.
source§impl<'a, 'b> Mul<&'a Natural> for &'b Natural
impl<'a, 'b> Mul<&'a Natural> for &'b Natural
source§fn mul(self, other: &'a Natural) -> Natural
fn mul(self, other: &'a Natural) -> Natural
Multiplies two Natural
s, taking both by reference.
$$ f(x, y) = xy. $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{One, Zero};
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!(&Natural::ONE * &Natural::from(123u32), 123);
assert_eq!(&Natural::from(123u32) * &Natural::ZERO, 0);
assert_eq!(&Natural::from(123u32) * &Natural::from(456u32), 56088);
assert_eq!(
(&Natural::from_str("123456789000").unwrap() * &Natural::from_str("987654321000")
.unwrap()).to_string(),
"121932631112635269000000"
);
source§impl<'a> Mul<&'a Natural> for Natural
impl<'a> Mul<&'a Natural> for Natural
source§fn mul(self, other: &'a Natural) -> Natural
fn mul(self, other: &'a Natural) -> Natural
Multiplies two Natural
s, taking the first by value and the second by reference.
$$ f(x, y) = xy. $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{One, Zero};
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!(Natural::ONE * &Natural::from(123u32), 123);
assert_eq!(Natural::from(123u32) * &Natural::ZERO, 0);
assert_eq!(Natural::from(123u32) * &Natural::from(456u32), 56088);
assert_eq!(
(Natural::from_str("123456789000").unwrap() * &Natural::from_str("987654321000")
.unwrap()).to_string(),
"121932631112635269000000"
);
source§impl<'a> Mul<Natural> for &'a Natural
impl<'a> Mul<Natural> for &'a Natural
source§fn mul(self, other: Natural) -> Natural
fn mul(self, other: Natural) -> Natural
Multiplies two Natural
s, taking the first by reference and the second by value.
$$ f(x, y) = xy. $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{One, Zero};
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!(&Natural::ONE * Natural::from(123u32), 123);
assert_eq!(&Natural::from(123u32) * Natural::ZERO, 0);
assert_eq!(&Natural::from(123u32) * Natural::from(456u32), 56088);
assert_eq!(
(&Natural::from_str("123456789000").unwrap() * Natural::from_str("987654321000")
.unwrap()).to_string(),
"121932631112635269000000"
);
source§impl Mul for Natural
impl Mul for Natural
source§fn mul(self, other: Natural) -> Natural
fn mul(self, other: Natural) -> Natural
Multiplies two Natural
s, taking both by value.
$$ f(x, y) = xy. $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::{One, Zero};
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!(Natural::ONE * Natural::from(123u32), 123);
assert_eq!(Natural::from(123u32) * Natural::ZERO, 0);
assert_eq!(Natural::from(123u32) * Natural::from(456u32), 56088);
assert_eq!(
(Natural::from_str("123456789000").unwrap() * Natural::from_str("987654321000")
.unwrap()).to_string(),
"121932631112635269000000"
);
source§impl<'a> MulAssign<&'a Natural> for Natural
impl<'a> MulAssign<&'a Natural> for Natural
source§fn mul_assign(&mut self, other: &'a Natural)
fn mul_assign(&mut self, other: &'a Natural)
Multiplies a Natural
by a Natural
in place, taking the Natural
on the right-hand
side by reference.
$$ x \gets = xy. $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::One;
use malachite_nz::natural::Natural;
use core::str::FromStr;
let mut x = Natural::ONE;
x *= &Natural::from_str("1000").unwrap();
x *= &Natural::from_str("2000").unwrap();
x *= &Natural::from_str("3000").unwrap();
x *= &Natural::from_str("4000").unwrap();
assert_eq!(x.to_string(), "24000000000000");
source§impl MulAssign for Natural
impl MulAssign for Natural
source§fn mul_assign(&mut self, other: Natural)
fn mul_assign(&mut self, other: Natural)
Multiplies a Natural
by a Natural
in place, taking the Natural
on the right-hand
side by value.
$$ x \gets = xy. $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::basic::traits::One;
use malachite_nz::natural::Natural;
use core::str::FromStr;
let mut x = Natural::ONE;
x *= Natural::from_str("1000").unwrap();
x *= Natural::from_str("2000").unwrap();
x *= Natural::from_str("3000").unwrap();
x *= Natural::from_str("4000").unwrap();
assert_eq!(x.to_string(), "24000000000000");
source§impl Multifactorial for Natural
impl Multifactorial for Natural
source§fn multifactorial(n: u64, m: u64) -> Natural
fn multifactorial(n: u64, m: u64) -> Natural
Computes a multifactorial of a number.
$$ f(n, m) = n!^{(m)} = n \times (n - m) \times (n - 2m) \times \cdots \times i. $$ If $n$ is divisible by $m$, then $i$ is $m$; otherwise, $i$ is the remainder when $n$ is divided by $m$.
$n!^{(m)} = O(\sqrt{n}(n/e)^{n/m})$.
§Worst-case complexity
$T(n, m) = O(n (\log n)^2 \log\log n)$
$M(n, m) = O(n \log n)$
§Examples
use malachite_base::num::arithmetic::traits::Multifactorial;
use malachite_nz::natural::Natural;
assert_eq!(Natural::multifactorial(0, 1), 1);
assert_eq!(Natural::multifactorial(1, 1), 1);
assert_eq!(Natural::multifactorial(2, 1), 2);
assert_eq!(Natural::multifactorial(3, 1), 6);
assert_eq!(Natural::multifactorial(4, 1), 24);
assert_eq!(Natural::multifactorial(5, 1), 120);
assert_eq!(Natural::multifactorial(0, 2), 1);
assert_eq!(Natural::multifactorial(1, 2), 1);
assert_eq!(Natural::multifactorial(2, 2), 2);
assert_eq!(Natural::multifactorial(3, 2), 3);
assert_eq!(Natural::multifactorial(4, 2), 8);
assert_eq!(Natural::multifactorial(5, 2), 15);
assert_eq!(Natural::multifactorial(6, 2), 48);
assert_eq!(Natural::multifactorial(7, 2), 105);
assert_eq!(Natural::multifactorial(0, 3), 1);
assert_eq!(Natural::multifactorial(1, 3), 1);
assert_eq!(Natural::multifactorial(2, 3), 2);
assert_eq!(Natural::multifactorial(3, 3), 3);
assert_eq!(Natural::multifactorial(4, 3), 4);
assert_eq!(Natural::multifactorial(5, 3), 10);
assert_eq!(Natural::multifactorial(6, 3), 18);
assert_eq!(Natural::multifactorial(7, 3), 28);
assert_eq!(Natural::multifactorial(8, 3), 80);
assert_eq!(Natural::multifactorial(9, 3), 162);
assert_eq!(
Natural::multifactorial(100, 3).to_string(),
"174548867015437739741494347897360069928419328000000000"
);
source§impl<'a> Neg for &'a Natural
impl<'a> Neg for &'a Natural
source§fn neg(self) -> Integer
fn neg(self) -> Integer
Negates a Natural
, taking it by reference and returning an Integer
.
$$ f(x) = -x. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!(-&Natural::ZERO, 0);
assert_eq!(-&Natural::from(123u32), -123);
source§impl Neg for Natural
impl Neg for Natural
source§fn neg(self) -> Integer
fn neg(self) -> Integer
Negates a Natural
, taking it by value and returning an Integer
.
$$ f(x) = -x. $$
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!(-Natural::ZERO, 0);
assert_eq!(-Natural::from(123u32), -123);
source§impl<'a, 'b> NegMod<&'b Natural> for &'a Natural
impl<'a, 'b> NegMod<&'b Natural> for &'a Natural
source§fn neg_mod(self, other: &'b Natural) -> Natural
fn neg_mod(self, other: &'b Natural) -> Natural
Divides the negative of a Natural
by another Natural
, taking both by reference and
returning just the remainder.
If the quotient were computed, the quotient and remainder would satisfy $x = qy - r$ and $0 \leq r < y$.
$$ f(x, y) = y\left \lceil \frac{x}{y} \right \rceil - x. $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_base::num::arithmetic::traits::NegMod;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 3 * 10 - 7 = 23
assert_eq!((&Natural::from(23u32)).neg_mod(&Natural::from(10u32)), 7);
// 810000006724 * 1234567890987 - 704498996588 = 1000000000000000000000000
assert_eq!(
(&Natural::from_str("1000000000000000000000000").unwrap())
.neg_mod(&Natural::from_str("1234567890987").unwrap()),
704498996588u64
);
type Output = Natural
source§impl<'a> NegMod<&'a Natural> for Natural
impl<'a> NegMod<&'a Natural> for Natural
source§fn neg_mod(self, other: &'a Natural) -> Natural
fn neg_mod(self, other: &'a Natural) -> Natural
Divides the negative of a Natural
by another Natural
, taking the first by value and
the second by reference and returning just the remainder.
If the quotient were computed, the quotient and remainder would satisfy $x = qy - r$ and $0 \leq r < y$.
$$ f(x, y) = y\left \lceil \frac{x}{y} \right \rceil - x. $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_base::num::arithmetic::traits::NegMod;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 3 * 10 - 7 = 23
assert_eq!(Natural::from(23u32).neg_mod(&Natural::from(10u32)), 7);
// 810000006724 * 1234567890987 - 704498996588 = 1000000000000000000000000
assert_eq!(
Natural::from_str("1000000000000000000000000").unwrap()
.neg_mod(&Natural::from_str("1234567890987").unwrap()),
704498996588u64
);
type Output = Natural
source§impl<'a> NegMod<Natural> for &'a Natural
impl<'a> NegMod<Natural> for &'a Natural
source§fn neg_mod(self, other: Natural) -> Natural
fn neg_mod(self, other: Natural) -> Natural
Divides the negative of a Natural
by another Natural
, taking the first by reference
and the second by value and returning just the remainder.
If the quotient were computed, the quotient and remainder would satisfy $x = qy - r$ and $0 \leq r < y$.
$$ f(x, y) = y\left \lceil \frac{x}{y} \right \rceil - x. $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_base::num::arithmetic::traits::NegMod;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 3 * 10 - 7 = 23
assert_eq!((&Natural::from(23u32)).neg_mod(Natural::from(10u32)), 7);
// 810000006724 * 1234567890987 - 704498996588 = 1000000000000000000000000
assert_eq!(
(&Natural::from_str("1000000000000000000000000").unwrap())
.neg_mod(Natural::from_str("1234567890987").unwrap()),
704498996588u64
);
type Output = Natural
source§impl NegMod for Natural
impl NegMod for Natural
source§fn neg_mod(self, other: Natural) -> Natural
fn neg_mod(self, other: Natural) -> Natural
Divides the negative of a Natural
by another Natural
, taking both by value and
returning just the remainder.
If the quotient were computed, the quotient and remainder would satisfy $x = qy - r$ and $0 \leq r < y$.
$$ f(x, y) = y\left \lceil \frac{x}{y} \right \rceil - x. $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_base::num::arithmetic::traits::NegMod;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 3 * 10 - 7 = 23
assert_eq!(Natural::from(23u32).neg_mod(Natural::from(10u32)), 7);
// 810000006724 * 1234567890987 - 704498996588 = 1000000000000000000000000
assert_eq!(
Natural::from_str("1000000000000000000000000").unwrap()
.neg_mod(Natural::from_str("1234567890987").unwrap()),
704498996588u64
);
type Output = Natural
source§impl<'a> NegModAssign<&'a Natural> for Natural
impl<'a> NegModAssign<&'a Natural> for Natural
source§fn neg_mod_assign(&mut self, other: &'a Natural)
fn neg_mod_assign(&mut self, other: &'a Natural)
Divides the negative of a Natural
by another Natural
, taking the second Natural
s
by reference and replacing the first by the remainder.
If the quotient were computed, the quotient and remainder would satisfy $x = qy - r$ and $0 \leq r < y$.
$$ x \gets y\left \lceil \frac{x}{y} \right \rceil - x. $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_base::num::arithmetic::traits::NegModAssign;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 3 * 10 - 7 = 23
let mut x = Natural::from(23u32);
x.neg_mod_assign(&Natural::from(10u32));
assert_eq!(x, 7);
// 810000006724 * 1234567890987 - 704498996588 = 1000000000000000000000000
let mut x = Natural::from_str("1000000000000000000000000").unwrap();
x.neg_mod_assign(&Natural::from_str("1234567890987").unwrap());
assert_eq!(x, 704498996588u64);
source§impl NegModAssign for Natural
impl NegModAssign for Natural
source§fn neg_mod_assign(&mut self, other: Natural)
fn neg_mod_assign(&mut self, other: Natural)
Divides the negative of a Natural
by another Natural
, taking the second Natural
s
by value and replacing the first by the remainder.
If the quotient were computed, the quotient and remainder would satisfy $x = qy - r$ and $0 \leq r < y$.
$$ x \gets y\left \lceil \frac{x}{y} \right \rceil - x. $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_base::num::arithmetic::traits::NegModAssign;
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 3 * 10 - 7 = 23
let mut x = Natural::from(23u32);
x.neg_mod_assign(Natural::from(10u32));
assert_eq!(x, 7);
// 810000006724 * 1234567890987 - 704498996588 = 1000000000000000000000000
let mut x = Natural::from_str("1000000000000000000000000").unwrap();
x.neg_mod_assign(Natural::from_str("1234567890987").unwrap());
assert_eq!(x, 704498996588u64);
source§impl<'a> NegModPowerOf2 for &'a Natural
impl<'a> NegModPowerOf2 for &'a Natural
source§fn neg_mod_power_of_2(self, pow: u64) -> Natural
fn neg_mod_power_of_2(self, pow: u64) -> Natural
Divides the negative of a Natural
by a $2^k$, returning just the remainder. The
Natural
is taken by reference.
If the quotient were computed, the quotient and remainder would satisfy $x = q2^k - r$ and $0 \leq r < 2^k$.
$$ f(x, k) = 2^k\left \lceil \frac{x}{2^k} \right \rceil - x. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Examples
use malachite_base::num::arithmetic::traits::NegModPowerOf2;
use malachite_nz::natural::Natural;
// 2 * 2^8 - 252 = 260
assert_eq!((&Natural::from(260u32)).neg_mod_power_of_2(8), 252);
// 101 * 2^4 - 5 = 1611
assert_eq!((&Natural::from(1611u32)).neg_mod_power_of_2(4), 5);
type Output = Natural
source§impl NegModPowerOf2 for Natural
impl NegModPowerOf2 for Natural
source§fn neg_mod_power_of_2(self, pow: u64) -> Natural
fn neg_mod_power_of_2(self, pow: u64) -> Natural
Divides the negative of a Natural
by a $2^k$, returning just the remainder. The
Natural
is taken by value.
If the quotient were computed, the quotient and remainder would satisfy $x = q2^k - r$ and $0 \leq r < 2^k$.
$$ f(x, k) = 2^k\left \lceil \frac{x}{2^k} \right \rceil - x. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Examples
use malachite_base::num::arithmetic::traits::NegModPowerOf2;
use malachite_nz::natural::Natural;
// 2 * 2^8 - 252 = 260
assert_eq!(Natural::from(260u32).neg_mod_power_of_2(8), 252);
// 101 * 2^4 - 5 = 1611
assert_eq!(Natural::from(1611u32).neg_mod_power_of_2(4), 5);
type Output = Natural
source§impl NegModPowerOf2Assign for Natural
impl NegModPowerOf2Assign for Natural
source§fn neg_mod_power_of_2_assign(&mut self, pow: u64)
fn neg_mod_power_of_2_assign(&mut self, pow: u64)
Divides the negative of a Natural
by $2^k$, returning just the remainder.
If the quotient were computed, the quotient and remainder would satisfy $x = q2^k - r$ and $0 \leq r < 2^k$.
$$ x \gets 2^k\left \lceil \frac{x}{2^k} \right \rceil - x. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Examples
use malachite_base::num::arithmetic::traits::NegModPowerOf2Assign;
use malachite_nz::natural::Natural;
// 2 * 2^8 - 252 = 260
let mut x = Natural::from(260u32);
x.neg_mod_power_of_2_assign(8);
assert_eq!(x, 252);
// 101 * 2^4 - 5 = 1611
let mut x = Natural::from(1611u32);
x.neg_mod_power_of_2_assign(4);
assert_eq!(x, 5);
source§impl<'a> NextPowerOf2 for &'a Natural
impl<'a> NextPowerOf2 for &'a Natural
source§fn next_power_of_2(self) -> Natural
fn next_power_of_2(self) -> Natural
Finds the smallest power of 2 greater than or equal to a Natural
. The Natural
is
taken by reference.
$f(x) = 2^{\lceil \log_2 x \rceil}$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::{NextPowerOf2, Pow};
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::ZERO).next_power_of_2(), 1);
assert_eq!((&Natural::from(123u32)).next_power_of_2(), 128);
assert_eq!((&Natural::from(10u32).pow(12)).next_power_of_2(), 1099511627776u64);
type Output = Natural
source§impl NextPowerOf2 for Natural
impl NextPowerOf2 for Natural
source§fn next_power_of_2(self) -> Natural
fn next_power_of_2(self) -> Natural
Finds the smallest power of 2 greater than or equal to a Natural
. The Natural
is
taken by value.
$f(x) = 2^{\lceil \log_2 x \rceil}$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$ (only if the underlying Vec
needs to reallocate)
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::{NextPowerOf2, Pow};
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!(Natural::ZERO.next_power_of_2(), 1);
assert_eq!(Natural::from(123u32).next_power_of_2(), 128);
assert_eq!(Natural::from(10u32).pow(12).next_power_of_2(), 1099511627776u64);
type Output = Natural
source§impl NextPowerOf2Assign for Natural
impl NextPowerOf2Assign for Natural
source§fn next_power_of_2_assign(&mut self)
fn next_power_of_2_assign(&mut self)
Replaces a Natural
with the smallest power of 2 greater than or equal to it.
$x \gets 2^{\lceil \log_2 x \rceil}$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$ (only if the underlying Vec
needs to reallocate)
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::{NextPowerOf2Assign, Pow};
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
let mut x = Natural::ZERO;
x.next_power_of_2_assign();
assert_eq!(x, 1);
let mut x = Natural::from(123u32);
x.next_power_of_2_assign();
assert_eq!(x, 128);
let mut x = Natural::from(10u32).pow(12);
x.next_power_of_2_assign();
assert_eq!(x, 1099511627776u64);
source§impl<'a> Not for &'a Natural
impl<'a> Not for &'a Natural
source§fn not(self) -> Integer
fn not(self) -> Integer
Returns the bitwise negation of a Natural
, taking it by reference and returning an
Integer
.
The Natural
is bitwise-negated as if it were represented in two’s complement.
$$ f(n) = -n - 1. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!(!&Natural::ZERO, -1);
assert_eq!(!&Natural::from(123u32), -124);
source§impl Not for Natural
impl Not for Natural
source§fn not(self) -> Integer
fn not(self) -> Integer
Returns the bitwise negation of a Natural
, taking it by value and returning an
Integer
.
The Natural
is bitwise-negated as if it were represented in two’s complement.
$$ f(n) = -n - 1. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!(!Natural::ZERO, -1);
assert_eq!(!Natural::from(123u32), -124);
source§impl Octal for Natural
impl Octal for Natural
source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Converts a Natural
to an octal String
.
Using the #
format flag prepends "0o"
to the string.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_base::strings::ToOctalString;
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!(Natural::ZERO.to_octal_string(), "0");
assert_eq!(Natural::from(123u32).to_octal_string(), "173");
assert_eq!(
Natural::from_str("1000000000000").unwrap().to_octal_string(),
"16432451210000"
);
assert_eq!(format!("{:07o}", Natural::from(123u32)), "0000173");
assert_eq!(format!("{:#o}", Natural::ZERO), "0o0");
assert_eq!(format!("{:#o}", Natural::from(123u32)), "0o173");
assert_eq!(
format!("{:#o}", Natural::from_str("1000000000000").unwrap()),
"0o16432451210000"
);
assert_eq!(format!("{:#07o}", Natural::from(123u32)), "0o00173");
source§impl Ord for Natural
impl Ord for Natural
source§fn cmp(&self, other: &Natural) -> Ordering
fn cmp(&self, other: &Natural) -> Ordering
Compares two Natural
s.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_nz::natural::Natural;
assert!(Natural::from(123u32) > Natural::from(122u32));
assert!(Natural::from(123u32) >= Natural::from(122u32));
assert!(Natural::from(123u32) < Natural::from(124u32));
assert!(Natural::from(123u32) <= Natural::from(124u32));
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl<'a> OverflowingFrom<&'a Natural> for i128
impl<'a> OverflowingFrom<&'a Natural> for i128
source§fn overflowing_from(value: &Natural) -> (i128, bool)
fn overflowing_from(value: &Natural) -> (i128, bool)
Converts a Natural
to an isize
or a value of a signed primitive integer type
that’s larger than a Limb
, wrapping modulo $2^W$, where $W$ is the
width of a limb.
The returned boolean value indicates whether wrapping occurred.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§impl<'a> OverflowingFrom<&'a Natural> for i16
impl<'a> OverflowingFrom<&'a Natural> for i16
source§impl<'a> OverflowingFrom<&'a Natural> for i32
impl<'a> OverflowingFrom<&'a Natural> for i32
source§impl<'a> OverflowingFrom<&'a Natural> for i64
impl<'a> OverflowingFrom<&'a Natural> for i64
source§impl<'a> OverflowingFrom<&'a Natural> for i8
impl<'a> OverflowingFrom<&'a Natural> for i8
source§impl<'a> OverflowingFrom<&'a Natural> for isize
impl<'a> OverflowingFrom<&'a Natural> for isize
source§fn overflowing_from(value: &Natural) -> (isize, bool)
fn overflowing_from(value: &Natural) -> (isize, bool)
Converts a Natural
to an isize
or a value of a signed primitive integer type
that’s larger than a Limb
, wrapping modulo $2^W$, where $W$ is the
width of a limb.
The returned boolean value indicates whether wrapping occurred.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§impl<'a> OverflowingFrom<&'a Natural> for u128
impl<'a> OverflowingFrom<&'a Natural> for u128
source§impl<'a> OverflowingFrom<&'a Natural> for u16
impl<'a> OverflowingFrom<&'a Natural> for u16
source§impl<'a> OverflowingFrom<&'a Natural> for u32
impl<'a> OverflowingFrom<&'a Natural> for u32
source§impl<'a> OverflowingFrom<&'a Natural> for u64
impl<'a> OverflowingFrom<&'a Natural> for u64
source§impl<'a> OverflowingFrom<&'a Natural> for u8
impl<'a> OverflowingFrom<&'a Natural> for u8
source§impl<'a> OverflowingFrom<&'a Natural> for usize
impl<'a> OverflowingFrom<&'a Natural> for usize
source§impl<'a> Parity for &'a Natural
impl<'a> Parity for &'a Natural
source§fn even(self) -> bool
fn even(self) -> bool
Tests whether a Natural
is even.
$f(x) = (2|x)$.
$f(x) = (\exists k \in \N : x = 2k)$.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::arithmetic::traits::{Parity, Pow};
use malachite_base::num::basic::traits::{One, Zero};
use malachite_nz::natural::Natural;
assert_eq!(Natural::ZERO.even(), true);
assert_eq!(Natural::from(123u32).even(), false);
assert_eq!(Natural::from(0x80u32).even(), true);
assert_eq!(Natural::from(10u32).pow(12).even(), true);
assert_eq!((Natural::from(10u32).pow(12) + Natural::ONE).even(), false);
source§fn odd(self) -> bool
fn odd(self) -> bool
Tests whether a Natural
is odd.
$f(x) = (2\nmid x)$.
$f(x) = (\exists k \in \N : x = 2k+1)$.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::arithmetic::traits::{Parity, Pow};
use malachite_base::num::basic::traits::{One, Zero};
use malachite_nz::natural::Natural;
assert_eq!(Natural::ZERO.odd(), false);
assert_eq!(Natural::from(123u32).odd(), true);
assert_eq!(Natural::from(0x80u32).odd(), false);
assert_eq!(Natural::from(10u32).pow(12).odd(), false);
assert_eq!((Natural::from(10u32).pow(12) + Natural::ONE).odd(), true);
source§impl PartialEq<Integer> for Natural
impl PartialEq<Integer> for Natural
source§fn eq(&self, other: &Integer) -> bool
fn eq(&self, other: &Integer) -> bool
Determines whether a Natural
is equal to an Integer
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where n = min(self.significant_bits(), other.significant_bits())
§Examples
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;
assert!(Natural::from(123u32) == Integer::from(123));
assert!(Natural::from(123u32) != Integer::from(5));
source§impl PartialEq<Natural> for Integer
impl PartialEq<Natural> for Integer
source§fn eq(&self, other: &Natural) -> bool
fn eq(&self, other: &Natural) -> bool
Determines whether an Integer
is equal to a Natural
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where n = min(self.significant_bits(), other.significant_bits())
§Examples
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;
assert!(Integer::from(123) == Natural::from(123u32));
assert!(Integer::from(123) != Natural::from(5u32));
source§impl PartialEq<Natural> for u128
impl PartialEq<Natural> for u128
source§fn eq(&self, other: &Natural) -> bool
fn eq(&self, other: &Natural) -> bool
Determines whether a value of an unsigned primitive integer type that’s larger than
a Limb
is equal to a Natural
.
This implementation is general enough to also work for usize
, regardless of
whether it is equal in width to Limb
.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§impl PartialEq<Natural> for usize
impl PartialEq<Natural> for usize
source§fn eq(&self, other: &Natural) -> bool
fn eq(&self, other: &Natural) -> bool
Determines whether a value of an unsigned primitive integer type that’s larger than
a Limb
is equal to a Natural
.
This implementation is general enough to also work for usize
, regardless of
whether it is equal in width to Limb
.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
source§impl PartialEq for Natural
impl PartialEq for Natural
source§impl PartialOrd<Integer> for Natural
impl PartialOrd<Integer> for Natural
source§fn partial_cmp(&self, other: &Integer) -> Option<Ordering>
fn partial_cmp(&self, other: &Integer) -> Option<Ordering>
Compares a Natural
to an Integer
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where n = min(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;
assert!(Natural::from(123u32) > Integer::from(122));
assert!(Natural::from(123u32) >= Integer::from(122));
assert!(Natural::from(123u32) < Integer::from(124));
assert!(Natural::from(123u32) <= Integer::from(124));
assert!(Natural::from(123u32) > Integer::from(-123));
assert!(Natural::from(123u32) >= Integer::from(-123));
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 PartialOrd<Natural> for Integer
impl PartialOrd<Natural> for Integer
source§fn partial_cmp(&self, other: &Natural) -> Option<Ordering>
fn partial_cmp(&self, other: &Natural) -> Option<Ordering>
Compares an Integer
to a Natural
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where n = min(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;
assert!(Integer::from(123) > Natural::from(122u32));
assert!(Integer::from(123) >= Natural::from(122u32));
assert!(Integer::from(123) < Natural::from(124u32));
assert!(Integer::from(123) <= Natural::from(124u32));
assert!(Integer::from(-123) < Natural::from(123u32));
assert!(Integer::from(-123) <= Natural::from(123u32));
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 PartialOrd<Natural> for f32
impl PartialOrd<Natural> for f32
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 PartialOrd<Natural> for f64
impl PartialOrd<Natural> for f64
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 PartialOrd<Natural> for i128
impl PartialOrd<Natural> for i128
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 PartialOrd<Natural> for i16
impl PartialOrd<Natural> for i16
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 PartialOrd<Natural> for i32
impl PartialOrd<Natural> for i32
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 PartialOrd<Natural> for i64
impl PartialOrd<Natural> for i64
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 PartialOrd<Natural> for i8
impl PartialOrd<Natural> for i8
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 PartialOrd<Natural> for isize
impl PartialOrd<Natural> for isize
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 PartialOrd<Natural> for u128
impl PartialOrd<Natural> for u128
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 PartialOrd<Natural> for u16
impl PartialOrd<Natural> for u16
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 PartialOrd<Natural> for u32
impl PartialOrd<Natural> for u32
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 PartialOrd<Natural> for u64
impl PartialOrd<Natural> for u64
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 PartialOrd<Natural> for u8
impl PartialOrd<Natural> for u8
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 PartialOrd<Natural> for usize
impl PartialOrd<Natural> for usize
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 PartialOrd<f32> for Natural
impl PartialOrd<f32> for Natural
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 PartialOrd<f64> for Natural
impl PartialOrd<f64> for Natural
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 PartialOrd<i128> for Natural
impl PartialOrd<i128> for Natural
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 PartialOrd<i16> for Natural
impl PartialOrd<i16> for Natural
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 PartialOrd<i32> for Natural
impl PartialOrd<i32> for Natural
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 PartialOrd<i64> for Natural
impl PartialOrd<i64> for Natural
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 PartialOrd<i8> for Natural
impl PartialOrd<i8> for Natural
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 PartialOrd<isize> for Natural
impl PartialOrd<isize> for Natural
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 PartialOrd<u128> for Natural
impl PartialOrd<u128> for Natural
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 PartialOrd<u16> for Natural
impl PartialOrd<u16> for Natural
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 PartialOrd<u32> for Natural
impl PartialOrd<u32> for Natural
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 PartialOrd<u64> for Natural
impl PartialOrd<u64> for Natural
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 PartialOrd<u8> for Natural
impl PartialOrd<u8> for Natural
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 PartialOrd<usize> for Natural
impl PartialOrd<usize> for Natural
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 PartialOrd for Natural
impl PartialOrd for Natural
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 PartialOrdAbs<Integer> for Natural
impl PartialOrdAbs<Integer> for Natural
source§fn partial_cmp_abs(&self, other: &Integer) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &Integer) -> Option<Ordering>
Compares the absolute values of a Natural
and an Integer
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::comparison::traits::PartialOrdAbs;
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;
assert!(Natural::from(123u32).gt_abs(&Integer::from(122)));
assert!(Natural::from(123u32).ge_abs(&Integer::from(122)));
assert!(Natural::from(123u32).lt_abs(&Integer::from(124)));
assert!(Natural::from(123u32).le_abs(&Integer::from(124)));
assert!(Natural::from(123u32).lt_abs(&Integer::from(-124)));
assert!(Natural::from(123u32).le_abs(&Integer::from(-124)));
source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
source§impl PartialOrdAbs<Natural> for Integer
impl PartialOrdAbs<Natural> for Integer
source§fn partial_cmp_abs(&self, other: &Natural) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &Natural) -> Option<Ordering>
Compares the absolute values of an Integer
and a Natural
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.significant_bits())
.
§Examples
use malachite_base::num::comparison::traits::PartialOrdAbs;
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;
assert!(Integer::from(123).gt_abs(&Natural::from(122u32)));
assert!(Integer::from(123).ge_abs(&Natural::from(122u32)));
assert!(Integer::from(123).lt_abs(&Natural::from(124u32)));
assert!(Integer::from(123).le_abs(&Natural::from(124u32)));
assert!(Integer::from(-124).gt_abs(&Natural::from(123u32)));
assert!(Integer::from(-124).ge_abs(&Natural::from(123u32)));
source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
source§impl PartialOrdAbs<Natural> for f32
impl PartialOrdAbs<Natural> for f32
source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
source§impl PartialOrdAbs<Natural> for f64
impl PartialOrdAbs<Natural> for f64
source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
source§impl PartialOrdAbs<Natural> for i128
impl PartialOrdAbs<Natural> for i128
source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
source§impl PartialOrdAbs<Natural> for i16
impl PartialOrdAbs<Natural> for i16
source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
source§impl PartialOrdAbs<Natural> for i32
impl PartialOrdAbs<Natural> for i32
source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
source§impl PartialOrdAbs<Natural> for i64
impl PartialOrdAbs<Natural> for i64
source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
source§impl PartialOrdAbs<Natural> for i8
impl PartialOrdAbs<Natural> for i8
source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
source§impl PartialOrdAbs<Natural> for isize
impl PartialOrdAbs<Natural> for isize
source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
source§impl PartialOrdAbs<Natural> for u128
impl PartialOrdAbs<Natural> for u128
source§fn partial_cmp_abs(&self, other: &Natural) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &Natural) -> Option<Ordering>
Compares a value of unsigned primitive integer type to a Natural
.
Since both values are non-negative, this is the same as ordinary
partial_cmp
.
§Worst-case complexity
Constant time and additional memory.
See here.
source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
source§impl PartialOrdAbs<Natural> for u16
impl PartialOrdAbs<Natural> for u16
source§fn partial_cmp_abs(&self, other: &Natural) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &Natural) -> Option<Ordering>
Compares a value of unsigned primitive integer type to a Natural
.
Since both values are non-negative, this is the same as ordinary
partial_cmp
.
§Worst-case complexity
Constant time and additional memory.
See here.
source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
source§impl PartialOrdAbs<Natural> for u32
impl PartialOrdAbs<Natural> for u32
source§fn partial_cmp_abs(&self, other: &Natural) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &Natural) -> Option<Ordering>
Compares a value of unsigned primitive integer type to a Natural
.
Since both values are non-negative, this is the same as ordinary
partial_cmp
.
§Worst-case complexity
Constant time and additional memory.
See here.
source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
source§impl PartialOrdAbs<Natural> for u64
impl PartialOrdAbs<Natural> for u64
source§fn partial_cmp_abs(&self, other: &Natural) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &Natural) -> Option<Ordering>
Compares a value of unsigned primitive integer type to a Natural
.
Since both values are non-negative, this is the same as ordinary
partial_cmp
.
§Worst-case complexity
Constant time and additional memory.
See here.
source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
source§impl PartialOrdAbs<Natural> for u8
impl PartialOrdAbs<Natural> for u8
source§fn partial_cmp_abs(&self, other: &Natural) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &Natural) -> Option<Ordering>
Compares a value of unsigned primitive integer type to a Natural
.
Since both values are non-negative, this is the same as ordinary
partial_cmp
.
§Worst-case complexity
Constant time and additional memory.
See here.
source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
source§impl PartialOrdAbs<Natural> for usize
impl PartialOrdAbs<Natural> for usize
source§fn partial_cmp_abs(&self, other: &Natural) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &Natural) -> Option<Ordering>
Compares a value of unsigned primitive integer type to a Natural
.
Since both values are non-negative, this is the same as ordinary
partial_cmp
.
§Worst-case complexity
Constant time and additional memory.
See here.
source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
source§impl PartialOrdAbs<f32> for Natural
impl PartialOrdAbs<f32> for Natural
source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
source§impl PartialOrdAbs<f64> for Natural
impl PartialOrdAbs<f64> for Natural
source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
source§impl PartialOrdAbs<i128> for Natural
impl PartialOrdAbs<i128> for Natural
source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
source§impl PartialOrdAbs<i16> for Natural
impl PartialOrdAbs<i16> for Natural
source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
source§impl PartialOrdAbs<i32> for Natural
impl PartialOrdAbs<i32> for Natural
source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
source§impl PartialOrdAbs<i64> for Natural
impl PartialOrdAbs<i64> for Natural
source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
source§impl PartialOrdAbs<i8> for Natural
impl PartialOrdAbs<i8> for Natural
source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
source§impl PartialOrdAbs<isize> for Natural
impl PartialOrdAbs<isize> for Natural
source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
source§impl PartialOrdAbs<u128> for Natural
impl PartialOrdAbs<u128> for Natural
source§fn partial_cmp_abs(&self, other: &u128) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &u128) -> Option<Ordering>
Compares a Natural
to an unsigned primitive integer.
Since both values are non-negative, this is the same as ordinary
partial_cmp
.
§Worst-case complexity
Constant time and additional memory.
See here.
source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
source§impl PartialOrdAbs<u16> for Natural
impl PartialOrdAbs<u16> for Natural
source§fn partial_cmp_abs(&self, other: &u16) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &u16) -> Option<Ordering>
Compares a Natural
to an unsigned primitive integer.
Since both values are non-negative, this is the same as ordinary
partial_cmp
.
§Worst-case complexity
Constant time and additional memory.
See here.
source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
source§impl PartialOrdAbs<u32> for Natural
impl PartialOrdAbs<u32> for Natural
source§fn partial_cmp_abs(&self, other: &u32) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &u32) -> Option<Ordering>
Compares a Natural
to an unsigned primitive integer.
Since both values are non-negative, this is the same as ordinary
partial_cmp
.
§Worst-case complexity
Constant time and additional memory.
See here.
source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
source§impl PartialOrdAbs<u64> for Natural
impl PartialOrdAbs<u64> for Natural
source§fn partial_cmp_abs(&self, other: &u64) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &u64) -> Option<Ordering>
Compares a Natural
to an unsigned primitive integer.
Since both values are non-negative, this is the same as ordinary
partial_cmp
.
§Worst-case complexity
Constant time and additional memory.
See here.
source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
source§impl PartialOrdAbs<u8> for Natural
impl PartialOrdAbs<u8> for Natural
source§fn partial_cmp_abs(&self, other: &u8) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &u8) -> Option<Ordering>
Compares a Natural
to an unsigned primitive integer.
Since both values are non-negative, this is the same as ordinary
partial_cmp
.
§Worst-case complexity
Constant time and additional memory.
See here.
source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
source§impl PartialOrdAbs<usize> for Natural
impl PartialOrdAbs<usize> for Natural
source§fn partial_cmp_abs(&self, other: &usize) -> Option<Ordering>
fn partial_cmp_abs(&self, other: &usize) -> Option<Ordering>
Compares a Natural
to an unsigned primitive integer.
Since both values are non-negative, this is the same as ordinary
partial_cmp
.
§Worst-case complexity
Constant time and additional memory.
See here.
source§fn lt_abs(&self, other: &Rhs) -> bool
fn lt_abs(&self, other: &Rhs) -> bool
source§fn le_abs(&self, other: &Rhs) -> bool
fn le_abs(&self, other: &Rhs) -> bool
source§impl<'a> Pow<u64> for &'a Natural
impl<'a> Pow<u64> for &'a Natural
source§fn pow(self, exp: u64) -> Natural
fn pow(self, exp: u64) -> Natural
Raises a Natural
to a power, taking the Natural
by reference.
$f(x, n) = x^n$.
§Worst-case complexity
$T(n, m) = O(nm \log (nm) \log\log (nm))$
$M(n, m) = O(nm \log (nm))$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and $m$ is
exp
.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!(
(&Natural::from(3u32)).pow(100).to_string(),
"515377520732011331036461129765621272702107522001"
);
assert_eq!(
(&Natural::from_str("12345678987654321").unwrap()).pow(3).to_string(),
"1881676411868862234942354805142998028003108518161"
);
type Output = Natural
source§impl Pow<u64> for Natural
impl Pow<u64> for Natural
source§fn pow(self, exp: u64) -> Natural
fn pow(self, exp: u64) -> Natural
Raises a Natural
to a power, taking the Natural
by value.
$f(x, n) = x^n$.
§Worst-case complexity
$T(n, m) = O(nm \log (nm) \log\log (nm))$
$M(n, m) = O(nm \log (nm))$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and $m$ is
exp
.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!(
Natural::from(3u32).pow(100).to_string(),
"515377520732011331036461129765621272702107522001"
);
assert_eq!(
Natural::from_str("12345678987654321").unwrap().pow(3).to_string(),
"1881676411868862234942354805142998028003108518161"
);
type Output = Natural
source§impl PowAssign<u64> for Natural
impl PowAssign<u64> for Natural
source§fn pow_assign(&mut self, exp: u64)
fn pow_assign(&mut self, exp: u64)
Raises a Natural
to a power in place.
$x \gets x^n$.
§Worst-case complexity
$T(n, m) = O(nm \log (nm) \log\log (nm))$
$M(n, m) = O(nm \log (nm))$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and $m$ is
exp
.
§Examples
use malachite_base::num::arithmetic::traits::PowAssign;
use malachite_nz::natural::Natural;
use core::str::FromStr;
let mut x = Natural::from(3u32);
x.pow_assign(100);
assert_eq!(x.to_string(), "515377520732011331036461129765621272702107522001");
let mut x = Natural::from_str("12345678987654321").unwrap();
x.pow_assign(3);
assert_eq!(x.to_string(), "1881676411868862234942354805142998028003108518161");
source§impl PowerOf2<u64> for Natural
impl PowerOf2<u64> for Natural
source§fn power_of_2(pow: u64) -> Natural
fn power_of_2(pow: u64) -> Natural
Raises 2 to an integer power.
$f(k) = 2^k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Examples
use malachite_base::num::arithmetic::traits::PowerOf2;
use malachite_nz::natural::Natural;
assert_eq!(Natural::power_of_2(0), 1);
assert_eq!(Natural::power_of_2(3), 8);
assert_eq!(Natural::power_of_2(100).to_string(), "1267650600228229401496703205376");
source§impl<'a> PowerOf2DigitIterable<Natural> for &'a Natural
impl<'a> PowerOf2DigitIterable<Natural> for &'a Natural
source§fn power_of_2_digits(self, log_base: u64) -> NaturalPowerOf2DigitIterator<'a> ⓘ
fn power_of_2_digits(self, log_base: u64) -> NaturalPowerOf2DigitIterator<'a> ⓘ
Returns a double-ended iterator over the base-$2^k$ digits of a Natural
.
The base-2 logarithm of the base is specified. The type of each digit is Natural
. The
forward order is ascending, so that less significant digits appear first. There are no
trailing zero digits going forward, or leading zero digits going backward.
If it’s necessary to get a [Vec
] of all the digits, consider using
to_power_of_2_digits_asc
or
to_power_of_2_digits_desc
instead.
§Worst-case complexity
Constant time and additional memory.
§Examples
use itertools::Itertools;
use malachite_base::num::basic::traits::Zero;
use malachite_base::num::conversion::traits::PowerOf2DigitIterable;
use malachite_nz::natural::Natural;
let n = Natural::ZERO;
assert!(PowerOf2DigitIterable::<Natural>::power_of_2_digits(&n, 2).next().is_none());
// 107 = 1223_4
let n = Natural::from(107u32);
assert_eq!(
PowerOf2DigitIterable::<Natural>::power_of_2_digits(&n, 2).collect_vec(),
vec![
Natural::from(3u32),
Natural::from(2u32),
Natural::from(2u32),
Natural::from(1u32)
]
);
let n = Natural::ZERO;
assert!(PowerOf2DigitIterable::<Natural>::power_of_2_digits(&n, 2)
.next_back()
.is_none());
// 107 = 1223_4
let n = Natural::from(107u32);
assert_eq!(
PowerOf2DigitIterable::<Natural>::power_of_2_digits(&n, 2)
.rev()
.collect_vec(),
vec![
Natural::from(1u32),
Natural::from(2u32),
Natural::from(2u32),
Natural::from(3u32)
]
);
type PowerOf2DigitIterator = NaturalPowerOf2DigitIterator<'a>
source§impl<'a> PowerOf2DigitIterable<u128> for &'a Natural
impl<'a> PowerOf2DigitIterable<u128> for &'a Natural
source§fn power_of_2_digits(
self,
log_base: u64
) -> NaturalPowerOf2DigitPrimitiveIterator<'a, u128> ⓘ
fn power_of_2_digits( self, log_base: u64 ) -> NaturalPowerOf2DigitPrimitiveIterator<'a, u128> ⓘ
Returns a double-ended iterator over the base-$2^k$ digits of a Natural
.
The base-2 logarithm of the base is specified. Each digit has primitive integer
type, and log_base
must be no larger than the width of that type. The forward
order is ascending, so that less significant digits appear first. There are no
trailing zero digits going forward, or leading zero digits going backward.
If it’s necessary to get a [Vec
] of all the digits, consider using
to_power_of_2_digits_asc
or
to_power_of_2_digits_desc
instead.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
type PowerOf2DigitIterator = NaturalPowerOf2DigitPrimitiveIterator<'a, u128>
source§impl<'a> PowerOf2DigitIterable<u16> for &'a Natural
impl<'a> PowerOf2DigitIterable<u16> for &'a Natural
source§fn power_of_2_digits(
self,
log_base: u64
) -> NaturalPowerOf2DigitPrimitiveIterator<'a, u16> ⓘ
fn power_of_2_digits( self, log_base: u64 ) -> NaturalPowerOf2DigitPrimitiveIterator<'a, u16> ⓘ
Returns a double-ended iterator over the base-$2^k$ digits of a Natural
.
The base-2 logarithm of the base is specified. Each digit has primitive integer
type, and log_base
must be no larger than the width of that type. The forward
order is ascending, so that less significant digits appear first. There are no
trailing zero digits going forward, or leading zero digits going backward.
If it’s necessary to get a [Vec
] of all the digits, consider using
to_power_of_2_digits_asc
or
to_power_of_2_digits_desc
instead.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
type PowerOf2DigitIterator = NaturalPowerOf2DigitPrimitiveIterator<'a, u16>
source§impl<'a> PowerOf2DigitIterable<u32> for &'a Natural
impl<'a> PowerOf2DigitIterable<u32> for &'a Natural
source§fn power_of_2_digits(
self,
log_base: u64
) -> NaturalPowerOf2DigitPrimitiveIterator<'a, u32> ⓘ
fn power_of_2_digits( self, log_base: u64 ) -> NaturalPowerOf2DigitPrimitiveIterator<'a, u32> ⓘ
Returns a double-ended iterator over the base-$2^k$ digits of a Natural
.
The base-2 logarithm of the base is specified. Each digit has primitive integer
type, and log_base
must be no larger than the width of that type. The forward
order is ascending, so that less significant digits appear first. There are no
trailing zero digits going forward, or leading zero digits going backward.
If it’s necessary to get a [Vec
] of all the digits, consider using
to_power_of_2_digits_asc
or
to_power_of_2_digits_desc
instead.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
type PowerOf2DigitIterator = NaturalPowerOf2DigitPrimitiveIterator<'a, u32>
source§impl<'a> PowerOf2DigitIterable<u64> for &'a Natural
impl<'a> PowerOf2DigitIterable<u64> for &'a Natural
source§fn power_of_2_digits(
self,
log_base: u64
) -> NaturalPowerOf2DigitPrimitiveIterator<'a, u64> ⓘ
fn power_of_2_digits( self, log_base: u64 ) -> NaturalPowerOf2DigitPrimitiveIterator<'a, u64> ⓘ
Returns a double-ended iterator over the base-$2^k$ digits of a Natural
.
The base-2 logarithm of the base is specified. Each digit has primitive integer
type, and log_base
must be no larger than the width of that type. The forward
order is ascending, so that less significant digits appear first. There are no
trailing zero digits going forward, or leading zero digits going backward.
If it’s necessary to get a [Vec
] of all the digits, consider using
to_power_of_2_digits_asc
or
to_power_of_2_digits_desc
instead.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
type PowerOf2DigitIterator = NaturalPowerOf2DigitPrimitiveIterator<'a, u64>
source§impl<'a> PowerOf2DigitIterable<u8> for &'a Natural
impl<'a> PowerOf2DigitIterable<u8> for &'a Natural
source§fn power_of_2_digits(
self,
log_base: u64
) -> NaturalPowerOf2DigitPrimitiveIterator<'a, u8> ⓘ
fn power_of_2_digits( self, log_base: u64 ) -> NaturalPowerOf2DigitPrimitiveIterator<'a, u8> ⓘ
Returns a double-ended iterator over the base-$2^k$ digits of a Natural
.
The base-2 logarithm of the base is specified. Each digit has primitive integer
type, and log_base
must be no larger than the width of that type. The forward
order is ascending, so that less significant digits appear first. There are no
trailing zero digits going forward, or leading zero digits going backward.
If it’s necessary to get a [Vec
] of all the digits, consider using
to_power_of_2_digits_asc
or
to_power_of_2_digits_desc
instead.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
type PowerOf2DigitIterator = NaturalPowerOf2DigitPrimitiveIterator<'a, u8>
source§impl<'a> PowerOf2DigitIterable<usize> for &'a Natural
impl<'a> PowerOf2DigitIterable<usize> for &'a Natural
source§fn power_of_2_digits(
self,
log_base: u64
) -> NaturalPowerOf2DigitPrimitiveIterator<'a, usize> ⓘ
fn power_of_2_digits( self, log_base: u64 ) -> NaturalPowerOf2DigitPrimitiveIterator<'a, usize> ⓘ
Returns a double-ended iterator over the base-$2^k$ digits of a Natural
.
The base-2 logarithm of the base is specified. Each digit has primitive integer
type, and log_base
must be no larger than the width of that type. The forward
order is ascending, so that less significant digits appear first. There are no
trailing zero digits going forward, or leading zero digits going backward.
If it’s necessary to get a [Vec
] of all the digits, consider using
to_power_of_2_digits_asc
or
to_power_of_2_digits_desc
instead.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
type PowerOf2DigitIterator = NaturalPowerOf2DigitPrimitiveIterator<'a, usize>
source§impl<'a> PowerOf2DigitIterator<Natural> for NaturalPowerOf2DigitIterator<'a>
impl<'a> PowerOf2DigitIterator<Natural> for NaturalPowerOf2DigitIterator<'a>
source§fn get(&self, index: u64) -> Natural
fn get(&self, index: u64) -> Natural
Retrieves the base-$2^k$ digits of a Natural
by index.
$f(x, k, i) = d_i$, where $0 \leq d_i < 2^k$ for all $i$ and $$ \sum_{i=0}^\infty2^{ki}d_i = x. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is log_base
.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_base::num::conversion::traits::{PowerOf2DigitIterable, PowerOf2DigitIterator};
use malachite_nz::natural::Natural;
let n = Natural::ZERO;
assert_eq!(PowerOf2DigitIterable::<Natural>::power_of_2_digits(&n, 2).get(0), 0);
// 107 = 1223_4
let n = Natural::from(107u32);
let digits = PowerOf2DigitIterable::<Natural>::power_of_2_digits(&n, 2);
assert_eq!(digits.get(0), 3);
assert_eq!(digits.get(1), 2);
assert_eq!(digits.get(2), 2);
assert_eq!(digits.get(3), 1);
assert_eq!(digits.get(4), 0);
assert_eq!(digits.get(100), 0);
source§impl PowerOf2Digits<Natural> for Natural
impl PowerOf2Digits<Natural> for Natural
source§fn to_power_of_2_digits_asc(&self, log_base: u64) -> Vec<Natural>
fn to_power_of_2_digits_asc(&self, log_base: u64) -> Vec<Natural>
Returns a Vec
containing the base-$2^k$ digits of a Natural
in ascending order:
least- to most-significant.
The base-2 logarithm of the base is specified. The type of each digit is Natural
. If the
Natural
is 0, the Vec
is empty; otherwise, it ends with a nonzero digit.
$f(x, k) = (d_i)_ {i=0}^{n-1}$, where $0 \leq d_i < 2^k$ for all $i$, $n=0$ or $d_{n-1} \neq 0$, and
$$ \sum_{i=0}^{n-1}2^{ki}d_i = x. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if log_base
is zero.
§Examples
use malachite_base::num::basic::traits::{Two, Zero};
use malachite_base::num::conversion::traits::PowerOf2Digits;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
assert_eq!(
PowerOf2Digits::<Natural>::to_power_of_2_digits_asc(&Natural::ZERO, 6)
.to_debug_string(),
"[]"
);
assert_eq!(
PowerOf2Digits::<Natural>::to_power_of_2_digits_asc(&Natural::TWO, 6)
.to_debug_string(),
"[2]"
);
// 123_10 = 173_8
assert_eq!(
PowerOf2Digits::<Natural>::to_power_of_2_digits_asc(&Natural::from(123u32), 3)
.to_debug_string(),
"[3, 7, 1]"
);
source§fn to_power_of_2_digits_desc(&self, log_base: u64) -> Vec<Natural>
fn to_power_of_2_digits_desc(&self, log_base: u64) -> Vec<Natural>
Returns a Vec
containing the base-$2^k$ digits of a Natural
in descending order:
most- to least-significant.
The base-2 logarithm of the base is specified. The type of each digit is Natural
. If the
Natural
is 0, the Vec
is empty; otherwise, it begins with a nonzero digit.
$f(x, k) = (d_i)_ {i=0}^{n-1}$, where $0 \leq d_i < 2^k$ for all $i$, $n=0$ or $d_0 \neq 0$, and
$$ \sum_{i=0}^{n-1}2^{k (n-i-1)}d_i = x. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if log_base
is zero.
§Examples
use malachite_base::num::basic::traits::{Two, Zero};
use malachite_base::num::conversion::traits::PowerOf2Digits;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
assert_eq!(
PowerOf2Digits::<Natural>::to_power_of_2_digits_desc(&Natural::ZERO, 6)
.to_debug_string(),
"[]"
);
assert_eq!(
PowerOf2Digits::<Natural>::to_power_of_2_digits_desc(&Natural::TWO, 6)
.to_debug_string(),
"[2]"
);
// 123_10 = 173_8
assert_eq!(
PowerOf2Digits::<Natural>::to_power_of_2_digits_desc(&Natural::from(123u32), 3)
.to_debug_string(),
"[1, 7, 3]"
);
source§fn from_power_of_2_digits_asc<I: Iterator<Item = Natural>>(
log_base: u64,
digits: I
) -> Option<Natural>
fn from_power_of_2_digits_asc<I: Iterator<Item = Natural>>( log_base: u64, digits: I ) -> Option<Natural>
Converts an iterator of base-$2^k$ digits into a Natural
.
The base-2 logarithm of the base is specified. The input digits are in ascending order:
least- to most-significant. The type of each digit is Natural
.
If some digit is greater than $2^k$, None
is returned.
$$ f((d_i)_ {i=0}^{n-1}, k) = \sum_{i=0}^{n-1}2^{ki}d_i. $$
§Worst-case complexity
$T(n, m) = O(nm)$
$M(n, m) = O(nm)$
where $T$ is time, $M$ is additional memory, $n$ is digits.count()
, and $m$ is log_base
.
§Panics
Panics if log_base
is zero.
§Examples
use malachite_base::num::basic::traits::{One, Two, Zero};
use malachite_base::num::conversion::traits::PowerOf2Digits;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
let digits = &[Natural::ZERO, Natural::ZERO, Natural::ZERO];
assert_eq!(
Natural::from_power_of_2_digits_asc(6, digits.iter().cloned()).to_debug_string(),
"Some(0)"
);
let digits = &[Natural::TWO, Natural::ZERO];
assert_eq!(
Natural::from_power_of_2_digits_asc(6, digits.iter().cloned()).to_debug_string(),
"Some(2)"
);
let digits = &[Natural::from(3u32), Natural::from(7u32), Natural::ONE];
assert_eq!(
Natural::from_power_of_2_digits_asc(3, digits.iter().cloned()).to_debug_string(),
"Some(123)"
);
let digits = &[Natural::from(100u32)];
assert_eq!(
Natural::from_power_of_2_digits_asc(3, digits.iter().cloned()).to_debug_string(),
"None"
);
source§fn from_power_of_2_digits_desc<I: Iterator<Item = Natural>>(
log_base: u64,
digits: I
) -> Option<Natural>
fn from_power_of_2_digits_desc<I: Iterator<Item = Natural>>( log_base: u64, digits: I ) -> Option<Natural>
Converts an iterator of base-$2^k$ digits into a Natural
.
The base-2 logarithm of the base is specified. The input digits are in descending order:
most- to least-significant. The type of each digit is Natural
.
If some digit is greater than $2^k$, None
is returned.
$$ f((d_i)_ {i=0}^{n-1}, k) = \sum_{i=0}^{n-1}2^{k (n-i-1)}d_i. $$
§Worst-case complexity
$T(n, m) = O(nm)$
$M(n, m) = O(nm)$
where $T$ is time, $M$ is additional memory, $n$ is digits.count()
, and $m$ is log_base
.
§Panics
Panics if log_base
is zero.
§Examples
use malachite_base::num::basic::traits::{One, Two, Zero};
use malachite_base::num::conversion::traits::PowerOf2Digits;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
let digits = &[Natural::ZERO, Natural::ZERO, Natural::ZERO];
assert_eq!(
Natural::from_power_of_2_digits_desc(6, digits.iter().cloned()).to_debug_string(),
"Some(0)"
);
let digits = &[Natural::ZERO, Natural::TWO];
assert_eq!(
Natural::from_power_of_2_digits_desc(6, digits.iter().cloned()).to_debug_string(),
"Some(2)"
);
let digits = &[Natural::ONE, Natural::from(7u32), Natural::from(3u32)];
assert_eq!(
Natural::from_power_of_2_digits_desc(3, digits.iter().cloned()).to_debug_string(),
"Some(123)"
);
let digits = &[Natural::from(100u32)];
assert_eq!(
Natural::from_power_of_2_digits_desc(3, digits.iter().cloned()).to_debug_string(),
"None"
);
source§impl PowerOf2Digits<u128> for Natural
impl PowerOf2Digits<u128> for Natural
source§fn to_power_of_2_digits_asc(&self, log_base: u64) -> Vec<u128>
fn to_power_of_2_digits_asc(&self, log_base: u64) -> Vec<u128>
Returns a Vec
containing the base-$2^k$ digits of a Natural
in ascending
order: least- to most-significant.
The base-2 logarithm of the base is specified. Each digit has primitive integer
type, and log_base
must be no larger than the width of that type. If the
Natural
is 0, the Vec
is empty; otherwise, it ends with a nonzero digit.
$f(x, k) = (d_i)_ {i=0}^{n-1}$, where $0 \leq d_i < 2^k$ for all $i$, $n=0$ or $d_{n-1} \neq 0$, and
$$ \sum_{i=0}^{n-1}2^{ki}d_i = x. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if log_base
is greater than the width of the digit type, or if log_base
is zero.
§Examples
See here.
source§fn to_power_of_2_digits_desc(&self, log_base: u64) -> Vec<u128>
fn to_power_of_2_digits_desc(&self, log_base: u64) -> Vec<u128>
Returns a Vec
containing the base-$2^k$ digits of a Natural
in descending
order: most- to least-significant.
The base-2 logarithm of the base is specified. Each digit has primitive integer
type, and log_base
must be no larger than the width of that type. If the
Natural
is 0, the Vec
is empty; otherwise, it begins with a nonzero digit.
$f(x, k) = (d_i)_ {i=0}^{n-1}$, where $0 \leq d_i < 2^k$ for all $i$, $n=0$ or $d_0 \neq 0$, and
$$ \sum_{i=0}^{n-1}2^{k (n-i-1)}d_i = x. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if log_base
is greater than the width of the digit type, or if log_base
is zero.
§Examples
See here.
source§fn from_power_of_2_digits_asc<I: Iterator<Item = u128>>(
log_base: u64,
digits: I
) -> Option<Natural>
fn from_power_of_2_digits_asc<I: Iterator<Item = u128>>( log_base: u64, digits: I ) -> Option<Natural>
Converts an iterator of base-$2^k$ digits into a Natural
.
The base-2 logarithm of the base is specified. The input digits are in ascending
order: least- to most-significant. Each digit has primitive integer type, and
log_base
must be no larger than the width of that type.
If some digit is greater than $2^k$, None
is returned.
$$ f((d_i)_ {i=0}^{n-1}, k) = \sum_{i=0}^{n-1}2^{ki}d_i. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is digits.count()
.
§Panics
Panics if log_base
is zero or greater than the width of the digit type.
§Examples
See here.
source§fn from_power_of_2_digits_desc<I: Iterator<Item = u128>>(
log_base: u64,
digits: I
) -> Option<Natural>
fn from_power_of_2_digits_desc<I: Iterator<Item = u128>>( log_base: u64, digits: I ) -> Option<Natural>
Converts an iterator of base-$2^k$ digits into a Natural
.
The base-2 logarithm of the base is specified. The input digits are in descending
order: most- to least-significant. Each digit has primitive integer type, and
log_base
must be no larger than the width of that type.
If some digit is greater than $2^k$, None
is returned.
$$ f((d_i)_ {i=0}^{n-1}, k) = \sum_{i=0}^{n-1}2^{k (n-i-1)}d_i. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is digits.count()
.
§Panics
Panics if log_base
is zero or greater than the width of the digit type.
§Examples
See here.
source§impl PowerOf2Digits<u16> for Natural
impl PowerOf2Digits<u16> for Natural
source§fn to_power_of_2_digits_asc(&self, log_base: u64) -> Vec<u16>
fn to_power_of_2_digits_asc(&self, log_base: u64) -> Vec<u16>
Returns a Vec
containing the base-$2^k$ digits of a Natural
in ascending
order: least- to most-significant.
The base-2 logarithm of the base is specified. Each digit has primitive integer
type, and log_base
must be no larger than the width of that type. If the
Natural
is 0, the Vec
is empty; otherwise, it ends with a nonzero digit.
$f(x, k) = (d_i)_ {i=0}^{n-1}$, where $0 \leq d_i < 2^k$ for all $i$, $n=0$ or $d_{n-1} \neq 0$, and
$$ \sum_{i=0}^{n-1}2^{ki}d_i = x. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if log_base
is greater than the width of the digit type, or if log_base
is zero.
§Examples
See here.
source§fn to_power_of_2_digits_desc(&self, log_base: u64) -> Vec<u16>
fn to_power_of_2_digits_desc(&self, log_base: u64) -> Vec<u16>
Returns a Vec
containing the base-$2^k$ digits of a Natural
in descending
order: most- to least-significant.
The base-2 logarithm of the base is specified. Each digit has primitive integer
type, and log_base
must be no larger than the width of that type. If the
Natural
is 0, the Vec
is empty; otherwise, it begins with a nonzero digit.
$f(x, k) = (d_i)_ {i=0}^{n-1}$, where $0 \leq d_i < 2^k$ for all $i$, $n=0$ or $d_0 \neq 0$, and
$$ \sum_{i=0}^{n-1}2^{k (n-i-1)}d_i = x. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if log_base
is greater than the width of the digit type, or if log_base
is zero.
§Examples
See here.
source§fn from_power_of_2_digits_asc<I: Iterator<Item = u16>>(
log_base: u64,
digits: I
) -> Option<Natural>
fn from_power_of_2_digits_asc<I: Iterator<Item = u16>>( log_base: u64, digits: I ) -> Option<Natural>
Converts an iterator of base-$2^k$ digits into a Natural
.
The base-2 logarithm of the base is specified. The input digits are in ascending
order: least- to most-significant. Each digit has primitive integer type, and
log_base
must be no larger than the width of that type.
If some digit is greater than $2^k$, None
is returned.
$$ f((d_i)_ {i=0}^{n-1}, k) = \sum_{i=0}^{n-1}2^{ki}d_i. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is digits.count()
.
§Panics
Panics if log_base
is zero or greater than the width of the digit type.
§Examples
See here.
source§fn from_power_of_2_digits_desc<I: Iterator<Item = u16>>(
log_base: u64,
digits: I
) -> Option<Natural>
fn from_power_of_2_digits_desc<I: Iterator<Item = u16>>( log_base: u64, digits: I ) -> Option<Natural>
Converts an iterator of base-$2^k$ digits into a Natural
.
The base-2 logarithm of the base is specified. The input digits are in descending
order: most- to least-significant. Each digit has primitive integer type, and
log_base
must be no larger than the width of that type.
If some digit is greater than $2^k$, None
is returned.
$$ f((d_i)_ {i=0}^{n-1}, k) = \sum_{i=0}^{n-1}2^{k (n-i-1)}d_i. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is digits.count()
.
§Panics
Panics if log_base
is zero or greater than the width of the digit type.
§Examples
See here.
source§impl PowerOf2Digits<u32> for Natural
impl PowerOf2Digits<u32> for Natural
source§fn to_power_of_2_digits_asc(&self, log_base: u64) -> Vec<u32>
fn to_power_of_2_digits_asc(&self, log_base: u64) -> Vec<u32>
Returns a Vec
containing the base-$2^k$ digits of a Natural
in ascending
order: least- to most-significant.
The base-2 logarithm of the base is specified. Each digit has primitive integer
type, and log_base
must be no larger than the width of that type. If the
Natural
is 0, the Vec
is empty; otherwise, it ends with a nonzero digit.
$f(x, k) = (d_i)_ {i=0}^{n-1}$, where $0 \leq d_i < 2^k$ for all $i$, $n=0$ or $d_{n-1} \neq 0$, and
$$ \sum_{i=0}^{n-1}2^{ki}d_i = x. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if log_base
is greater than the width of the digit type, or if log_base
is zero.
§Examples
See here.
source§fn to_power_of_2_digits_desc(&self, log_base: u64) -> Vec<u32>
fn to_power_of_2_digits_desc(&self, log_base: u64) -> Vec<u32>
Returns a Vec
containing the base-$2^k$ digits of a Natural
in descending
order: most- to least-significant.
The base-2 logarithm of the base is specified. Each digit has primitive integer
type, and log_base
must be no larger than the width of that type. If the
Natural
is 0, the Vec
is empty; otherwise, it begins with a nonzero digit.
$f(x, k) = (d_i)_ {i=0}^{n-1}$, where $0 \leq d_i < 2^k$ for all $i$, $n=0$ or $d_0 \neq 0$, and
$$ \sum_{i=0}^{n-1}2^{k (n-i-1)}d_i = x. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if log_base
is greater than the width of the digit type, or if log_base
is zero.
§Examples
See here.
source§fn from_power_of_2_digits_asc<I: Iterator<Item = u32>>(
log_base: u64,
digits: I
) -> Option<Natural>
fn from_power_of_2_digits_asc<I: Iterator<Item = u32>>( log_base: u64, digits: I ) -> Option<Natural>
Converts an iterator of base-$2^k$ digits into a Natural
.
The base-2 logarithm of the base is specified. The input digits are in ascending
order: least- to most-significant. Each digit has primitive integer type, and
log_base
must be no larger than the width of that type.
If some digit is greater than $2^k$, None
is returned.
$$ f((d_i)_ {i=0}^{n-1}, k) = \sum_{i=0}^{n-1}2^{ki}d_i. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is digits.count()
.
§Panics
Panics if log_base
is zero or greater than the width of the digit type.
§Examples
See here.
source§fn from_power_of_2_digits_desc<I: Iterator<Item = u32>>(
log_base: u64,
digits: I
) -> Option<Natural>
fn from_power_of_2_digits_desc<I: Iterator<Item = u32>>( log_base: u64, digits: I ) -> Option<Natural>
Converts an iterator of base-$2^k$ digits into a Natural
.
The base-2 logarithm of the base is specified. The input digits are in descending
order: most- to least-significant. Each digit has primitive integer type, and
log_base
must be no larger than the width of that type.
If some digit is greater than $2^k$, None
is returned.
$$ f((d_i)_ {i=0}^{n-1}, k) = \sum_{i=0}^{n-1}2^{k (n-i-1)}d_i. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is digits.count()
.
§Panics
Panics if log_base
is zero or greater than the width of the digit type.
§Examples
See here.
source§impl PowerOf2Digits<u64> for Natural
impl PowerOf2Digits<u64> for Natural
source§fn to_power_of_2_digits_asc(&self, log_base: u64) -> Vec<u64>
fn to_power_of_2_digits_asc(&self, log_base: u64) -> Vec<u64>
Returns a Vec
containing the base-$2^k$ digits of a Natural
in ascending
order: least- to most-significant.
The base-2 logarithm of the base is specified. Each digit has primitive integer
type, and log_base
must be no larger than the width of that type. If the
Natural
is 0, the Vec
is empty; otherwise, it ends with a nonzero digit.
$f(x, k) = (d_i)_ {i=0}^{n-1}$, where $0 \leq d_i < 2^k$ for all $i$, $n=0$ or $d_{n-1} \neq 0$, and
$$ \sum_{i=0}^{n-1}2^{ki}d_i = x. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if log_base
is greater than the width of the digit type, or if log_base
is zero.
§Examples
See here.
source§fn to_power_of_2_digits_desc(&self, log_base: u64) -> Vec<u64>
fn to_power_of_2_digits_desc(&self, log_base: u64) -> Vec<u64>
Returns a Vec
containing the base-$2^k$ digits of a Natural
in descending
order: most- to least-significant.
The base-2 logarithm of the base is specified. Each digit has primitive integer
type, and log_base
must be no larger than the width of that type. If the
Natural
is 0, the Vec
is empty; otherwise, it begins with a nonzero digit.
$f(x, k) = (d_i)_ {i=0}^{n-1}$, where $0 \leq d_i < 2^k$ for all $i$, $n=0$ or $d_0 \neq 0$, and
$$ \sum_{i=0}^{n-1}2^{k (n-i-1)}d_i = x. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if log_base
is greater than the width of the digit type, or if log_base
is zero.
§Examples
See here.
source§fn from_power_of_2_digits_asc<I: Iterator<Item = u64>>(
log_base: u64,
digits: I
) -> Option<Natural>
fn from_power_of_2_digits_asc<I: Iterator<Item = u64>>( log_base: u64, digits: I ) -> Option<Natural>
Converts an iterator of base-$2^k$ digits into a Natural
.
The base-2 logarithm of the base is specified. The input digits are in ascending
order: least- to most-significant. Each digit has primitive integer type, and
log_base
must be no larger than the width of that type.
If some digit is greater than $2^k$, None
is returned.
$$ f((d_i)_ {i=0}^{n-1}, k) = \sum_{i=0}^{n-1}2^{ki}d_i. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is digits.count()
.
§Panics
Panics if log_base
is zero or greater than the width of the digit type.
§Examples
See here.
source§fn from_power_of_2_digits_desc<I: Iterator<Item = u64>>(
log_base: u64,
digits: I
) -> Option<Natural>
fn from_power_of_2_digits_desc<I: Iterator<Item = u64>>( log_base: u64, digits: I ) -> Option<Natural>
Converts an iterator of base-$2^k$ digits into a Natural
.
The base-2 logarithm of the base is specified. The input digits are in descending
order: most- to least-significant. Each digit has primitive integer type, and
log_base
must be no larger than the width of that type.
If some digit is greater than $2^k$, None
is returned.
$$ f((d_i)_ {i=0}^{n-1}, k) = \sum_{i=0}^{n-1}2^{k (n-i-1)}d_i. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is digits.count()
.
§Panics
Panics if log_base
is zero or greater than the width of the digit type.
§Examples
See here.
source§impl PowerOf2Digits<u8> for Natural
impl PowerOf2Digits<u8> for Natural
source§fn to_power_of_2_digits_asc(&self, log_base: u64) -> Vec<u8>
fn to_power_of_2_digits_asc(&self, log_base: u64) -> Vec<u8>
Returns a Vec
containing the base-$2^k$ digits of a Natural
in ascending
order: least- to most-significant.
The base-2 logarithm of the base is specified. Each digit has primitive integer
type, and log_base
must be no larger than the width of that type. If the
Natural
is 0, the Vec
is empty; otherwise, it ends with a nonzero digit.
$f(x, k) = (d_i)_ {i=0}^{n-1}$, where $0 \leq d_i < 2^k$ for all $i$, $n=0$ or $d_{n-1} \neq 0$, and
$$ \sum_{i=0}^{n-1}2^{ki}d_i = x. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if log_base
is greater than the width of the digit type, or if log_base
is zero.
§Examples
See here.
source§fn to_power_of_2_digits_desc(&self, log_base: u64) -> Vec<u8>
fn to_power_of_2_digits_desc(&self, log_base: u64) -> Vec<u8>
Returns a Vec
containing the base-$2^k$ digits of a Natural
in descending
order: most- to least-significant.
The base-2 logarithm of the base is specified. Each digit has primitive integer
type, and log_base
must be no larger than the width of that type. If the
Natural
is 0, the Vec
is empty; otherwise, it begins with a nonzero digit.
$f(x, k) = (d_i)_ {i=0}^{n-1}$, where $0 \leq d_i < 2^k$ for all $i$, $n=0$ or $d_0 \neq 0$, and
$$ \sum_{i=0}^{n-1}2^{k (n-i-1)}d_i = x. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if log_base
is greater than the width of the digit type, or if log_base
is zero.
§Examples
See here.
source§fn from_power_of_2_digits_asc<I: Iterator<Item = u8>>(
log_base: u64,
digits: I
) -> Option<Natural>
fn from_power_of_2_digits_asc<I: Iterator<Item = u8>>( log_base: u64, digits: I ) -> Option<Natural>
Converts an iterator of base-$2^k$ digits into a Natural
.
The base-2 logarithm of the base is specified. The input digits are in ascending
order: least- to most-significant. Each digit has primitive integer type, and
log_base
must be no larger than the width of that type.
If some digit is greater than $2^k$, None
is returned.
$$ f((d_i)_ {i=0}^{n-1}, k) = \sum_{i=0}^{n-1}2^{ki}d_i. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is digits.count()
.
§Panics
Panics if log_base
is zero or greater than the width of the digit type.
§Examples
See here.
source§fn from_power_of_2_digits_desc<I: Iterator<Item = u8>>(
log_base: u64,
digits: I
) -> Option<Natural>
fn from_power_of_2_digits_desc<I: Iterator<Item = u8>>( log_base: u64, digits: I ) -> Option<Natural>
Converts an iterator of base-$2^k$ digits into a Natural
.
The base-2 logarithm of the base is specified. The input digits are in descending
order: most- to least-significant. Each digit has primitive integer type, and
log_base
must be no larger than the width of that type.
If some digit is greater than $2^k$, None
is returned.
$$ f((d_i)_ {i=0}^{n-1}, k) = \sum_{i=0}^{n-1}2^{k (n-i-1)}d_i. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is digits.count()
.
§Panics
Panics if log_base
is zero or greater than the width of the digit type.
§Examples
See here.
source§impl PowerOf2Digits<usize> for Natural
impl PowerOf2Digits<usize> for Natural
source§fn to_power_of_2_digits_asc(&self, log_base: u64) -> Vec<usize>
fn to_power_of_2_digits_asc(&self, log_base: u64) -> Vec<usize>
Returns a Vec
containing the base-$2^k$ digits of a Natural
in ascending
order: least- to most-significant.
The base-2 logarithm of the base is specified. Each digit has primitive integer
type, and log_base
must be no larger than the width of that type. If the
Natural
is 0, the Vec
is empty; otherwise, it ends with a nonzero digit.
$f(x, k) = (d_i)_ {i=0}^{n-1}$, where $0 \leq d_i < 2^k$ for all $i$, $n=0$ or $d_{n-1} \neq 0$, and
$$ \sum_{i=0}^{n-1}2^{ki}d_i = x. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if log_base
is greater than the width of the digit type, or if log_base
is zero.
§Examples
See here.
source§fn to_power_of_2_digits_desc(&self, log_base: u64) -> Vec<usize>
fn to_power_of_2_digits_desc(&self, log_base: u64) -> Vec<usize>
Returns a Vec
containing the base-$2^k$ digits of a Natural
in descending
order: most- to least-significant.
The base-2 logarithm of the base is specified. Each digit has primitive integer
type, and log_base
must be no larger than the width of that type. If the
Natural
is 0, the Vec
is empty; otherwise, it begins with a nonzero digit.
$f(x, k) = (d_i)_ {i=0}^{n-1}$, where $0 \leq d_i < 2^k$ for all $i$, $n=0$ or $d_0 \neq 0$, and
$$ \sum_{i=0}^{n-1}2^{k (n-i-1)}d_i = x. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if log_base
is greater than the width of the digit type, or if log_base
is zero.
§Examples
See here.
source§fn from_power_of_2_digits_asc<I: Iterator<Item = usize>>(
log_base: u64,
digits: I
) -> Option<Natural>
fn from_power_of_2_digits_asc<I: Iterator<Item = usize>>( log_base: u64, digits: I ) -> Option<Natural>
Converts an iterator of base-$2^k$ digits into a Natural
.
The base-2 logarithm of the base is specified. The input digits are in ascending
order: least- to most-significant. Each digit has primitive integer type, and
log_base
must be no larger than the width of that type.
If some digit is greater than $2^k$, None
is returned.
$$ f((d_i)_ {i=0}^{n-1}, k) = \sum_{i=0}^{n-1}2^{ki}d_i. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is digits.count()
.
§Panics
Panics if log_base
is zero or greater than the width of the digit type.
§Examples
See here.
source§fn from_power_of_2_digits_desc<I: Iterator<Item = usize>>(
log_base: u64,
digits: I
) -> Option<Natural>
fn from_power_of_2_digits_desc<I: Iterator<Item = usize>>( log_base: u64, digits: I ) -> Option<Natural>
Converts an iterator of base-$2^k$ digits into a Natural
.
The base-2 logarithm of the base is specified. The input digits are in descending
order: most- to least-significant. Each digit has primitive integer type, and
log_base
must be no larger than the width of that type.
If some digit is greater than $2^k$, None
is returned.
$$ f((d_i)_ {i=0}^{n-1}, k) = \sum_{i=0}^{n-1}2^{k (n-i-1)}d_i. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is digits.count()
.
§Panics
Panics if log_base
is zero or greater than the width of the digit type.
§Examples
See here.
source§impl Primes for Natural
impl Primes for Natural
source§fn primes_less_than(n: &Natural) -> NaturalPrimesLessThanIterator ⓘ
fn primes_less_than(n: &Natural) -> NaturalPrimesLessThanIterator ⓘ
Returns an iterator that generates all primes less than a given value.
The iterator produced by primes_less_than(n)
generates the same primes as the iterator
produced by primes().take_while(|&p| p < n)
, but the latter would be slower because it
doesn’t know in advance how large its prime sieve should be, and might have to create larger
and larger prime sieves.
§Worst-case complexity (amortized)
$T(i) = O(\log \log i)$
$M(i) = O(1)$
where $T$ is time, $M$ is additional memory, and $i$ is the iteration index.
§Examples
See here.
source§fn primes_less_than_or_equal_to(n: &Natural) -> NaturalPrimesLessThanIterator ⓘ
fn primes_less_than_or_equal_to(n: &Natural) -> NaturalPrimesLessThanIterator ⓘ
Returns an iterator that generates all primes less than or equal to a given value.
The iterator produced by primes_less_than_or_equal_to(n)
generates the same primes as the
iterator produced by primes().take_while(|&p| p <= n)
, but the latter would be slower
because it doesn’t know in advance how large its prime sieve should be, and might have to
create larger and larger prime sieves.
§Worst-case complexity (amortized)
$T(i) = O(\log \log i)$
$M(i) = O(1)$
where $T$ is time, $M$ is additional memory, and $i$ is the iteration index.
§Examples
See here.
source§fn primes() -> NaturalPrimesIterator ⓘ
fn primes() -> NaturalPrimesIterator ⓘ
type I = NaturalPrimesIterator
type LI = NaturalPrimesLessThanIterator
source§impl Primorial for Natural
impl Primorial for Natural
source§fn primorial(n: u64) -> Natural
fn primorial(n: u64) -> Natural
Computes the primorial of a Natural
: the product of all primes less than or equal to it.
The product_of_first_n_primes
function is similar;
it computes the primorial of the $n$th prime.
$$ f(n) = n\# =prod_{pleq natop p\text {prime}} p. $$
$n\# = O(e^{(1+o(1))n})$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
§Examples
use malachite_base::num::arithmetic::traits::Primorial;
use malachite_nz::natural::Natural;
assert_eq!(Natural::primorial(0), 1);
assert_eq!(Natural::primorial(1), 1);
assert_eq!(Natural::primorial(2), 2);
assert_eq!(Natural::primorial(3), 6);
assert_eq!(Natural::primorial(4), 6);
assert_eq!(Natural::primorial(5), 30);
assert_eq!(Natural::primorial(100).to_string(), "2305567963945518424753102147331756070");
This is equivalent to mpz_primorial_ui
from mpz/primorial_ui.c
, GMP 6.2.1.
source§fn product_of_first_n_primes(n: u64) -> Natural
fn product_of_first_n_primes(n: u64) -> Natural
Computes the product of the first $n$ primes.
The primorial
function is similar; it computes the product of all
primes less than or equal to $n$.
$$ f(n) = p_n\# = \prod_{k=1}^n p_n, $$ where $p_n$ is the $n$th prime number.
$p_n\# = O\left (\left (\frac{1}{e}k\log k\left (\frac{\log k}{e^2}k \right )^{1/\log k}\right )^k\omega(1)\right )$.
This asymptotic approximation is due to Bart Michels.
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
§Examples
use malachite_base::num::arithmetic::traits::Primorial;
use malachite_nz::natural::Natural;
assert_eq!(Natural::product_of_first_n_primes(0), 1);
assert_eq!(Natural::product_of_first_n_primes(1), 2);
assert_eq!(Natural::product_of_first_n_primes(2), 6);
assert_eq!(Natural::product_of_first_n_primes(3), 30);
assert_eq!(Natural::product_of_first_n_primes(4), 210);
assert_eq!(Natural::product_of_first_n_primes(5), 2310);
assert_eq!(
Natural::product_of_first_n_primes(100).to_string(),
"4711930799906184953162487834760260422020574773409675520188634839616415335845034221205\
28925670554468197243910409777715799180438028421831503871944494399049257903072063599053\
8452312528339864352999310398481791730017201031090"
);
source§impl<'a> Product<&'a Natural> for Natural
impl<'a> Product<&'a Natural> for Natural
source§fn product<I>(xs: I) -> Natural
fn product<I>(xs: I) -> Natural
Multiplies together all the Natural
s in an iterator of Natural
references.
$$ f((x_i)_ {i=0}^{n-1}) = \prod_ {i=0}^{n-1} x_i. $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is
Natural::sum(xs.map(Natural::significant_bits))
.
§Examples
use malachite_base::vecs::vec_from_str;
use malachite_nz::natural::Natural;
use core::iter::Product;
assert_eq!(Natural::product(vec_from_str::<Natural>("[2, 3, 5, 7]").unwrap().iter()), 210);
source§impl Product for Natural
impl Product for Natural
source§fn product<I>(xs: I) -> Natural
fn product<I>(xs: I) -> Natural
Multiplies together all the Natural
s in an iterator.
$$ f((x_i)_ {i=0}^{n-1}) = \prod_ {i=0}^{n-1} x_i. $$
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is
Natural::sum(xs.map(Natural::significant_bits))
.
§Examples
use malachite_base::vecs::vec_from_str;
use malachite_nz::natural::Natural;
use core::iter::Product;
assert_eq!(
Natural::product(vec_from_str::<Natural>("[2, 3, 5, 7]").unwrap().into_iter()),
210
);
source§impl<'a, 'b> Rem<&'b Natural> for &'a Natural
impl<'a, 'b> Rem<&'b Natural> for &'a Natural
source§fn rem(self, other: &'b Natural) -> Natural
fn rem(self, other: &'b Natural) -> Natural
Divides a Natural
by another Natural
, taking both by reference and returning just
the remainder.
If the quotient were computed, the quotient and remainder would satisfy $x = qy + r$ and $0 \leq r < y$.
$$ f(x, y) = x - y\left \lfloor \frac{x}{y} \right \rfloor. $$
For Natural
s, rem
is equivalent to mod_op
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 2 * 10 + 3 = 23
assert_eq!(&Natural::from(23u32) % &Natural::from(10u32), 3);
// 810000006723 * 1234567890987 + 530068894399 = 1000000000000000000000000
assert_eq!(
&Natural::from_str("1000000000000000000000000").unwrap() %
&Natural::from_str("1234567890987").unwrap(),
530068894399u64
);
source§impl<'a> Rem<&'a Natural> for Natural
impl<'a> Rem<&'a Natural> for Natural
source§fn rem(self, other: &'a Natural) -> Natural
fn rem(self, other: &'a Natural) -> Natural
Divides a Natural
by another Natural
, taking the first by value and the second by
reference and returning just the remainder.
If the quotient were computed, the quotient and remainder would satisfy $x = qy + r$ and $0 \leq r < y$.
$$ f(x, y) = x - y\left \lfloor \frac{x}{y} \right \rfloor. $$
For Natural
s, rem
is equivalent to mod_op
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 2 * 10 + 3 = 23
assert_eq!(Natural::from(23u32) % &Natural::from(10u32), 3);
// 810000006723 * 1234567890987 + 530068894399 = 1000000000000000000000000
assert_eq!(
Natural::from_str("1000000000000000000000000").unwrap() %
&Natural::from_str("1234567890987").unwrap(),
530068894399u64
);
source§impl<'a> Rem<Natural> for &'a Natural
impl<'a> Rem<Natural> for &'a Natural
source§fn rem(self, other: Natural) -> Natural
fn rem(self, other: Natural) -> Natural
Divides a Natural
by another Natural
, taking the first by reference and the second
by value and returning just the remainder.
If the quotient were computed, the quotient and remainder would satisfy $x = qy + r$ and $0 \leq r < y$.
$$ f(x, y) = x - y\left \lfloor \frac{x}{y} \right \rfloor. $$
For Natural
s, rem
is equivalent to mod_op
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 2 * 10 + 3 = 23
assert_eq!(&Natural::from(23u32) % Natural::from(10u32), 3);
// 810000006723 * 1234567890987 + 530068894399 = 1000000000000000000000000
assert_eq!(
&Natural::from_str("1000000000000000000000000").unwrap() %
Natural::from_str("1234567890987").unwrap(),
530068894399u64
);
source§impl Rem for Natural
impl Rem for Natural
source§fn rem(self, other: Natural) -> Natural
fn rem(self, other: Natural) -> Natural
Divides a Natural
by another Natural
, taking both by value and returning just the
remainder.
If the quotient were computed, the quotient and remainder would satisfy $x = qy + r$ and $0 \leq r < y$.
$$ f(x, y) = x - y\left \lfloor \frac{x}{y} \right \rfloor. $$
For Natural
s, rem
is equivalent to mod_op
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 2 * 10 + 3 = 23
assert_eq!(Natural::from(23u32) % Natural::from(10u32), 3);
// 810000006723 * 1234567890987 + 530068894399 = 1000000000000000000000000
assert_eq!(
Natural::from_str("1000000000000000000000000").unwrap() %
Natural::from_str("1234567890987").unwrap(),
530068894399u64
);
source§impl<'a> RemAssign<&'a Natural> for Natural
impl<'a> RemAssign<&'a Natural> for Natural
source§fn rem_assign(&mut self, other: &'a Natural)
fn rem_assign(&mut self, other: &'a Natural)
Divides a Natural
by another Natural
, taking the second Natural
by reference and
replacing the first by the remainder.
If the quotient were computed, he quotient and remainder would satisfy $x = qy + r$ and $0 \leq r < y$.
$$ x \gets x - y\left \lfloor \frac{x}{y} \right \rfloor. $$
For Natural
s, rem_assign
is equivalent to mod_assign
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 2 * 10 + 3 = 23
let mut x = Natural::from(23u32);
x %= &Natural::from(10u32);
assert_eq!(x, 3);
// 810000006723 * 1234567890987 + 530068894399 = 1000000000000000000000000
let mut x = Natural::from_str("1000000000000000000000000").unwrap();
x %= &Natural::from_str("1234567890987").unwrap();
assert_eq!(x, 530068894399u64);
source§impl RemAssign for Natural
impl RemAssign for Natural
source§fn rem_assign(&mut self, other: Natural)
fn rem_assign(&mut self, other: Natural)
Divides a Natural
by another Natural
, taking the second Natural
by value and
replacing the first by the remainder.
If the quotient were computed, he quotient and remainder would satisfy $x = qy + r$ and $0 \leq r < y$.
$$ x \gets x - y\left \lfloor \frac{x}{y} \right \rfloor. $$
For Natural
s, rem_assign
is equivalent to mod_assign
.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is zero.
§Examples
use malachite_nz::natural::Natural;
use core::str::FromStr;
// 2 * 10 + 3 = 23
let mut x = Natural::from(23u32);
x %= Natural::from(10u32);
assert_eq!(x, 3);
// 810000006723 * 1234567890987 + 530068894399 = 1000000000000000000000000
let mut x = Natural::from_str("1000000000000000000000000").unwrap();
x %= Natural::from_str("1234567890987").unwrap();
assert_eq!(x, 530068894399u64);
source§impl<'a> RemPowerOf2 for &'a Natural
impl<'a> RemPowerOf2 for &'a Natural
source§fn rem_power_of_2(self, pow: u64) -> Natural
fn rem_power_of_2(self, pow: u64) -> Natural
Divides a Natural
by $2^k$, returning just the remainder. The Natural
is taken by
reference.
If the quotient were computed, the quotient and remainder would satisfy $x = q2^k + r$ and $0 \leq r < 2^k$.
$$ f(x, k) = x - 2^k\left \lfloor \frac{x}{2^k} \right \rfloor. $$
For Natural
s, rem_power_of_2
is equivalent to
mod_power_of_2
.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is pow
.
§Examples
use malachite_base::num::arithmetic::traits::RemPowerOf2;
use malachite_nz::natural::Natural;
// 1 * 2^8 + 4 = 260
assert_eq!((&Natural::from(260u32)).rem_power_of_2(8), 4);
// 100 * 2^4 + 11 = 1611
assert_eq!((&Natural::from(1611u32)).rem_power_of_2(4), 11);
type Output = Natural
source§impl RemPowerOf2 for Natural
impl RemPowerOf2 for Natural
source§fn rem_power_of_2(self, pow: u64) -> Natural
fn rem_power_of_2(self, pow: u64) -> Natural
Divides a Natural
by $2^k$, returning just the remainder. The Natural
is taken by
value.
If the quotient were computed, the quotient and remainder would satisfy $x = q2^k + r$ and $0 \leq r < 2^k$.
$$ f(x, k) = x - 2^k\left \lfloor \frac{x}{2^k} \right \rfloor. $$
For Natural
s, rem_power_of_2
is equivalent to
mod_power_of_2
.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::arithmetic::traits::RemPowerOf2;
use malachite_nz::natural::Natural;
// 1 * 2^8 + 4 = 260
assert_eq!(Natural::from(260u32).rem_power_of_2(8), 4);
// 100 * 2^4 + 11 = 1611
assert_eq!(Natural::from(1611u32).rem_power_of_2(4), 11);
type Output = Natural
source§impl RemPowerOf2Assign for Natural
impl RemPowerOf2Assign for Natural
source§fn rem_power_of_2_assign(&mut self, pow: u64)
fn rem_power_of_2_assign(&mut self, pow: u64)
Divides a Natural
by $2^k$, replacing the first Natural
by the remainder.
If the quotient were computed, the quotient and remainder would satisfy $x = q2^k + r$ and $0 \leq r < 2^k$.
$$ x \gets x - 2^k\left \lfloor \frac{x}{2^k} \right \rfloor. $$
For Natural
s, rem_power_of_2_assign
is equivalent to
mod_power_of_2_assign
.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::arithmetic::traits::RemPowerOf2Assign;
use malachite_nz::natural::Natural;
// 1 * 2^8 + 4 = 260
let mut x = Natural::from(260u32);
x.rem_power_of_2_assign(8);
assert_eq!(x, 4);
// 100 * 2^4 + 11 = 1611
let mut x = Natural::from(1611u32);
x.rem_power_of_2_assign(4);
assert_eq!(x, 11);
source§impl RootAssignRem<u64> for Natural
impl RootAssignRem<u64> for Natural
source§fn root_assign_rem(&mut self, exp: u64) -> Natural
fn root_assign_rem(&mut self, exp: u64) -> Natural
Replaces a Natural
with the floor of its $n$th root, and returns the remainder (the
difference between the original Natural
and the $n$th power of the floor).
$f(x, n) = x - \lfloor\sqrt[n]{x}\rfloor^n$,
$x \gets \lfloor\sqrt[n]{x}\rfloor$.
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::RootAssignRem;
use malachite_nz::natural::Natural;
let mut x = Natural::from(999u16);
assert_eq!(x.root_assign_rem(3), 270);
assert_eq!(x, 9);
let mut x = Natural::from(1000u16);
assert_eq!(x.root_assign_rem(3), 0);
assert_eq!(x, 10);
let mut x = Natural::from(1001u16);
assert_eq!(x.root_assign_rem(3), 1);
assert_eq!(x, 10);
let mut x = Natural::from(100000000000u64);
assert_eq!(x.root_assign_rem(5), 1534195232);
assert_eq!(x, 158);
type RemOutput = Natural
source§impl<'a> RootRem<u64> for &'a Natural
impl<'a> RootRem<u64> for &'a Natural
source§fn root_rem(self, exp: u64) -> (Natural, Natural)
fn root_rem(self, exp: u64) -> (Natural, Natural)
Returns the floor of the $n$th root of a Natural
, and the remainder (the difference
between the Natural
and the $n$th power of the floor). The Natural
is taken by
reference.
$f(x, n) = (\lfloor\sqrt[n]{x}\rfloor, x - \lfloor\sqrt[n]{x}\rfloor^n)$.
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::RootRem;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::from(999u16)).root_rem(3).to_debug_string(), "(9, 270)");
assert_eq!((&Natural::from(1000u16)).root_rem(3).to_debug_string(), "(10, 0)");
assert_eq!((&Natural::from(1001u16)).root_rem(3).to_debug_string(), "(10, 1)");
assert_eq!(
(&Natural::from(100000000000u64)).root_rem(5).to_debug_string(),
"(158, 1534195232)"
);
type RootOutput = Natural
type RemOutput = Natural
source§impl RootRem<u64> for Natural
impl RootRem<u64> for Natural
source§fn root_rem(self, exp: u64) -> (Natural, Natural)
fn root_rem(self, exp: u64) -> (Natural, Natural)
Returns the floor of the $n$th root of a Natural
, and the remainder (the difference
between the Natural
and the $n$th power of the floor). The Natural
is taken by
value.
$f(x, n) = (\lfloor\sqrt[n]{x}\rfloor, x - \lfloor\sqrt[n]{x}\rfloor^n)$.
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::RootRem;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(999u16).root_rem(3).to_debug_string(), "(9, 270)");
assert_eq!(Natural::from(1000u16).root_rem(3).to_debug_string(), "(10, 0)");
assert_eq!(Natural::from(1001u16).root_rem(3).to_debug_string(), "(10, 1)");
assert_eq!(
Natural::from(100000000000u64).root_rem(5).to_debug_string(),
"(158, 1534195232)"
);
type RootOutput = Natural
type RemOutput = Natural
source§impl<'a, 'b> RoundToMultiple<&'b Natural> for &'a Natural
impl<'a, 'b> RoundToMultiple<&'b Natural> for &'a Natural
source§fn round_to_multiple(
self,
other: &'b Natural,
rm: RoundingMode
) -> (Natural, Ordering)
fn round_to_multiple( self, other: &'b Natural, rm: RoundingMode ) -> (Natural, Ordering)
Rounds a Natural
to a multiple of another Natural
, according to a specified rounding
mode. Both Natural
s are taken by reference. An Ordering
is also returned, indicating
whether the returned value is less than, equal to, or greater than the original value.
Let $q = \frac{x}{y}$:
$f(x, y, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = y \lfloor q \rfloor.$
$f(x, y, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = y \lceil q \rceil.$
$$ f(x, y, \mathrm{Nearest}) = \begin{cases} y \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2} \\ y \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2} \\ y \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even} \\ y \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd.} \end{cases} $$
$f(x, y, \mathrm{Exact}) = x$, but panics if $q \notin \N$.
The following two expressions are equivalent:
x.round_to_multiple(other, RoundingMode::Exact)
{ assert!(x.divisible_by(other)); x }
but the latter should be used as it is clearer and more efficient.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
- If
rm
isExact
, butself
is not a multiple ofother
. - If
self
is nonzero,other
is zero, andrm
is trying to round away from zero.
§Examples
use malachite_base::num::arithmetic::traits::RoundToMultiple;
use malachite_base::num::basic::traits::Zero;
use malachite_base::rounding_modes::RoundingMode;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
assert_eq!(
(&Natural::from(5u32)).round_to_multiple(&Natural::ZERO, RoundingMode::Down)
.to_debug_string(),
"(0, Less)"
);
assert_eq!(
(&Natural::from(10u32)).round_to_multiple(&Natural::from(4u32), RoundingMode::Down)
.to_debug_string(),
"(8, Less)"
);
assert_eq!(
(&Natural::from(10u32)).round_to_multiple(&Natural::from(4u32), RoundingMode::Up)
.to_debug_string(),
"(12, Greater)"
);
assert_eq!(
(&Natural::from(10u32)).round_to_multiple(&Natural::from(5u32), RoundingMode::Exact)
.to_debug_string(),
"(10, Equal)"
);
assert_eq!(
(&Natural::from(10u32)).round_to_multiple(&Natural::from(3u32), RoundingMode::Nearest)
.to_debug_string(),
"(9, Less)"
);
assert_eq!(
(&Natural::from(20u32)).round_to_multiple(&Natural::from(3u32), RoundingMode::Nearest)
.to_debug_string(),
"(21, Greater)"
);
assert_eq!(
(&Natural::from(10u32)).round_to_multiple(&Natural::from(4u32), RoundingMode::Nearest)
.to_debug_string(),
"(8, Less)"
);
assert_eq!(
(&Natural::from(14u32)).round_to_multiple(&Natural::from(4u32), RoundingMode::Nearest)
.to_debug_string(),
"(16, Greater)"
);
type Output = Natural
source§impl<'a> RoundToMultiple<&'a Natural> for Natural
impl<'a> RoundToMultiple<&'a Natural> for Natural
source§fn round_to_multiple(
self,
other: &'a Natural,
rm: RoundingMode
) -> (Natural, Ordering)
fn round_to_multiple( self, other: &'a Natural, rm: RoundingMode ) -> (Natural, Ordering)
Rounds a Natural
to a multiple of another Natural
, according to a specified rounding
mode. The first Natural
is taken by value and the second by reference. An Ordering
is also returned, indicating whether the returned value is less than, equal to, or greater
than the original value.
Let $q = \frac{x}{y}$:
$f(x, y, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = y \lfloor q \rfloor.$
$f(x, y, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = y \lceil q \rceil.$
$$ f(x, y, \mathrm{Nearest}) = \begin{cases} y \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2} \\ y \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2} \\ y \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even} \\ y \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd.} \end{cases} $$
$f(x, y, \mathrm{Exact}) = x$, but panics if $q \notin \N$.
The following two expressions are equivalent:
x.round_to_multiple(other, RoundingMode::Exact)
{ assert!(x.divisible_by(other)); x }
but the latter should be used as it is clearer and more efficient.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
- If
rm
isExact
, butself
is not a multiple ofother
. - If
self
is nonzero,other
is zero, andrm
is trying to round away from zero.
§Examples
use malachite_base::num::arithmetic::traits::RoundToMultiple;
use malachite_base::num::basic::traits::Zero;
use malachite_base::rounding_modes::RoundingMode;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
assert_eq!(
Natural::from(5u32).round_to_multiple(&Natural::ZERO, RoundingMode::Down)
.to_debug_string(),
"(0, Less)"
);
assert_eq!(
Natural::from(10u32).round_to_multiple(&Natural::from(4u32), RoundingMode::Down)
.to_debug_string(),
"(8, Less)"
);
assert_eq!(
Natural::from(10u32).round_to_multiple(&Natural::from(4u32), RoundingMode::Up)
.to_debug_string(),
"(12, Greater)"
);
assert_eq!(
Natural::from(10u32).round_to_multiple(&Natural::from(5u32), RoundingMode::Exact)
.to_debug_string(),
"(10, Equal)"
);
assert_eq!(
Natural::from(10u32).round_to_multiple(&Natural::from(3u32), RoundingMode::Nearest)
.to_debug_string(),
"(9, Less)"
);
assert_eq!(
Natural::from(20u32).round_to_multiple(&Natural::from(3u32), RoundingMode::Nearest)
.to_debug_string(),
"(21, Greater)"
);
assert_eq!(
Natural::from(10u32).round_to_multiple(&Natural::from(4u32), RoundingMode::Nearest)
.to_debug_string(),
"(8, Less)"
);
assert_eq!(
Natural::from(14u32).round_to_multiple(&Natural::from(4u32), RoundingMode::Nearest)
.to_debug_string(),
"(16, Greater)"
);
type Output = Natural
source§impl<'a> RoundToMultiple<Natural> for &'a Natural
impl<'a> RoundToMultiple<Natural> for &'a Natural
source§fn round_to_multiple(
self,
other: Natural,
rm: RoundingMode
) -> (Natural, Ordering)
fn round_to_multiple( self, other: Natural, rm: RoundingMode ) -> (Natural, Ordering)
Rounds a Natural
to a multiple of another Natural
, according to a specified rounding
mode. The first Natural
is taken by reference and the second by value. An Ordering
is also returned, indicating whether the returned value is less than, equal to, or greater
than the original value.
Let $q = \frac{x}{y}$:
$f(x, y, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = y \lfloor q \rfloor.$
$f(x, y, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = y \lceil q \rceil.$
$$ f(x, y, \mathrm{Nearest}) = \begin{cases} y \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2} \\ y \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2} \\ y \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even} \\ y \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd.} \end{cases} $$
$f(x, y, \mathrm{Exact}) = x$, but panics if $q \notin \N$.
The following two expressions are equivalent:
x.round_to_multiple(other, RoundingMode::Exact)
{ assert!(x.divisible_by(other)); x }
but the latter should be used as it is clearer and more efficient.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
- If
rm
isExact
, butself
is not a multiple ofother
. - If
self
is nonzero,other
is zero, andrm
is trying to round away from zero.
§Examples
use malachite_base::num::arithmetic::traits::RoundToMultiple;
use malachite_base::num::basic::traits::Zero;
use malachite_base::rounding_modes::RoundingMode;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
assert_eq!(
(&Natural::from(5u32)).round_to_multiple(Natural::ZERO, RoundingMode::Down)
.to_debug_string(),
"(0, Less)"
);
assert_eq!(
(&Natural::from(10u32)).round_to_multiple(Natural::from(4u32), RoundingMode::Down)
.to_debug_string(),
"(8, Less)"
);
assert_eq!(
(&Natural::from(10u32)).round_to_multiple(Natural::from(4u32), RoundingMode::Up)
.to_debug_string(),
"(12, Greater)"
);
assert_eq!(
(&Natural::from(10u32)).round_to_multiple(Natural::from(5u32), RoundingMode::Exact)
.to_debug_string(),
"(10, Equal)"
);
assert_eq!(
(&Natural::from(10u32)).round_to_multiple(Natural::from(3u32), RoundingMode::Nearest)
.to_debug_string(),
"(9, Less)"
);
assert_eq!(
(&Natural::from(20u32)).round_to_multiple(Natural::from(3u32), RoundingMode::Nearest)
.to_debug_string(),
"(21, Greater)"
);
assert_eq!(
(&Natural::from(10u32)).round_to_multiple(Natural::from(4u32), RoundingMode::Nearest)
.to_debug_string(),
"(8, Less)"
);
assert_eq!(
(&Natural::from(14u32)).round_to_multiple(Natural::from(4u32), RoundingMode::Nearest)
.to_debug_string(),
"(16, Greater)"
);
type Output = Natural
source§impl RoundToMultiple for Natural
impl RoundToMultiple for Natural
source§fn round_to_multiple(
self,
other: Natural,
rm: RoundingMode
) -> (Natural, Ordering)
fn round_to_multiple( self, other: Natural, rm: RoundingMode ) -> (Natural, Ordering)
Rounds a Natural
to a multiple of another Natural
, according to a specified rounding
mode. Both Natural
s are taken by value. An Ordering
is also returned, indicating
whether the returned value is less than, equal to, or greater than the original value.
Let $q = \frac{x}{y}$:
$f(x, y, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = y \lfloor q \rfloor.$
$f(x, y, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = y \lceil q \rceil.$
$$ f(x, y, \mathrm{Nearest}) = \begin{cases} y \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2} \\ y \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2} \\ y \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even} \\ y \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd.} \end{cases} $$
$f(x, y, \mathrm{Exact}) = x$, but panics if $q \notin \N$.
The following two expressions are equivalent:
x.round_to_multiple(other, RoundingMode::Exact)
{ assert!(x.divisible_by(other)); x }
but the latter should be used as it is clearer and more efficient.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
- If
rm
isExact
, butself
is not a multiple ofother
. - If
self
is nonzero,other
is zero, andrm
is trying to round away from zero.
§Examples
use malachite_base::num::arithmetic::traits::RoundToMultiple;
use malachite_base::num::basic::traits::Zero;
use malachite_base::rounding_modes::RoundingMode;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
assert_eq!(
Natural::from(5u32).round_to_multiple(Natural::ZERO, RoundingMode::Down)
.to_debug_string(),
"(0, Less)"
);
assert_eq!(
Natural::from(10u32).round_to_multiple(Natural::from(4u32), RoundingMode::Down)
.to_debug_string(),
"(8, Less)"
);
assert_eq!(
Natural::from(10u32).round_to_multiple(Natural::from(4u32), RoundingMode::Up)
.to_debug_string(),
"(12, Greater)"
);
assert_eq!(
Natural::from(10u32).round_to_multiple(Natural::from(5u32), RoundingMode::Exact)
.to_debug_string(),
"(10, Equal)"
);
assert_eq!(
Natural::from(10u32).round_to_multiple(Natural::from(3u32), RoundingMode::Nearest)
.to_debug_string(),
"(9, Less)"
);
assert_eq!(
Natural::from(20u32).round_to_multiple(Natural::from(3u32), RoundingMode::Nearest)
.to_debug_string(),
"(21, Greater)"
);
assert_eq!(
Natural::from(10u32).round_to_multiple(Natural::from(4u32), RoundingMode::Nearest)
.to_debug_string(),
"(8, Less)"
);
assert_eq!(
Natural::from(14u32).round_to_multiple(Natural::from(4u32), RoundingMode::Nearest)
.to_debug_string(),
"(16, Greater)"
);
type Output = Natural
source§impl<'a> RoundToMultipleAssign<&'a Natural> for Natural
impl<'a> RoundToMultipleAssign<&'a Natural> for Natural
source§fn round_to_multiple_assign(
&mut self,
other: &'a Natural,
rm: RoundingMode
) -> Ordering
fn round_to_multiple_assign( &mut self, other: &'a Natural, rm: RoundingMode ) -> Ordering
Rounds a Natural
to a multiple of another Natural
in place, according to a specified
rounding mode. The Natural
on the right-hand side is taken by reference. An Ordering
is also returned, indicating whether the returned value is less than, equal to, or greater
than the original value.
See the RoundToMultiple
documentation for details.
The following two expressions are equivalent:
x.round_to_multiple_assign(other, RoundingMode::Exact);
assert!(x.divisible_by(other));
but the latter should be used as it is clearer and more efficient.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
- If
rm
isExact
, butself
is not a multiple ofother
. - If
self
is nonzero,other
is zero, andrm
is trying to round away from zero.
§Examples
use malachite_base::num::arithmetic::traits::RoundToMultipleAssign;
use malachite_base::num::basic::traits::Zero;
use malachite_base::rounding_modes::RoundingMode;
use malachite_nz::natural::Natural;
use core::cmp::Ordering;
let mut x = Natural::from(5u32);
assert_eq!(x.round_to_multiple_assign(&Natural::ZERO, RoundingMode::Down), Ordering::Less);
assert_eq!(x, 0);
let mut x = Natural::from(10u32);
assert_eq!(
x.round_to_multiple_assign(&Natural::from(4u32), RoundingMode::Down),
Ordering::Less
);
assert_eq!(x, 8);
let mut x = Natural::from(10u32);
assert_eq!(
x.round_to_multiple_assign(&Natural::from(4u32), RoundingMode::Up),
Ordering::Greater
);
assert_eq!(x, 12);
let mut x = Natural::from(10u32);
assert_eq!(
x.round_to_multiple_assign(&Natural::from(5u32), RoundingMode::Exact),
Ordering::Equal
);
assert_eq!(x, 10);
let mut x = Natural::from(10u32);
assert_eq!(
x.round_to_multiple_assign(&Natural::from(3u32), RoundingMode::Nearest),
Ordering::Less
);
assert_eq!(x, 9);
let mut x = Natural::from(20u32);
assert_eq!(
x.round_to_multiple_assign(&Natural::from(3u32), RoundingMode::Nearest),
Ordering::Greater
);
assert_eq!(x, 21);
let mut x = Natural::from(10u32);
assert_eq!(
x.round_to_multiple_assign(&Natural::from(4u32), RoundingMode::Nearest),
Ordering::Less
);
assert_eq!(x, 8);
let mut x = Natural::from(14u32);
assert_eq!(
x.round_to_multiple_assign(&Natural::from(4u32), RoundingMode::Nearest),
Ordering::Greater
);
assert_eq!(x, 16);
source§impl RoundToMultipleAssign for Natural
impl RoundToMultipleAssign for Natural
source§fn round_to_multiple_assign(
&mut self,
other: Natural,
rm: RoundingMode
) -> Ordering
fn round_to_multiple_assign( &mut self, other: Natural, rm: RoundingMode ) -> Ordering
Rounds a Natural
to a multiple of another Natural
in place, according to a specified
rounding mode. The Natural
on the right-hand side is taken by value. An Ordering
is
returned, indicating whether the returned value is less than, equal to, or greater than the
original value.
See the RoundToMultiple
documentation for details.
The following two expressions are equivalent:
x.round_to_multiple_assign(other, RoundingMode::Exact);
assert!(x.divisible_by(other));
but the latter should be used as it is clearer and more efficient.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
- If
rm
isExact
, butself
is not a multiple ofother
. - If
self
is nonzero,other
is zero, andrm
is trying to round away from zero.
§Examples
use malachite_base::num::arithmetic::traits::RoundToMultipleAssign;
use malachite_base::num::basic::traits::Zero;
use malachite_base::rounding_modes::RoundingMode;
use malachite_nz::natural::Natural;
use core::cmp::Ordering;
let mut x = Natural::from(5u32);
assert_eq!(x.round_to_multiple_assign(Natural::ZERO, RoundingMode::Down), Ordering::Less);
assert_eq!(x, 0);
let mut x = Natural::from(10u32);
assert_eq!(
x.round_to_multiple_assign(Natural::from(4u32), RoundingMode::Down),
Ordering::Less
);
assert_eq!(x, 8);
let mut x = Natural::from(10u32);
assert_eq!(
x.round_to_multiple_assign(Natural::from(4u32), RoundingMode::Up),
Ordering::Greater
);
assert_eq!(x, 12);
let mut x = Natural::from(10u32);
assert_eq!(
x.round_to_multiple_assign(Natural::from(5u32), RoundingMode::Exact),
Ordering::Equal
);
assert_eq!(x, 10);
let mut x = Natural::from(10u32);
assert_eq!(
x.round_to_multiple_assign(Natural::from(3u32), RoundingMode::Nearest),
Ordering::Less
);
assert_eq!(x, 9);
let mut x = Natural::from(20u32);
assert_eq!(
x.round_to_multiple_assign(Natural::from(3u32), RoundingMode::Nearest),
Ordering::Greater
);
assert_eq!(x, 21);
let mut x = Natural::from(10u32);
assert_eq!(
x.round_to_multiple_assign(Natural::from(4u32), RoundingMode::Nearest),
Ordering::Less
);
assert_eq!(x, 8);
let mut x = Natural::from(14u32);
assert_eq!(
x.round_to_multiple_assign(Natural::from(4u32), RoundingMode::Nearest),
Ordering::Greater
);
assert_eq!(x, 16);
source§impl<'a> RoundToMultipleOfPowerOf2<u64> for &'a Natural
impl<'a> RoundToMultipleOfPowerOf2<u64> for &'a Natural
source§fn round_to_multiple_of_power_of_2(
self,
pow: u64,
rm: RoundingMode
) -> (Natural, Ordering)
fn round_to_multiple_of_power_of_2( self, pow: u64, rm: RoundingMode ) -> (Natural, Ordering)
Rounds a Natural
to a multiple of $2^k$ according to a specified rounding mode. The
Natural
is taken by reference. An Ordering
is also returned, indicating whether the
returned value is less than, equal to, or greater than the original value.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, k, \mathrm{Floor}) = 2^k \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, k, \mathrm{Ceiling}) = 2^k \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} 2^k \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2} \\ 2^k \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2} \\ 2^k \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even} \\ 2^k \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd.} \end{cases} $$
$f(x, k, \mathrm{Exact}) = 2^k q$, but panics if $q \notin \Z$.
The following two expressions are equivalent:
x.round_to_multiple_of_power_of_2(pow, RoundingMode::Exact)
{ assert!(x.divisible_by_power_of_2(pow)); x }
but the latter should be used as it is clearer and more efficient.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), pow / Limb::WIDTH)
.
§Panics
Panics if rm
is Exact
, but self
is not a multiple of the power of 2.
§Examples
use malachite_base::num::arithmetic::traits::RoundToMultipleOfPowerOf2;
use malachite_base::rounding_modes::RoundingMode;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
assert_eq!(
(&Natural::from(10u32)).round_to_multiple_of_power_of_2(2, RoundingMode::Floor)
.to_debug_string(),
"(8, Less)"
);
assert_eq!(
(&Natural::from(10u32)).round_to_multiple_of_power_of_2(2, RoundingMode::Ceiling)
.to_debug_string(),
"(12, Greater)"
);
assert_eq!(
(&Natural::from(10u32)).round_to_multiple_of_power_of_2(2, RoundingMode::Down)
.to_debug_string(),
"(8, Less)"
);
assert_eq!(
(&Natural::from(10u32)).round_to_multiple_of_power_of_2(2, RoundingMode::Up)
.to_debug_string(),
"(12, Greater)"
);
assert_eq!(
(&Natural::from(10u32)).round_to_multiple_of_power_of_2(2, RoundingMode::Nearest)
.to_debug_string(),
"(8, Less)"
);
assert_eq!(
(&Natural::from(12u32)).round_to_multiple_of_power_of_2(2, RoundingMode::Exact)
.to_debug_string(),
"(12, Equal)"
);
type Output = Natural
source§impl RoundToMultipleOfPowerOf2<u64> for Natural
impl RoundToMultipleOfPowerOf2<u64> for Natural
source§fn round_to_multiple_of_power_of_2(
self,
pow: u64,
rm: RoundingMode
) -> (Natural, Ordering)
fn round_to_multiple_of_power_of_2( self, pow: u64, rm: RoundingMode ) -> (Natural, Ordering)
Rounds a Natural
to a multiple of $2^k$ according to a specified rounding mode. The
Natural
is taken by value. An Ordering
is also returned, indicating whether the
returned value is less than, equal to, or greater than the original value.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, k, \mathrm{Floor}) = 2^k \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, k, \mathrm{Ceiling}) = 2^k \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} 2^k \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2} \\ 2^k \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2} \\ 2^k \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even} \\ 2^k \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd.} \end{cases} $$
$f(x, k, \mathrm{Exact}) = 2^k q$, but panics if $q \notin \Z$.
The following two expressions are equivalent:
x.round_to_multiple_of_power_of_2(pow, RoundingMode::Exact)
{ assert!(x.divisible_by_power_of_2(pow)); x }
but the latter should be used as it is clearer and more efficient.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), pow / Limb::WIDTH)
.
§Panics
Panics if rm
is Exact
, but self
is not a multiple of the power of 2.
§Examples
use malachite_base::num::arithmetic::traits::RoundToMultipleOfPowerOf2;
use malachite_base::rounding_modes::RoundingMode;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
assert_eq!(
Natural::from(10u32).round_to_multiple_of_power_of_2(2, RoundingMode::Floor)
.to_debug_string(),
"(8, Less)"
);
assert_eq!(
Natural::from(10u32).round_to_multiple_of_power_of_2(2, RoundingMode::Ceiling)
.to_debug_string(),
"(12, Greater)"
);
assert_eq!(
Natural::from(10u32).round_to_multiple_of_power_of_2(2, RoundingMode::Down)
.to_debug_string(),
"(8, Less)"
);
assert_eq!(
Natural::from(10u32).round_to_multiple_of_power_of_2(2, RoundingMode::Up)
.to_debug_string(),
"(12, Greater)"
);
assert_eq!(
Natural::from(10u32).round_to_multiple_of_power_of_2(2, RoundingMode::Nearest)
.to_debug_string(),
"(8, Less)"
);
assert_eq!(
Natural::from(12u32).round_to_multiple_of_power_of_2(2, RoundingMode::Exact)
.to_debug_string(),
"(12, Equal)"
);
type Output = Natural
source§impl RoundToMultipleOfPowerOf2Assign<u64> for Natural
impl RoundToMultipleOfPowerOf2Assign<u64> for Natural
source§fn round_to_multiple_of_power_of_2_assign(
&mut self,
pow: u64,
rm: RoundingMode
) -> Ordering
fn round_to_multiple_of_power_of_2_assign( &mut self, pow: u64, rm: RoundingMode ) -> Ordering
Rounds a Natural
to a multiple of $2^k$ in place, according to a specified rounding
mode. An Ordering
is returned, indicating whether the returned value is less than, equal
to, or greater than the original value.
See the RoundToMultipleOfPowerOf2
documentation for details.
The following two expressions are equivalent:
x.round_to_multiple_of_power_of_2_assign(pow, RoundingMode::Exact);
assert!(x.divisible_by_power_of_2(pow));
but the latter should be used as it is clearer and more efficient.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), pow / Limb::WIDTH)
.
§Panics
Panics if rm
is Exact
, but self
is not a multiple of the power of 2.
§Examples
use malachite_base::num::arithmetic::traits::RoundToMultipleOfPowerOf2Assign;
use malachite_base::rounding_modes::RoundingMode;
use malachite_nz::natural::Natural;
use core::cmp::Ordering;
let mut n = Natural::from(10u32);
assert_eq!(
n.round_to_multiple_of_power_of_2_assign(2, RoundingMode::Floor),
Ordering::Less
);
assert_eq!(n, 8);
let mut n = Natural::from(10u32);
assert_eq!(
n.round_to_multiple_of_power_of_2_assign(2, RoundingMode::Ceiling),
Ordering::Greater
);
assert_eq!(n, 12);
let mut n = Natural::from(10u32);
assert_eq!(
n.round_to_multiple_of_power_of_2_assign(2, RoundingMode::Down),
Ordering::Less
);
assert_eq!(n, 8);
let mut n = Natural::from(10u32);
assert_eq!(
n.round_to_multiple_of_power_of_2_assign(2, RoundingMode::Up),
Ordering::Greater
);
assert_eq!(n, 12);
let mut n = Natural::from(10u32);
assert_eq!(
n.round_to_multiple_of_power_of_2_assign(2, RoundingMode::Nearest),
Ordering::Less
);
assert_eq!(n, 8);
let mut n = Natural::from(12u32);
assert_eq!(
n.round_to_multiple_of_power_of_2_assign(2, RoundingMode::Exact),
Ordering::Equal
);
assert_eq!(n, 12);
source§impl<'a> RoundingFrom<&'a Natural> for f32
impl<'a> RoundingFrom<&'a Natural> for f32
source§fn rounding_from(value: &'a Natural, rm: RoundingMode) -> (f32, Ordering)
fn rounding_from(value: &'a Natural, rm: RoundingMode) -> (f32, Ordering)
Converts a Natural
to a primitive float according to a specified
RoundingMode
. An Ordering
is also returned, indicating whether the returned
value is less than, equal to, or greater than the original value.
- If the rounding mode is
Floor
orDown
, the largest float less than or equal to theNatural
is returned. If theNatural
is greater than the maximum finite float, then the maximum finite float is returned. - If the rounding mode is
Ceiling
orUp
, the smallest float greater than or equal to theNatural
is returned. If theNatural
is greater than the maximum finite float, then positive infinity is returned. - If the rounding mode is
Nearest
, then the nearest float is returned. If theNatural
is exactly between two floats, the float with the zero least-significant bit in its representation is selected. If theNatural
is greater than the maximum finite float, then the maximum finite float is returned.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is value.significant_bits()
.
§Panics
Panics if the rounding mode is Exact
and value
cannot be represented exactly.
§Examples
See here.
source§impl<'a> RoundingFrom<&'a Natural> for f64
impl<'a> RoundingFrom<&'a Natural> for f64
source§fn rounding_from(value: &'a Natural, rm: RoundingMode) -> (f64, Ordering)
fn rounding_from(value: &'a Natural, rm: RoundingMode) -> (f64, Ordering)
Converts a Natural
to a primitive float according to a specified
RoundingMode
. An Ordering
is also returned, indicating whether the returned
value is less than, equal to, or greater than the original value.
- If the rounding mode is
Floor
orDown
, the largest float less than or equal to theNatural
is returned. If theNatural
is greater than the maximum finite float, then the maximum finite float is returned. - If the rounding mode is
Ceiling
orUp
, the smallest float greater than or equal to theNatural
is returned. If theNatural
is greater than the maximum finite float, then positive infinity is returned. - If the rounding mode is
Nearest
, then the nearest float is returned. If theNatural
is exactly between two floats, the float with the zero least-significant bit in its representation is selected. If theNatural
is greater than the maximum finite float, then the maximum finite float is returned.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is value.significant_bits()
.
§Panics
Panics if the rounding mode is Exact
and value
cannot be represented exactly.
§Examples
See here.
source§impl RoundingFrom<f32> for Natural
impl RoundingFrom<f32> for Natural
source§fn rounding_from(value: f32, rm: RoundingMode) -> (Self, Ordering)
fn rounding_from(value: f32, rm: RoundingMode) -> (Self, Ordering)
Converts a floating-point value to a Natural
, using the specified rounding mode.
An Ordering
is also returned, indicating whether the returned value is less
than, equal to, or greater than the original value.
The floating-point value cannot be NaN or infinite, and it cannot round to a negative integer.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is value.sci_exponent()
.
§Panics
Panics if value
is NaN or infinite, if it would round to a negative integer, or if
the rounding mode is Exact
and value
is not an integer.
§Examples
See here.
source§impl RoundingFrom<f64> for Natural
impl RoundingFrom<f64> for Natural
source§fn rounding_from(value: f64, rm: RoundingMode) -> (Self, Ordering)
fn rounding_from(value: f64, rm: RoundingMode) -> (Self, Ordering)
Converts a floating-point value to a Natural
, using the specified rounding mode.
An Ordering
is also returned, indicating whether the returned value is less
than, equal to, or greater than the original value.
The floating-point value cannot be NaN or infinite, and it cannot round to a negative integer.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is value.sci_exponent()
.
§Panics
Panics if value
is NaN or infinite, if it would round to a negative integer, or if
the rounding mode is Exact
and value
is not an integer.
§Examples
See here.
source§impl<'a> SaturatingFrom<&'a Integer> for Natural
impl<'a> SaturatingFrom<&'a Integer> for Natural
source§fn saturating_from(value: &'a Integer) -> Natural
fn saturating_from(value: &'a Integer) -> Natural
Converts an Integer
to a Natural
, taking the Natural
by reference. If the
Integer
is negative, 0 is returned.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::conversion::traits::SaturatingFrom;
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;
assert_eq!(Natural::saturating_from(&Integer::from(123)), 123);
assert_eq!(Natural::saturating_from(&Integer::from(-123)), 0);
assert_eq!(Natural::saturating_from(&Integer::from(10u32).pow(12)), 1000000000000u64);
assert_eq!(Natural::saturating_from(&-Integer::from(10u32).pow(12)), 0);
source§impl<'a> SaturatingFrom<&'a Natural> for i128
impl<'a> SaturatingFrom<&'a Natural> for i128
source§fn saturating_from(value: &Natural) -> i128
fn saturating_from(value: &Natural) -> i128
source§impl<'a> SaturatingFrom<&'a Natural> for i16
impl<'a> SaturatingFrom<&'a Natural> for i16
source§fn saturating_from(value: &Natural) -> i16
fn saturating_from(value: &Natural) -> i16
source§impl<'a> SaturatingFrom<&'a Natural> for i32
impl<'a> SaturatingFrom<&'a Natural> for i32
source§fn saturating_from(value: &Natural) -> i32
fn saturating_from(value: &Natural) -> i32
source§impl<'a> SaturatingFrom<&'a Natural> for i64
impl<'a> SaturatingFrom<&'a Natural> for i64
source§fn saturating_from(value: &Natural) -> i64
fn saturating_from(value: &Natural) -> i64
source§impl<'a> SaturatingFrom<&'a Natural> for i8
impl<'a> SaturatingFrom<&'a Natural> for i8
source§fn saturating_from(value: &Natural) -> i8
fn saturating_from(value: &Natural) -> i8
source§impl<'a> SaturatingFrom<&'a Natural> for isize
impl<'a> SaturatingFrom<&'a Natural> for isize
source§fn saturating_from(value: &Natural) -> isize
fn saturating_from(value: &Natural) -> isize
source§impl<'a> SaturatingFrom<&'a Natural> for u128
impl<'a> SaturatingFrom<&'a Natural> for u128
source§fn saturating_from(value: &Natural) -> u128
fn saturating_from(value: &Natural) -> u128
source§impl<'a> SaturatingFrom<&'a Natural> for u16
impl<'a> SaturatingFrom<&'a Natural> for u16
source§fn saturating_from(value: &Natural) -> u16
fn saturating_from(value: &Natural) -> u16
source§impl<'a> SaturatingFrom<&'a Natural> for u32
impl<'a> SaturatingFrom<&'a Natural> for u32
source§fn saturating_from(value: &Natural) -> u32
fn saturating_from(value: &Natural) -> u32
source§impl<'a> SaturatingFrom<&'a Natural> for u64
impl<'a> SaturatingFrom<&'a Natural> for u64
source§impl<'a> SaturatingFrom<&'a Natural> for u8
impl<'a> SaturatingFrom<&'a Natural> for u8
source§fn saturating_from(value: &Natural) -> u8
fn saturating_from(value: &Natural) -> u8
source§impl<'a> SaturatingFrom<&'a Natural> for usize
impl<'a> SaturatingFrom<&'a Natural> for usize
source§impl SaturatingFrom<Integer> for Natural
impl SaturatingFrom<Integer> for Natural
source§fn saturating_from(value: Integer) -> Natural
fn saturating_from(value: Integer) -> Natural
Converts an Integer
to a Natural
, taking the Natural
by value. If the
Integer
is negative, 0 is returned.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::conversion::traits::SaturatingFrom;
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;
assert_eq!(Natural::saturating_from(Integer::from(123)), 123);
assert_eq!(Natural::saturating_from(Integer::from(-123)), 0);
assert_eq!(Natural::saturating_from(Integer::from(10u32).pow(12)), 1000000000000u64);
assert_eq!(Natural::saturating_from(-Integer::from(10u32).pow(12)), 0);
source§impl SaturatingFrom<i128> for Natural
impl SaturatingFrom<i128> for Natural
source§impl SaturatingFrom<i16> for Natural
impl SaturatingFrom<i16> for Natural
source§impl SaturatingFrom<i32> for Natural
impl SaturatingFrom<i32> for Natural
source§impl SaturatingFrom<i64> for Natural
impl SaturatingFrom<i64> for Natural
source§impl SaturatingFrom<i8> for Natural
impl SaturatingFrom<i8> for Natural
source§impl SaturatingFrom<isize> for Natural
impl SaturatingFrom<isize> for Natural
source§impl<'a, 'b> SaturatingSub<&'a Natural> for &'b Natural
impl<'a, 'b> SaturatingSub<&'a Natural> for &'b Natural
source§fn saturating_sub(self, other: &'a Natural) -> Natural
fn saturating_sub(self, other: &'a Natural) -> Natural
Subtracts a Natural
by another Natural
, taking both by reference and returning 0 if
the result is negative.
$$ f(x, y) = \max(x - y, 0). $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::{Pow, SaturatingSub};
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::ZERO).saturating_sub(&Natural::from(123u32)), 0);
assert_eq!((&Natural::from(123u32)).saturating_sub(&Natural::ZERO), 123);
assert_eq!((&Natural::from(456u32)).saturating_sub(&Natural::from(123u32)), 333);
assert_eq!(
(&(Natural::from(10u32).pow(12) * Natural::from(3u32)))
.saturating_sub(&Natural::from(10u32).pow(12)),
2000000000000u64
);
type Output = Natural
source§impl<'a> SaturatingSub<&'a Natural> for Natural
impl<'a> SaturatingSub<&'a Natural> for Natural
source§fn saturating_sub(self, other: &'a Natural) -> Natural
fn saturating_sub(self, other: &'a Natural) -> Natural
Subtracts a Natural
by another Natural
, taking the first by value and the second by
reference and returning 0 if the result is negative.
$$ f(x, y) = \max(x - y, 0). $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::{Pow, SaturatingSub};
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!(Natural::ZERO.saturating_sub(&Natural::from(123u32)), 0);
assert_eq!(Natural::from(123u32).saturating_sub(&Natural::ZERO), 123);
assert_eq!(Natural::from(456u32).saturating_sub(&Natural::from(123u32)), 333);
assert_eq!(
(Natural::from(10u32).pow(12) * Natural::from(3u32))
.saturating_sub(&Natural::from(10u32).pow(12)),
2000000000000u64
);
type Output = Natural
source§impl<'a> SaturatingSub<Natural> for &'a Natural
impl<'a> SaturatingSub<Natural> for &'a Natural
source§fn saturating_sub(self, other: Natural) -> Natural
fn saturating_sub(self, other: Natural) -> Natural
Subtracts a Natural
by another Natural
, taking the first by reference and the second
by value and returning 0 if the result is negative.
$$ f(x, y) = \max(x - y, 0). $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::{Pow, SaturatingSub};
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::ZERO).saturating_sub(Natural::from(123u32)), 0);
assert_eq!((&Natural::from(123u32)).saturating_sub(Natural::ZERO), 123);
assert_eq!((&Natural::from(456u32)).saturating_sub(Natural::from(123u32)), 333);
assert_eq!(
(&(Natural::from(10u32).pow(12) * Natural::from(3u32)))
.saturating_sub(Natural::from(10u32).pow(12)),
2000000000000u64
);
type Output = Natural
source§impl SaturatingSub for Natural
impl SaturatingSub for Natural
source§fn saturating_sub(self, other: Natural) -> Natural
fn saturating_sub(self, other: Natural) -> Natural
Subtracts a Natural
by another Natural
, taking both by value and returning 0 if the
result is negative.
$$ f(x, y) = \max(x - y, 0). $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::{Pow, SaturatingSub};
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!(Natural::ZERO.saturating_sub(Natural::from(123u32)), 0);
assert_eq!(Natural::from(123u32).saturating_sub(Natural::ZERO), 123);
assert_eq!(Natural::from(456u32).saturating_sub(Natural::from(123u32)), 333);
assert_eq!(
(Natural::from(10u32).pow(12) * Natural::from(3u32))
.saturating_sub(Natural::from(10u32).pow(12)),
2000000000000u64
);
type Output = Natural
source§impl<'a> SaturatingSubAssign<&'a Natural> for Natural
impl<'a> SaturatingSubAssign<&'a Natural> for Natural
source§fn saturating_sub_assign(&mut self, other: &'a Natural)
fn saturating_sub_assign(&mut self, other: &'a Natural)
Subtracts a Natural
by another Natural
in place, taking the Natural
on the
right-hand side by reference and setting the left-hand side to 0 if the result is negative.
$$ x \gets \max(x - y, 0). $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is greater than self
.
§Examples
use malachite_base::num::arithmetic::traits::SaturatingSubAssign;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
let mut x = Natural::from(123u32);
x.saturating_sub_assign(&Natural::from(123u32));
assert_eq!(x, 0);
let mut x = Natural::from(123u32);
x.saturating_sub_assign(&Natural::ZERO);
assert_eq!(x, 123);
let mut x = Natural::from(456u32);
x.saturating_sub_assign(&Natural::from(123u32));
assert_eq!(x, 333);
let mut x = Natural::from(123u32);
x.saturating_sub_assign(&Natural::from(456u32));
assert_eq!(x, 0);
source§impl SaturatingSubAssign for Natural
impl SaturatingSubAssign for Natural
source§fn saturating_sub_assign(&mut self, other: Natural)
fn saturating_sub_assign(&mut self, other: Natural)
Subtracts a Natural
by another Natural
in place, taking the Natural
on the
right-hand side by value and setting the left-hand side to 0 if the result is negative.
$$ x \gets \max(x - y, 0). $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is greater than self
.
§Examples
use malachite_base::num::arithmetic::traits::SaturatingSubAssign;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
let mut x = Natural::from(123u32);
x.saturating_sub_assign(Natural::from(123u32));
assert_eq!(x, 0);
let mut x = Natural::from(123u32);
x.saturating_sub_assign(Natural::ZERO);
assert_eq!(x, 123);
let mut x = Natural::from(456u32);
x.saturating_sub_assign(Natural::from(123u32));
assert_eq!(x, 333);
let mut x = Natural::from(123u32);
x.saturating_sub_assign(Natural::from(456u32));
assert_eq!(x, 0);
source§impl<'a> SaturatingSubMul<&'a Natural> for Natural
impl<'a> SaturatingSubMul<&'a Natural> for Natural
source§fn saturating_sub_mul(self, y: &'a Natural, z: Natural) -> Natural
fn saturating_sub_mul(self, y: &'a Natural, z: Natural) -> Natural
Subtracts a Natural
by the product of two other Natural
s, taking the first and third
by value and the second by reference and returning 0 if the result is negative.
$$ f(x, y, z) = \max(x - yz, 0). $$
§Worst-case complexity
$T(n, m) = O(m + n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is max(y.significant_bits(), z.significant_bits())
, and $m$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::{Pow, SaturatingSubMul};
use malachite_nz::natural::Natural;
assert_eq!(
Natural::from(20u32).saturating_sub_mul(&Natural::from(3u32), Natural::from(4u32)),
8
);
assert_eq!(
Natural::from(10u32).saturating_sub_mul(&Natural::from(3u32), Natural::from(4u32)),
0
);
assert_eq!(
Natural::from(10u32).pow(12)
.saturating_sub_mul(&Natural::from(0x10000u32), Natural::from(0x10000u32)),
995705032704u64
);
type Output = Natural
source§impl<'a, 'b, 'c> SaturatingSubMul<&'b Natural, &'c Natural> for &'a Natural
impl<'a, 'b, 'c> SaturatingSubMul<&'b Natural, &'c Natural> for &'a Natural
source§fn saturating_sub_mul(self, y: &'b Natural, z: &'c Natural) -> Natural
fn saturating_sub_mul(self, y: &'b Natural, z: &'c Natural) -> Natural
Subtracts a Natural
by the product of two other Natural
s, taking all three by
reference and returning 0 if the result is negative.
$$ f(x, y, z) = \max(x - yz, 0). $$
§Worst-case complexity
$T(n, m) = O(m + n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is max(y.significant_bits(), z.significant_bits())
, and $m$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::{Pow, SaturatingSubMul};
use malachite_nz::natural::Natural;
assert_eq!(
(&Natural::from(20u32)).saturating_sub_mul(&Natural::from(3u32), &Natural::from(4u32)),
8
);
assert_eq!(
(&Natural::from(10u32)).saturating_sub_mul(&Natural::from(3u32), &Natural::from(4u32)),
0
);
assert_eq!(
(&Natural::from(10u32).pow(12))
.saturating_sub_mul(&Natural::from(0x10000u32), &Natural::from(0x10000u32)),
995705032704u64
);
type Output = Natural
source§impl<'a, 'b> SaturatingSubMul<&'a Natural, &'b Natural> for Natural
impl<'a, 'b> SaturatingSubMul<&'a Natural, &'b Natural> for Natural
source§fn saturating_sub_mul(self, y: &'a Natural, z: &'b Natural) -> Natural
fn saturating_sub_mul(self, y: &'a Natural, z: &'b Natural) -> Natural
Subtracts a Natural
by the product of two other Natural
s, taking the first by value
and the second and third by reference and returning 0 if the result is negative.
$$ f(x, y, z) = \max(x - yz, 0). $$
§Worst-case complexity
$T(n, m) = O(m + n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is max(y.significant_bits(), z.significant_bits())
, and $m$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::{Pow, SaturatingSubMul};
use malachite_nz::natural::Natural;
assert_eq!(
Natural::from(20u32).saturating_sub_mul(&Natural::from(3u32), &Natural::from(4u32)),
8
);
assert_eq!(
Natural::from(10u32).saturating_sub_mul(&Natural::from(3u32), &Natural::from(4u32)),
0
);
assert_eq!(
Natural::from(10u32).pow(12)
.saturating_sub_mul(&Natural::from(0x10000u32), &Natural::from(0x10000u32)),
995705032704u64
);
type Output = Natural
source§impl<'a> SaturatingSubMul<Natural, &'a Natural> for Natural
impl<'a> SaturatingSubMul<Natural, &'a Natural> for Natural
source§fn saturating_sub_mul(self, y: Natural, z: &'a Natural) -> Natural
fn saturating_sub_mul(self, y: Natural, z: &'a Natural) -> Natural
Subtracts a Natural
by the product of two other Natural
s, taking the first two by
value and the third by reference and returning 0 if the result is negative.
$$ f(x, y, z) = \max(x - yz, 0). $$
§Worst-case complexity
$T(n, m) = O(m + n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is max(y.significant_bits(), z.significant_bits())
, and $m$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::{Pow, SaturatingSubMul};
use malachite_nz::natural::Natural;
assert_eq!(
Natural::from(20u32).saturating_sub_mul(Natural::from(3u32), &Natural::from(4u32)),
8
);
assert_eq!(
Natural::from(10u32).saturating_sub_mul(Natural::from(3u32), &Natural::from(4u32)),
0
);
assert_eq!(
Natural::from(10u32).pow(12)
.saturating_sub_mul(Natural::from(0x10000u32), &Natural::from(0x10000u32)),
995705032704u64
);
type Output = Natural
source§impl SaturatingSubMul for Natural
impl SaturatingSubMul for Natural
source§fn saturating_sub_mul(self, y: Natural, z: Natural) -> Natural
fn saturating_sub_mul(self, y: Natural, z: Natural) -> Natural
Subtracts a Natural
by the product of two other Natural
s, taking all three by value
and returning 0 if the result is negative.
$$ f(x, y, z) = \max(x - yz, 0). $$
§Worst-case complexity
$T(n, m) = O(m + n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is max(y.significant_bits(), z.significant_bits())
, and $m$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::{Pow, SaturatingSubMul};
use malachite_nz::natural::Natural;
assert_eq!(
Natural::from(20u32).saturating_sub_mul(Natural::from(3u32), Natural::from(4u32)),
8
);
assert_eq!(
Natural::from(10u32).saturating_sub_mul(Natural::from(3u32), Natural::from(4u32)),
0
);
assert_eq!(
Natural::from(10u32).pow(12)
.saturating_sub_mul(Natural::from(0x10000u32), Natural::from(0x10000u32)),
995705032704u64
);
type Output = Natural
source§impl<'a> SaturatingSubMulAssign<&'a Natural> for Natural
impl<'a> SaturatingSubMulAssign<&'a Natural> for Natural
source§fn saturating_sub_mul_assign(&mut self, y: &'a Natural, z: Natural)
fn saturating_sub_mul_assign(&mut self, y: &'a Natural, z: Natural)
Subtracts a Natural
by the product of two other Natural
s in place, taking the first
Natural
on the right-hand side by reference and the second by value and replacing the
left-hand side Natural
with 0 if the result is negative.
$$ x \gets \max(x - yz, 0). $$
§Worst-case complexity
$T(n, m) = O(m + n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is max(y.significant_bits(), z.significant_bits())
, and $m$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::{Pow, SaturatingSubMulAssign};
use malachite_nz::natural::Natural;
let mut x = Natural::from(20u32);
x.saturating_sub_mul_assign(&Natural::from(3u32), Natural::from(4u32));
assert_eq!(x, 8);
let mut x = Natural::from(10u32);
x.saturating_sub_mul_assign(&Natural::from(3u32), Natural::from(4u32));
assert_eq!(x, 0);
let mut x = Natural::from(10u32).pow(12);
x.saturating_sub_mul_assign(&Natural::from(0x10000u32), Natural::from(0x10000u32));
assert_eq!(x, 995705032704u64);
source§impl<'a, 'b> SaturatingSubMulAssign<&'a Natural, &'b Natural> for Natural
impl<'a, 'b> SaturatingSubMulAssign<&'a Natural, &'b Natural> for Natural
source§fn saturating_sub_mul_assign(&mut self, y: &'a Natural, z: &'b Natural)
fn saturating_sub_mul_assign(&mut self, y: &'a Natural, z: &'b Natural)
Subtracts a Natural
by the product of two other Natural
s in place, taking both
Natural
s on the right-hand side by reference and replacing the left-hand side
Natural
with 0 if the result is negative.
$$ x \gets \max(x - yz, 0). $$
§Worst-case complexity
$T(n, m) = O(m + n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is max(y.significant_bits(), z.significant_bits())
, and $m$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::{Pow, SaturatingSubMulAssign};
use malachite_nz::natural::Natural;
let mut x = Natural::from(20u32);
x.saturating_sub_mul_assign(&Natural::from(3u32), &Natural::from(4u32));
assert_eq!(x, 8);
let mut x = Natural::from(10u32);
x.saturating_sub_mul_assign(&Natural::from(3u32), &Natural::from(4u32));
assert_eq!(x, 0);
let mut x = Natural::from(10u32).pow(12);
x.saturating_sub_mul_assign(&Natural::from(0x10000u32), &Natural::from(0x10000u32));
assert_eq!(x, 995705032704u64);
source§impl<'a> SaturatingSubMulAssign<Natural, &'a Natural> for Natural
impl<'a> SaturatingSubMulAssign<Natural, &'a Natural> for Natural
source§fn saturating_sub_mul_assign(&mut self, y: Natural, z: &'a Natural)
fn saturating_sub_mul_assign(&mut self, y: Natural, z: &'a Natural)
Subtracts a Natural
by the product of two other Natural
s in place, taking the first
Natural
on the right-hand side by value and the second by reference and replacing the
left-hand side Natural
with 0 if the result is negative.
$$ x \gets \max(x - yz, 0). $$
§Worst-case complexity
$T(n, m) = O(m + n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is max(y.significant_bits(), z.significant_bits())
, and $m$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::{Pow, SaturatingSubMulAssign};
use malachite_nz::natural::Natural;
let mut x = Natural::from(20u32);
x.saturating_sub_mul_assign(Natural::from(3u32), &Natural::from(4u32));
assert_eq!(x, 8);
let mut x = Natural::from(10u32);
x.saturating_sub_mul_assign(Natural::from(3u32), &Natural::from(4u32));
assert_eq!(x, 0);
let mut x = Natural::from(10u32).pow(12);
x.saturating_sub_mul_assign(Natural::from(0x10000u32), &Natural::from(0x10000u32));
assert_eq!(x, 995705032704u64);
source§impl SaturatingSubMulAssign for Natural
impl SaturatingSubMulAssign for Natural
source§fn saturating_sub_mul_assign(&mut self, y: Natural, z: Natural)
fn saturating_sub_mul_assign(&mut self, y: Natural, z: Natural)
Subtracts a Natural
by the product of two other Natural
s in place, taking both
Natural
s on the right-hand side by value and replacing the left-hand side Natural
with 0 if the result is negative.
$$ x \gets \max(x - yz, 0). $$
§Worst-case complexity
$T(n, m) = O(m + n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is max(y.significant_bits(), z.significant_bits())
, and $m$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::{Pow, SaturatingSubMulAssign};
use malachite_nz::natural::Natural;
let mut x = Natural::from(20u32);
x.saturating_sub_mul_assign(Natural::from(3u32), Natural::from(4u32));
assert_eq!(x, 8);
let mut x = Natural::from(10u32);
x.saturating_sub_mul_assign(Natural::from(3u32), Natural::from(4u32));
assert_eq!(x, 0);
let mut x = Natural::from(10u32).pow(12);
x.saturating_sub_mul_assign(Natural::from(0x10000u32), Natural::from(0x10000u32));
assert_eq!(x, 995705032704u64);
source§impl<'a> SciMantissaAndExponent<f32, u64, Natural> for &'a Natural
impl<'a> SciMantissaAndExponent<f32, u64, Natural> for &'a Natural
source§fn sci_mantissa_and_exponent(self) -> (f32, u64)
fn sci_mantissa_and_exponent(self) -> (f32, u64)
Returns a Natural
’s scientific mantissa and exponent.
When $x$ is positive, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and
$m_s$ is a rational number with $1 \leq m_s < 2$. We represent the rational mantissa
as a float. The conversion might not be exact, so we round to the nearest float
using the Nearest
rounding mode. To use other rounding modes, use
sci_mantissa_and_exponent_round
.
$$
f(x) \approx (\frac{x}{2^{\lfloor \log_2 x \rfloor}}, \lfloor \log_2 x \rfloor).
$$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
source§fn from_sci_mantissa_and_exponent(
sci_mantissa: f32,
sci_exponent: u64
) -> Option<Natural>
fn from_sci_mantissa_and_exponent( sci_mantissa: f32, sci_exponent: u64 ) -> Option<Natural>
Constructs a Natural
from its scientific mantissa and exponent.
When $x$ is positive, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and
$m_s$ is a rational number with $1 \leq m_s < 2$. Here, the rational mantissa is
provided as a float. If the mantissa is outside the range $[1, 2)$, None
is
returned.
Some combinations of mantissas and exponents do not specify a Natural
, in which
case the resulting value is rounded to a Natural
using the Nearest
rounding
mode. To specify other rounding modes, use
from_sci_mantissa_and_exponent_round
.
$$ f(x) \approx 2^{e_s}m_s. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is sci_exponent
.
§Examples
See here.
source§fn sci_mantissa(self) -> M
fn sci_mantissa(self) -> M
source§fn sci_exponent(self) -> E
fn sci_exponent(self) -> E
source§impl<'a> SciMantissaAndExponent<f64, u64, Natural> for &'a Natural
impl<'a> SciMantissaAndExponent<f64, u64, Natural> for &'a Natural
source§fn sci_mantissa_and_exponent(self) -> (f64, u64)
fn sci_mantissa_and_exponent(self) -> (f64, u64)
Returns a Natural
’s scientific mantissa and exponent.
When $x$ is positive, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and
$m_s$ is a rational number with $1 \leq m_s < 2$. We represent the rational mantissa
as a float. The conversion might not be exact, so we round to the nearest float
using the Nearest
rounding mode. To use other rounding modes, use
sci_mantissa_and_exponent_round
.
$$
f(x) \approx (\frac{x}{2^{\lfloor \log_2 x \rfloor}}, \lfloor \log_2 x \rfloor).
$$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
See here.
source§fn from_sci_mantissa_and_exponent(
sci_mantissa: f64,
sci_exponent: u64
) -> Option<Natural>
fn from_sci_mantissa_and_exponent( sci_mantissa: f64, sci_exponent: u64 ) -> Option<Natural>
Constructs a Natural
from its scientific mantissa and exponent.
When $x$ is positive, we can write $x = 2^{e_s}m_s$, where $e_s$ is an integer and
$m_s$ is a rational number with $1 \leq m_s < 2$. Here, the rational mantissa is
provided as a float. If the mantissa is outside the range $[1, 2)$, None
is
returned.
Some combinations of mantissas and exponents do not specify a Natural
, in which
case the resulting value is rounded to a Natural
using the Nearest
rounding
mode. To specify other rounding modes, use
from_sci_mantissa_and_exponent_round
.
$$ f(x) \approx 2^{e_s}m_s. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is sci_exponent
.
§Examples
See here.
source§fn sci_mantissa(self) -> M
fn sci_mantissa(self) -> M
source§fn sci_exponent(self) -> E
fn sci_exponent(self) -> E
source§impl<'a> Shl<i128> for &'a Natural
impl<'a> Shl<i128> for &'a Natural
source§fn shl(self, bits: i128) -> Natural
fn shl(self, bits: i128) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2 or divides it by a power of
2 and takes the floor), taking it by reference.
$$ f(x, k) = \lfloor x2^k \rfloor. $$
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(bits, 0)
.
§Examples
See here.
source§impl Shl<i128> for Natural
impl Shl<i128> for Natural
source§fn shl(self, bits: i128) -> Natural
fn shl(self, bits: i128) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2 or divides it by a power of
2 and takes the floor), taking it by value.
$$ f(x, k) = \lfloor x2^k \rfloor. $$
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(bits, 0)
.
§Examples
See here.
source§impl<'a> Shl<i16> for &'a Natural
impl<'a> Shl<i16> for &'a Natural
source§fn shl(self, bits: i16) -> Natural
fn shl(self, bits: i16) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2 or divides it by a power of
2 and takes the floor), taking it by reference.
$$ f(x, k) = \lfloor x2^k \rfloor. $$
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(bits, 0)
.
§Examples
See here.
source§impl Shl<i16> for Natural
impl Shl<i16> for Natural
source§fn shl(self, bits: i16) -> Natural
fn shl(self, bits: i16) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2 or divides it by a power of
2 and takes the floor), taking it by value.
$$ f(x, k) = \lfloor x2^k \rfloor. $$
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(bits, 0)
.
§Examples
See here.
source§impl<'a> Shl<i32> for &'a Natural
impl<'a> Shl<i32> for &'a Natural
source§fn shl(self, bits: i32) -> Natural
fn shl(self, bits: i32) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2 or divides it by a power of
2 and takes the floor), taking it by reference.
$$ f(x, k) = \lfloor x2^k \rfloor. $$
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(bits, 0)
.
§Examples
See here.
source§impl Shl<i32> for Natural
impl Shl<i32> for Natural
source§fn shl(self, bits: i32) -> Natural
fn shl(self, bits: i32) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2 or divides it by a power of
2 and takes the floor), taking it by value.
$$ f(x, k) = \lfloor x2^k \rfloor. $$
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(bits, 0)
.
§Examples
See here.
source§impl<'a> Shl<i64> for &'a Natural
impl<'a> Shl<i64> for &'a Natural
source§fn shl(self, bits: i64) -> Natural
fn shl(self, bits: i64) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2 or divides it by a power of
2 and takes the floor), taking it by reference.
$$ f(x, k) = \lfloor x2^k \rfloor. $$
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(bits, 0)
.
§Examples
See here.
source§impl Shl<i64> for Natural
impl Shl<i64> for Natural
source§fn shl(self, bits: i64) -> Natural
fn shl(self, bits: i64) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2 or divides it by a power of
2 and takes the floor), taking it by value.
$$ f(x, k) = \lfloor x2^k \rfloor. $$
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(bits, 0)
.
§Examples
See here.
source§impl<'a> Shl<i8> for &'a Natural
impl<'a> Shl<i8> for &'a Natural
source§fn shl(self, bits: i8) -> Natural
fn shl(self, bits: i8) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2 or divides it by a power of
2 and takes the floor), taking it by reference.
$$ f(x, k) = \lfloor x2^k \rfloor. $$
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(bits, 0)
.
§Examples
See here.
source§impl Shl<i8> for Natural
impl Shl<i8> for Natural
source§fn shl(self, bits: i8) -> Natural
fn shl(self, bits: i8) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2 or divides it by a power of
2 and takes the floor), taking it by value.
$$ f(x, k) = \lfloor x2^k \rfloor. $$
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(bits, 0)
.
§Examples
See here.
source§impl<'a> Shl<isize> for &'a Natural
impl<'a> Shl<isize> for &'a Natural
source§fn shl(self, bits: isize) -> Natural
fn shl(self, bits: isize) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2 or divides it by a power of
2 and takes the floor), taking it by reference.
$$ f(x, k) = \lfloor x2^k \rfloor. $$
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(bits, 0)
.
§Examples
See here.
source§impl Shl<isize> for Natural
impl Shl<isize> for Natural
source§fn shl(self, bits: isize) -> Natural
fn shl(self, bits: isize) -> Natural
Left-shifts a Natural
(multiplies it by a power of 2 or divides it by a power of
2 and takes the floor), taking it by value.
$$ f(x, k) = \lfloor x2^k \rfloor. $$
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(bits, 0)
.
§Examples
See here.
source§impl ShlAssign<i128> for Natural
impl ShlAssign<i128> for Natural
source§fn shl_assign(&mut self, bits: i128)
fn shl_assign(&mut self, bits: i128)
Left-shifts a Natural
(multiplies it by a power of 2 or divides it by a power of
2 and takes the floor), in place.
$$ x \gets \lfloor x2^k \rfloor. $$
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(bits, 0)
.
See here.
source§impl ShlAssign<i16> for Natural
impl ShlAssign<i16> for Natural
source§fn shl_assign(&mut self, bits: i16)
fn shl_assign(&mut self, bits: i16)
Left-shifts a Natural
(multiplies it by a power of 2 or divides it by a power of
2 and takes the floor), in place.
$$ x \gets \lfloor x2^k \rfloor. $$
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(bits, 0)
.
See here.
source§impl ShlAssign<i32> for Natural
impl ShlAssign<i32> for Natural
source§fn shl_assign(&mut self, bits: i32)
fn shl_assign(&mut self, bits: i32)
Left-shifts a Natural
(multiplies it by a power of 2 or divides it by a power of
2 and takes the floor), in place.
$$ x \gets \lfloor x2^k \rfloor. $$
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(bits, 0)
.
See here.
source§impl ShlAssign<i64> for Natural
impl ShlAssign<i64> for Natural
source§fn shl_assign(&mut self, bits: i64)
fn shl_assign(&mut self, bits: i64)
Left-shifts a Natural
(multiplies it by a power of 2 or divides it by a power of
2 and takes the floor), in place.
$$ x \gets \lfloor x2^k \rfloor. $$
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(bits, 0)
.
See here.
source§impl ShlAssign<i8> for Natural
impl ShlAssign<i8> for Natural
source§fn shl_assign(&mut self, bits: i8)
fn shl_assign(&mut self, bits: i8)
Left-shifts a Natural
(multiplies it by a power of 2 or divides it by a power of
2 and takes the floor), in place.
$$ x \gets \lfloor x2^k \rfloor. $$
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(bits, 0)
.
See here.
source§impl ShlAssign<isize> for Natural
impl ShlAssign<isize> for Natural
source§fn shl_assign(&mut self, bits: isize)
fn shl_assign(&mut self, bits: isize)
Left-shifts a Natural
(multiplies it by a power of 2 or divides it by a power of
2 and takes the floor), in place.
$$ x \gets \lfloor x2^k \rfloor. $$
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(bits, 0)
.
See here.
source§impl<'a> ShlRound<i128> for &'a Natural
impl<'a> ShlRound<i128> for &'a Natural
source§fn shl_round(self, bits: i128, rm: RoundingMode) -> (Natural, Ordering)
fn shl_round(self, bits: i128, rm: RoundingMode) -> (Natural, Ordering)
Left-shifts a Natural
(multiplies or divides it by a power of 2), taking it by
reference, and rounds according to the specified rounding mode. An Ordering
is
also returned, indicating whether the returned value is less than, equal to, or
greater than the exact value. If bits
is non-negative, then the returned
Ordering
is always Equal
, even if the higher bits of the result are lost.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if bits
is
negative.
Let $q = x2^k$, and let $g$ be the function that just returns the first element of
the pair, without the Ordering
:
$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ g(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then
$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(bits, 0)
.
§Panics
Let $k$ be bits
. Panics if $k$ is negative and rm
is RoundingMode::Exact
but
self
is not divisible by $2^{-k}$.
§Examples
See here.
type Output = Natural
source§impl ShlRound<i128> for Natural
impl ShlRound<i128> for Natural
source§fn shl_round(self, bits: i128, rm: RoundingMode) -> (Natural, Ordering)
fn shl_round(self, bits: i128, rm: RoundingMode) -> (Natural, Ordering)
Left-shifts a Natural
(multiplies or divides it by a power of 2), taking it by
value, and rounds according to the specified rounding mode. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater
than the exact value. If bits
is non-negative, then the returned Ordering
is
always Equal
, even if the higher bits of the result are lost.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if bits
is
negative.
Let $q = x2^k$, and let $g$ be the function that just returns the first element of
the pair, without the Ordering
:
$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then
$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(bits, 0)
.
§Panics
Let $k$ be bits
. Panics if $k$ is negative and rm
is RoundingMode::Exact
but
self
is not divisible by $2^{-k}$.
§Examples
See here.
type Output = Natural
source§impl<'a> ShlRound<i16> for &'a Natural
impl<'a> ShlRound<i16> for &'a Natural
source§fn shl_round(self, bits: i16, rm: RoundingMode) -> (Natural, Ordering)
fn shl_round(self, bits: i16, rm: RoundingMode) -> (Natural, Ordering)
Left-shifts a Natural
(multiplies or divides it by a power of 2), taking it by
reference, and rounds according to the specified rounding mode. An Ordering
is
also returned, indicating whether the returned value is less than, equal to, or
greater than the exact value. If bits
is non-negative, then the returned
Ordering
is always Equal
, even if the higher bits of the result are lost.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if bits
is
negative.
Let $q = x2^k$, and let $g$ be the function that just returns the first element of
the pair, without the Ordering
:
$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ g(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then
$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(bits, 0)
.
§Panics
Let $k$ be bits
. Panics if $k$ is negative and rm
is RoundingMode::Exact
but
self
is not divisible by $2^{-k}$.
§Examples
See here.
type Output = Natural
source§impl ShlRound<i16> for Natural
impl ShlRound<i16> for Natural
source§fn shl_round(self, bits: i16, rm: RoundingMode) -> (Natural, Ordering)
fn shl_round(self, bits: i16, rm: RoundingMode) -> (Natural, Ordering)
Left-shifts a Natural
(multiplies or divides it by a power of 2), taking it by
value, and rounds according to the specified rounding mode. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater
than the exact value. If bits
is non-negative, then the returned Ordering
is
always Equal
, even if the higher bits of the result are lost.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if bits
is
negative.
Let $q = x2^k$, and let $g$ be the function that just returns the first element of
the pair, without the Ordering
:
$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then
$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(bits, 0)
.
§Panics
Let $k$ be bits
. Panics if $k$ is negative and rm
is RoundingMode::Exact
but
self
is not divisible by $2^{-k}$.
§Examples
See here.
type Output = Natural
source§impl<'a> ShlRound<i32> for &'a Natural
impl<'a> ShlRound<i32> for &'a Natural
source§fn shl_round(self, bits: i32, rm: RoundingMode) -> (Natural, Ordering)
fn shl_round(self, bits: i32, rm: RoundingMode) -> (Natural, Ordering)
Left-shifts a Natural
(multiplies or divides it by a power of 2), taking it by
reference, and rounds according to the specified rounding mode. An Ordering
is
also returned, indicating whether the returned value is less than, equal to, or
greater than the exact value. If bits
is non-negative, then the returned
Ordering
is always Equal
, even if the higher bits of the result are lost.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if bits
is
negative.
Let $q = x2^k$, and let $g$ be the function that just returns the first element of
the pair, without the Ordering
:
$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ g(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then
$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(bits, 0)
.
§Panics
Let $k$ be bits
. Panics if $k$ is negative and rm
is RoundingMode::Exact
but
self
is not divisible by $2^{-k}$.
§Examples
See here.
type Output = Natural
source§impl ShlRound<i32> for Natural
impl ShlRound<i32> for Natural
source§fn shl_round(self, bits: i32, rm: RoundingMode) -> (Natural, Ordering)
fn shl_round(self, bits: i32, rm: RoundingMode) -> (Natural, Ordering)
Left-shifts a Natural
(multiplies or divides it by a power of 2), taking it by
value, and rounds according to the specified rounding mode. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater
than the exact value. If bits
is non-negative, then the returned Ordering
is
always Equal
, even if the higher bits of the result are lost.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if bits
is
negative.
Let $q = x2^k$, and let $g$ be the function that just returns the first element of
the pair, without the Ordering
:
$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then
$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(bits, 0)
.
§Panics
Let $k$ be bits
. Panics if $k$ is negative and rm
is RoundingMode::Exact
but
self
is not divisible by $2^{-k}$.
§Examples
See here.
type Output = Natural
source§impl<'a> ShlRound<i64> for &'a Natural
impl<'a> ShlRound<i64> for &'a Natural
source§fn shl_round(self, bits: i64, rm: RoundingMode) -> (Natural, Ordering)
fn shl_round(self, bits: i64, rm: RoundingMode) -> (Natural, Ordering)
Left-shifts a Natural
(multiplies or divides it by a power of 2), taking it by
reference, and rounds according to the specified rounding mode. An Ordering
is
also returned, indicating whether the returned value is less than, equal to, or
greater than the exact value. If bits
is non-negative, then the returned
Ordering
is always Equal
, even if the higher bits of the result are lost.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if bits
is
negative.
Let $q = x2^k$, and let $g$ be the function that just returns the first element of
the pair, without the Ordering
:
$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ g(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then
$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(bits, 0)
.
§Panics
Let $k$ be bits
. Panics if $k$ is negative and rm
is RoundingMode::Exact
but
self
is not divisible by $2^{-k}$.
§Examples
See here.
type Output = Natural
source§impl ShlRound<i64> for Natural
impl ShlRound<i64> for Natural
source§fn shl_round(self, bits: i64, rm: RoundingMode) -> (Natural, Ordering)
fn shl_round(self, bits: i64, rm: RoundingMode) -> (Natural, Ordering)
Left-shifts a Natural
(multiplies or divides it by a power of 2), taking it by
value, and rounds according to the specified rounding mode. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater
than the exact value. If bits
is non-negative, then the returned Ordering
is
always Equal
, even if the higher bits of the result are lost.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if bits
is
negative.
Let $q = x2^k$, and let $g$ be the function that just returns the first element of
the pair, without the Ordering
:
$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then
$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(bits, 0)
.
§Panics
Let $k$ be bits
. Panics if $k$ is negative and rm
is RoundingMode::Exact
but
self
is not divisible by $2^{-k}$.
§Examples
See here.
type Output = Natural
source§impl<'a> ShlRound<i8> for &'a Natural
impl<'a> ShlRound<i8> for &'a Natural
source§fn shl_round(self, bits: i8, rm: RoundingMode) -> (Natural, Ordering)
fn shl_round(self, bits: i8, rm: RoundingMode) -> (Natural, Ordering)
Left-shifts a Natural
(multiplies or divides it by a power of 2), taking it by
reference, and rounds according to the specified rounding mode. An Ordering
is
also returned, indicating whether the returned value is less than, equal to, or
greater than the exact value. If bits
is non-negative, then the returned
Ordering
is always Equal
, even if the higher bits of the result are lost.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if bits
is
negative.
Let $q = x2^k$, and let $g$ be the function that just returns the first element of
the pair, without the Ordering
:
$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ g(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then
$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(bits, 0)
.
§Panics
Let $k$ be bits
. Panics if $k$ is negative and rm
is RoundingMode::Exact
but
self
is not divisible by $2^{-k}$.
§Examples
See here.
type Output = Natural
source§impl ShlRound<i8> for Natural
impl ShlRound<i8> for Natural
source§fn shl_round(self, bits: i8, rm: RoundingMode) -> (Natural, Ordering)
fn shl_round(self, bits: i8, rm: RoundingMode) -> (Natural, Ordering)
Left-shifts a Natural
(multiplies or divides it by a power of 2), taking it by
value, and rounds according to the specified rounding mode. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater
than the exact value. If bits
is non-negative, then the returned Ordering
is
always Equal
, even if the higher bits of the result are lost.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if bits
is
negative.
Let $q = x2^k$, and let $g$ be the function that just returns the first element of
the pair, without the Ordering
:
$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then
$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(bits, 0)
.
§Panics
Let $k$ be bits
. Panics if $k$ is negative and rm
is RoundingMode::Exact
but
self
is not divisible by $2^{-k}$.
§Examples
See here.
type Output = Natural
source§impl<'a> ShlRound<isize> for &'a Natural
impl<'a> ShlRound<isize> for &'a Natural
source§fn shl_round(self, bits: isize, rm: RoundingMode) -> (Natural, Ordering)
fn shl_round(self, bits: isize, rm: RoundingMode) -> (Natural, Ordering)
Left-shifts a Natural
(multiplies or divides it by a power of 2), taking it by
reference, and rounds according to the specified rounding mode. An Ordering
is
also returned, indicating whether the returned value is less than, equal to, or
greater than the exact value. If bits
is non-negative, then the returned
Ordering
is always Equal
, even if the higher bits of the result are lost.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if bits
is
negative.
Let $q = x2^k$, and let $g$ be the function that just returns the first element of
the pair, without the Ordering
:
$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ g(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then
$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(bits, 0)
.
§Panics
Let $k$ be bits
. Panics if $k$ is negative and rm
is RoundingMode::Exact
but
self
is not divisible by $2^{-k}$.
§Examples
See here.
type Output = Natural
source§impl ShlRound<isize> for Natural
impl ShlRound<isize> for Natural
source§fn shl_round(self, bits: isize, rm: RoundingMode) -> (Natural, Ordering)
fn shl_round(self, bits: isize, rm: RoundingMode) -> (Natural, Ordering)
Left-shifts a Natural
(multiplies or divides it by a power of 2), taking it by
value, and rounds according to the specified rounding mode. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater
than the exact value. If bits
is non-negative, then the returned Ordering
is
always Equal
, even if the higher bits of the result are lost.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if bits
is
negative.
Let $q = x2^k$, and let $g$ be the function that just returns the first element of
the pair, without the Ordering
:
$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then
$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(bits, 0)
.
§Panics
Let $k$ be bits
. Panics if $k$ is negative and rm
is RoundingMode::Exact
but
self
is not divisible by $2^{-k}$.
§Examples
See here.
type Output = Natural
source§impl ShlRoundAssign<i128> for Natural
impl ShlRoundAssign<i128> for Natural
source§fn shl_round_assign(&mut self, bits: i128, rm: RoundingMode) -> Ordering
fn shl_round_assign(&mut self, bits: i128, rm: RoundingMode) -> Ordering
Left-shifts a Natural
(multiplies or divides it by a power of 2) and rounds
according to the specified rounding mode, in place. An Ordering
is returned,
indicating whether the assigned value is less than, equal to, or greater than the
exact value.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if bits
is
negative.
See the ShlRound
documentation for details.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(bits, 0)
.
§Panics
Let $k$ be bits
. Panics if $k$ is negative and rm
is RoundingMode::Exact
but
self
is not divisible by $2^{-k}$.
§Examples
See here.
source§impl ShlRoundAssign<i16> for Natural
impl ShlRoundAssign<i16> for Natural
source§fn shl_round_assign(&mut self, bits: i16, rm: RoundingMode) -> Ordering
fn shl_round_assign(&mut self, bits: i16, rm: RoundingMode) -> Ordering
Left-shifts a Natural
(multiplies or divides it by a power of 2) and rounds
according to the specified rounding mode, in place. An Ordering
is returned,
indicating whether the assigned value is less than, equal to, or greater than the
exact value.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if bits
is
negative.
See the ShlRound
documentation for details.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(bits, 0)
.
§Panics
Let $k$ be bits
. Panics if $k$ is negative and rm
is RoundingMode::Exact
but
self
is not divisible by $2^{-k}$.
§Examples
See here.
source§impl ShlRoundAssign<i32> for Natural
impl ShlRoundAssign<i32> for Natural
source§fn shl_round_assign(&mut self, bits: i32, rm: RoundingMode) -> Ordering
fn shl_round_assign(&mut self, bits: i32, rm: RoundingMode) -> Ordering
Left-shifts a Natural
(multiplies or divides it by a power of 2) and rounds
according to the specified rounding mode, in place. An Ordering
is returned,
indicating whether the assigned value is less than, equal to, or greater than the
exact value.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if bits
is
negative.
See the ShlRound
documentation for details.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(bits, 0)
.
§Panics
Let $k$ be bits
. Panics if $k$ is negative and rm
is RoundingMode::Exact
but
self
is not divisible by $2^{-k}$.
§Examples
See here.
source§impl ShlRoundAssign<i64> for Natural
impl ShlRoundAssign<i64> for Natural
source§fn shl_round_assign(&mut self, bits: i64, rm: RoundingMode) -> Ordering
fn shl_round_assign(&mut self, bits: i64, rm: RoundingMode) -> Ordering
Left-shifts a Natural
(multiplies or divides it by a power of 2) and rounds
according to the specified rounding mode, in place. An Ordering
is returned,
indicating whether the assigned value is less than, equal to, or greater than the
exact value.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if bits
is
negative.
See the ShlRound
documentation for details.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(bits, 0)
.
§Panics
Let $k$ be bits
. Panics if $k$ is negative and rm
is RoundingMode::Exact
but
self
is not divisible by $2^{-k}$.
§Examples
See here.
source§impl ShlRoundAssign<i8> for Natural
impl ShlRoundAssign<i8> for Natural
source§fn shl_round_assign(&mut self, bits: i8, rm: RoundingMode) -> Ordering
fn shl_round_assign(&mut self, bits: i8, rm: RoundingMode) -> Ordering
Left-shifts a Natural
(multiplies or divides it by a power of 2) and rounds
according to the specified rounding mode, in place. An Ordering
is returned,
indicating whether the assigned value is less than, equal to, or greater than the
exact value.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if bits
is
negative.
See the ShlRound
documentation for details.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(bits, 0)
.
§Panics
Let $k$ be bits
. Panics if $k$ is negative and rm
is RoundingMode::Exact
but
self
is not divisible by $2^{-k}$.
§Examples
See here.
source§impl ShlRoundAssign<isize> for Natural
impl ShlRoundAssign<isize> for Natural
source§fn shl_round_assign(&mut self, bits: isize, rm: RoundingMode) -> Ordering
fn shl_round_assign(&mut self, bits: isize, rm: RoundingMode) -> Ordering
Left-shifts a Natural
(multiplies or divides it by a power of 2) and rounds
according to the specified rounding mode, in place. An Ordering
is returned,
indicating whether the assigned value is less than, equal to, or greater than the
exact value.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if bits
is
negative.
See the ShlRound
documentation for details.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(bits, 0)
.
§Panics
Let $k$ be bits
. Panics if $k$ is negative and rm
is RoundingMode::Exact
but
self
is not divisible by $2^{-k}$.
§Examples
See here.
source§impl<'a> Shr<i128> for &'a Natural
impl<'a> Shr<i128> for &'a Natural
source§fn shr(self, bits: i128) -> Natural
fn shr(self, bits: i128) -> Natural
Right-shifts a Natural
(divides it by a power of 2 and takes the floor or
multiplies it by a power of 2), taking it by reference.
$$ f(x, k) = \left \lfloor \frac{x}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits)
.
§Examples
See here.
source§impl Shr<i128> for Natural
impl Shr<i128> for Natural
source§fn shr(self, bits: i128) -> Natural
fn shr(self, bits: i128) -> Natural
Right-shifts a Natural
(divides it by a power of 2 and takes the floor or
multiplies it by a power of 2), taking it by value.
$$ f(x, k) = \left \lfloor \frac{x}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits)
.
§Examples
See here.
source§impl<'a> Shr<i16> for &'a Natural
impl<'a> Shr<i16> for &'a Natural
source§fn shr(self, bits: i16) -> Natural
fn shr(self, bits: i16) -> Natural
Right-shifts a Natural
(divides it by a power of 2 and takes the floor or
multiplies it by a power of 2), taking it by reference.
$$ f(x, k) = \left \lfloor \frac{x}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits)
.
§Examples
See here.
source§impl Shr<i16> for Natural
impl Shr<i16> for Natural
source§fn shr(self, bits: i16) -> Natural
fn shr(self, bits: i16) -> Natural
Right-shifts a Natural
(divides it by a power of 2 and takes the floor or
multiplies it by a power of 2), taking it by value.
$$ f(x, k) = \left \lfloor \frac{x}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits)
.
§Examples
See here.
source§impl<'a> Shr<i32> for &'a Natural
impl<'a> Shr<i32> for &'a Natural
source§fn shr(self, bits: i32) -> Natural
fn shr(self, bits: i32) -> Natural
Right-shifts a Natural
(divides it by a power of 2 and takes the floor or
multiplies it by a power of 2), taking it by reference.
$$ f(x, k) = \left \lfloor \frac{x}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits)
.
§Examples
See here.
source§impl Shr<i32> for Natural
impl Shr<i32> for Natural
source§fn shr(self, bits: i32) -> Natural
fn shr(self, bits: i32) -> Natural
Right-shifts a Natural
(divides it by a power of 2 and takes the floor or
multiplies it by a power of 2), taking it by value.
$$ f(x, k) = \left \lfloor \frac{x}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits)
.
§Examples
See here.
source§impl<'a> Shr<i64> for &'a Natural
impl<'a> Shr<i64> for &'a Natural
source§fn shr(self, bits: i64) -> Natural
fn shr(self, bits: i64) -> Natural
Right-shifts a Natural
(divides it by a power of 2 and takes the floor or
multiplies it by a power of 2), taking it by reference.
$$ f(x, k) = \left \lfloor \frac{x}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits)
.
§Examples
See here.
source§impl Shr<i64> for Natural
impl Shr<i64> for Natural
source§fn shr(self, bits: i64) -> Natural
fn shr(self, bits: i64) -> Natural
Right-shifts a Natural
(divides it by a power of 2 and takes the floor or
multiplies it by a power of 2), taking it by value.
$$ f(x, k) = \left \lfloor \frac{x}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits)
.
§Examples
See here.
source§impl<'a> Shr<i8> for &'a Natural
impl<'a> Shr<i8> for &'a Natural
source§fn shr(self, bits: i8) -> Natural
fn shr(self, bits: i8) -> Natural
Right-shifts a Natural
(divides it by a power of 2 and takes the floor or
multiplies it by a power of 2), taking it by reference.
$$ f(x, k) = \left \lfloor \frac{x}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits)
.
§Examples
See here.
source§impl Shr<i8> for Natural
impl Shr<i8> for Natural
source§fn shr(self, bits: i8) -> Natural
fn shr(self, bits: i8) -> Natural
Right-shifts a Natural
(divides it by a power of 2 and takes the floor or
multiplies it by a power of 2), taking it by value.
$$ f(x, k) = \left \lfloor \frac{x}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits)
.
§Examples
See here.
source§impl<'a> Shr<isize> for &'a Natural
impl<'a> Shr<isize> for &'a Natural
source§fn shr(self, bits: isize) -> Natural
fn shr(self, bits: isize) -> Natural
Right-shifts a Natural
(divides it by a power of 2 and takes the floor or
multiplies it by a power of 2), taking it by reference.
$$ f(x, k) = \left \lfloor \frac{x}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits)
.
§Examples
See here.
source§impl Shr<isize> for Natural
impl Shr<isize> for Natural
source§fn shr(self, bits: isize) -> Natural
fn shr(self, bits: isize) -> Natural
Right-shifts a Natural
(divides it by a power of 2 and takes the floor or
multiplies it by a power of 2), taking it by value.
$$ f(x, k) = \left \lfloor \frac{x}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits)
.
§Examples
See here.
source§impl<'a> Shr<u128> for &'a Natural
impl<'a> Shr<u128> for &'a Natural
source§fn shr(self, bits: u128) -> Natural
fn shr(self, bits: u128) -> Natural
Right-shifts a Natural
(divides it by a power of 2 and takes the floor), taking
it by reference.
$$ f(x, k) = \left \lfloor \frac{x}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits)
.
§Examples
See here.
source§impl Shr<u128> for Natural
impl Shr<u128> for Natural
source§fn shr(self, bits: u128) -> Natural
fn shr(self, bits: u128) -> Natural
Right-shifts a Natural
(divides it by a power of 2 and takes the floor), taking
it by value.
$$ f(x, k) = \left \lfloor \frac{x}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits)
.
§Examples
See here.
source§impl<'a> Shr<u16> for &'a Natural
impl<'a> Shr<u16> for &'a Natural
source§fn shr(self, bits: u16) -> Natural
fn shr(self, bits: u16) -> Natural
Right-shifts a Natural
(divides it by a power of 2 and takes the floor), taking
it by reference.
$$ f(x, k) = \left \lfloor \frac{x}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits)
.
§Examples
See here.
source§impl Shr<u16> for Natural
impl Shr<u16> for Natural
source§fn shr(self, bits: u16) -> Natural
fn shr(self, bits: u16) -> Natural
Right-shifts a Natural
(divides it by a power of 2 and takes the floor), taking
it by value.
$$ f(x, k) = \left \lfloor \frac{x}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits)
.
§Examples
See here.
source§impl<'a> Shr<u32> for &'a Natural
impl<'a> Shr<u32> for &'a Natural
source§fn shr(self, bits: u32) -> Natural
fn shr(self, bits: u32) -> Natural
Right-shifts a Natural
(divides it by a power of 2 and takes the floor), taking
it by reference.
$$ f(x, k) = \left \lfloor \frac{x}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits)
.
§Examples
See here.
source§impl Shr<u32> for Natural
impl Shr<u32> for Natural
source§fn shr(self, bits: u32) -> Natural
fn shr(self, bits: u32) -> Natural
Right-shifts a Natural
(divides it by a power of 2 and takes the floor), taking
it by value.
$$ f(x, k) = \left \lfloor \frac{x}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits)
.
§Examples
See here.
source§impl<'a> Shr<u64> for &'a Natural
impl<'a> Shr<u64> for &'a Natural
source§fn shr(self, bits: u64) -> Natural
fn shr(self, bits: u64) -> Natural
Right-shifts a Natural
(divides it by a power of 2 and takes the floor), taking
it by reference.
$$ f(x, k) = \left \lfloor \frac{x}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits)
.
§Examples
See here.
source§impl Shr<u64> for Natural
impl Shr<u64> for Natural
source§fn shr(self, bits: u64) -> Natural
fn shr(self, bits: u64) -> Natural
Right-shifts a Natural
(divides it by a power of 2 and takes the floor), taking
it by value.
$$ f(x, k) = \left \lfloor \frac{x}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits)
.
§Examples
See here.
source§impl<'a> Shr<u8> for &'a Natural
impl<'a> Shr<u8> for &'a Natural
source§fn shr(self, bits: u8) -> Natural
fn shr(self, bits: u8) -> Natural
Right-shifts a Natural
(divides it by a power of 2 and takes the floor), taking
it by reference.
$$ f(x, k) = \left \lfloor \frac{x}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits)
.
§Examples
See here.
source§impl Shr<u8> for Natural
impl Shr<u8> for Natural
source§fn shr(self, bits: u8) -> Natural
fn shr(self, bits: u8) -> Natural
Right-shifts a Natural
(divides it by a power of 2 and takes the floor), taking
it by value.
$$ f(x, k) = \left \lfloor \frac{x}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits)
.
§Examples
See here.
source§impl<'a> Shr<usize> for &'a Natural
impl<'a> Shr<usize> for &'a Natural
source§fn shr(self, bits: usize) -> Natural
fn shr(self, bits: usize) -> Natural
Right-shifts a Natural
(divides it by a power of 2 and takes the floor), taking
it by reference.
$$ f(x, k) = \left \lfloor \frac{x}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits)
.
§Examples
See here.
source§impl Shr<usize> for Natural
impl Shr<usize> for Natural
source§fn shr(self, bits: usize) -> Natural
fn shr(self, bits: usize) -> Natural
Right-shifts a Natural
(divides it by a power of 2 and takes the floor), taking
it by value.
$$ f(x, k) = \left \lfloor \frac{x}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits)
.
§Examples
See here.
source§impl ShrAssign<i128> for Natural
impl ShrAssign<i128> for Natural
source§fn shr_assign(&mut self, bits: i128)
fn shr_assign(&mut self, bits: i128)
Right-shifts a Natural
(divides it by a power of 2 and takes the floor or
multiplies it by a power of 2), in place.
$$ x \gets \left \lfloor \frac{x}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits)
.
§Examples
See here.
source§impl ShrAssign<i16> for Natural
impl ShrAssign<i16> for Natural
source§fn shr_assign(&mut self, bits: i16)
fn shr_assign(&mut self, bits: i16)
Right-shifts a Natural
(divides it by a power of 2 and takes the floor or
multiplies it by a power of 2), in place.
$$ x \gets \left \lfloor \frac{x}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits)
.
§Examples
See here.
source§impl ShrAssign<i32> for Natural
impl ShrAssign<i32> for Natural
source§fn shr_assign(&mut self, bits: i32)
fn shr_assign(&mut self, bits: i32)
Right-shifts a Natural
(divides it by a power of 2 and takes the floor or
multiplies it by a power of 2), in place.
$$ x \gets \left \lfloor \frac{x}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits)
.
§Examples
See here.
source§impl ShrAssign<i64> for Natural
impl ShrAssign<i64> for Natural
source§fn shr_assign(&mut self, bits: i64)
fn shr_assign(&mut self, bits: i64)
Right-shifts a Natural
(divides it by a power of 2 and takes the floor or
multiplies it by a power of 2), in place.
$$ x \gets \left \lfloor \frac{x}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits)
.
§Examples
See here.
source§impl ShrAssign<i8> for Natural
impl ShrAssign<i8> for Natural
source§fn shr_assign(&mut self, bits: i8)
fn shr_assign(&mut self, bits: i8)
Right-shifts a Natural
(divides it by a power of 2 and takes the floor or
multiplies it by a power of 2), in place.
$$ x \gets \left \lfloor \frac{x}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits)
.
§Examples
See here.
source§impl ShrAssign<isize> for Natural
impl ShrAssign<isize> for Natural
source§fn shr_assign(&mut self, bits: isize)
fn shr_assign(&mut self, bits: isize)
Right-shifts a Natural
(divides it by a power of 2 and takes the floor or
multiplies it by a power of 2), in place.
$$ x \gets \left \lfloor \frac{x}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits)
.
§Examples
See here.
source§impl ShrAssign<u128> for Natural
impl ShrAssign<u128> for Natural
source§fn shr_assign(&mut self, bits: u128)
fn shr_assign(&mut self, bits: u128)
Right-shifts a Natural
(divides it by a power of 2 and takes the floor), in
place.
$$ x \gets \left \lfloor \frac{x}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits)
.
§Examples
See here.
source§impl ShrAssign<u16> for Natural
impl ShrAssign<u16> for Natural
source§fn shr_assign(&mut self, bits: u16)
fn shr_assign(&mut self, bits: u16)
Right-shifts a Natural
(divides it by a power of 2 and takes the floor), in
place.
$$ x \gets \left \lfloor \frac{x}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits)
.
§Examples
See here.
source§impl ShrAssign<u32> for Natural
impl ShrAssign<u32> for Natural
source§fn shr_assign(&mut self, bits: u32)
fn shr_assign(&mut self, bits: u32)
Right-shifts a Natural
(divides it by a power of 2 and takes the floor), in
place.
$$ x \gets \left \lfloor \frac{x}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits)
.
§Examples
See here.
source§impl ShrAssign<u64> for Natural
impl ShrAssign<u64> for Natural
source§fn shr_assign(&mut self, bits: u64)
fn shr_assign(&mut self, bits: u64)
Right-shifts a Natural
(divides it by a power of 2 and takes the floor), in
place.
$$ x \gets \left \lfloor \frac{x}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits)
.
§Examples
See here.
source§impl ShrAssign<u8> for Natural
impl ShrAssign<u8> for Natural
source§fn shr_assign(&mut self, bits: u8)
fn shr_assign(&mut self, bits: u8)
Right-shifts a Natural
(divides it by a power of 2 and takes the floor), in
place.
$$ x \gets \left \lfloor \frac{x}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits)
.
§Examples
See here.
source§impl ShrAssign<usize> for Natural
impl ShrAssign<usize> for Natural
source§fn shr_assign(&mut self, bits: usize)
fn shr_assign(&mut self, bits: usize)
Right-shifts a Natural
(divides it by a power of 2 and takes the floor), in
place.
$$ x \gets \left \lfloor \frac{x}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits)
.
§Examples
See here.
source§impl<'a> ShrRound<i128> for &'a Natural
impl<'a> ShrRound<i128> for &'a Natural
source§fn shr_round(self, bits: i128, rm: RoundingMode) -> (Natural, Ordering)
fn shr_round(self, bits: i128, rm: RoundingMode) -> (Natural, Ordering)
Shifts a Natural
right (divides or multiplies it by a power of 2), taking it by
reference, and rounds according to the specified rounding mode. An Ordering
is
also returned, indicating whether the returned value is less than, equal to, or
greater than the exact value. If bits
is negative, then the returned Ordering
is always Equal
, even if the higher bits of the result are lost.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$, and let $g$ be the function that just returns the first
element of the pair, without the Ordering
:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then
$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(-bits, 0)
.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(-bits, 0)
.
§Panics
Let $k$ be bits
. Panics if $k$ is positive and rm
is RoundingMode::Exact
but
self
is not divisible by $2^k$.
§Examples
See here.
type Output = Natural
source§impl ShrRound<i128> for Natural
impl ShrRound<i128> for Natural
source§fn shr_round(self, bits: i128, rm: RoundingMode) -> (Natural, Ordering)
fn shr_round(self, bits: i128, rm: RoundingMode) -> (Natural, Ordering)
Shifts a Natural
right (divides or multiplies it by a power of 2), taking it by
value, and rounds according to the specified rounding mode. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater
than the exact value. If bits
is negative, then the returned Ordering
is
always Equal
, even if the higher bits of the result are lost.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$, and let $g$ be the function that just returns the first
element of the pair, without the Ordering
:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then
$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(-bits, 0)
.
§Panics
Let $k$ be bits
. Panics if $k$ is positive and rm
is RoundingMode::Exact
but
self
is not divisible by $2^k$.
§Examples
See here.
type Output = Natural
source§impl<'a> ShrRound<i16> for &'a Natural
impl<'a> ShrRound<i16> for &'a Natural
source§fn shr_round(self, bits: i16, rm: RoundingMode) -> (Natural, Ordering)
fn shr_round(self, bits: i16, rm: RoundingMode) -> (Natural, Ordering)
Shifts a Natural
right (divides or multiplies it by a power of 2), taking it by
reference, and rounds according to the specified rounding mode. An Ordering
is
also returned, indicating whether the returned value is less than, equal to, or
greater than the exact value. If bits
is negative, then the returned Ordering
is always Equal
, even if the higher bits of the result are lost.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$, and let $g$ be the function that just returns the first
element of the pair, without the Ordering
:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then
$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(-bits, 0)
.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(-bits, 0)
.
§Panics
Let $k$ be bits
. Panics if $k$ is positive and rm
is RoundingMode::Exact
but
self
is not divisible by $2^k$.
§Examples
See here.
type Output = Natural
source§impl ShrRound<i16> for Natural
impl ShrRound<i16> for Natural
source§fn shr_round(self, bits: i16, rm: RoundingMode) -> (Natural, Ordering)
fn shr_round(self, bits: i16, rm: RoundingMode) -> (Natural, Ordering)
Shifts a Natural
right (divides or multiplies it by a power of 2), taking it by
value, and rounds according to the specified rounding mode. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater
than the exact value. If bits
is negative, then the returned Ordering
is
always Equal
, even if the higher bits of the result are lost.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$, and let $g$ be the function that just returns the first
element of the pair, without the Ordering
:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then
$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(-bits, 0)
.
§Panics
Let $k$ be bits
. Panics if $k$ is positive and rm
is RoundingMode::Exact
but
self
is not divisible by $2^k$.
§Examples
See here.
type Output = Natural
source§impl<'a> ShrRound<i32> for &'a Natural
impl<'a> ShrRound<i32> for &'a Natural
source§fn shr_round(self, bits: i32, rm: RoundingMode) -> (Natural, Ordering)
fn shr_round(self, bits: i32, rm: RoundingMode) -> (Natural, Ordering)
Shifts a Natural
right (divides or multiplies it by a power of 2), taking it by
reference, and rounds according to the specified rounding mode. An Ordering
is
also returned, indicating whether the returned value is less than, equal to, or
greater than the exact value. If bits
is negative, then the returned Ordering
is always Equal
, even if the higher bits of the result are lost.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$, and let $g$ be the function that just returns the first
element of the pair, without the Ordering
:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then
$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(-bits, 0)
.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(-bits, 0)
.
§Panics
Let $k$ be bits
. Panics if $k$ is positive and rm
is RoundingMode::Exact
but
self
is not divisible by $2^k$.
§Examples
See here.
type Output = Natural
source§impl ShrRound<i32> for Natural
impl ShrRound<i32> for Natural
source§fn shr_round(self, bits: i32, rm: RoundingMode) -> (Natural, Ordering)
fn shr_round(self, bits: i32, rm: RoundingMode) -> (Natural, Ordering)
Shifts a Natural
right (divides or multiplies it by a power of 2), taking it by
value, and rounds according to the specified rounding mode. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater
than the exact value. If bits
is negative, then the returned Ordering
is
always Equal
, even if the higher bits of the result are lost.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$, and let $g$ be the function that just returns the first
element of the pair, without the Ordering
:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then
$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(-bits, 0)
.
§Panics
Let $k$ be bits
. Panics if $k$ is positive and rm
is RoundingMode::Exact
but
self
is not divisible by $2^k$.
§Examples
See here.
type Output = Natural
source§impl<'a> ShrRound<i64> for &'a Natural
impl<'a> ShrRound<i64> for &'a Natural
source§fn shr_round(self, bits: i64, rm: RoundingMode) -> (Natural, Ordering)
fn shr_round(self, bits: i64, rm: RoundingMode) -> (Natural, Ordering)
Shifts a Natural
right (divides or multiplies it by a power of 2), taking it by
reference, and rounds according to the specified rounding mode. An Ordering
is
also returned, indicating whether the returned value is less than, equal to, or
greater than the exact value. If bits
is negative, then the returned Ordering
is always Equal
, even if the higher bits of the result are lost.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$, and let $g$ be the function that just returns the first
element of the pair, without the Ordering
:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then
$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(-bits, 0)
.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(-bits, 0)
.
§Panics
Let $k$ be bits
. Panics if $k$ is positive and rm
is RoundingMode::Exact
but
self
is not divisible by $2^k$.
§Examples
See here.
type Output = Natural
source§impl ShrRound<i64> for Natural
impl ShrRound<i64> for Natural
source§fn shr_round(self, bits: i64, rm: RoundingMode) -> (Natural, Ordering)
fn shr_round(self, bits: i64, rm: RoundingMode) -> (Natural, Ordering)
Shifts a Natural
right (divides or multiplies it by a power of 2), taking it by
value, and rounds according to the specified rounding mode. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater
than the exact value. If bits
is negative, then the returned Ordering
is
always Equal
, even if the higher bits of the result are lost.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$, and let $g$ be the function that just returns the first
element of the pair, without the Ordering
:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then
$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(-bits, 0)
.
§Panics
Let $k$ be bits
. Panics if $k$ is positive and rm
is RoundingMode::Exact
but
self
is not divisible by $2^k$.
§Examples
See here.
type Output = Natural
source§impl<'a> ShrRound<i8> for &'a Natural
impl<'a> ShrRound<i8> for &'a Natural
source§fn shr_round(self, bits: i8, rm: RoundingMode) -> (Natural, Ordering)
fn shr_round(self, bits: i8, rm: RoundingMode) -> (Natural, Ordering)
Shifts a Natural
right (divides or multiplies it by a power of 2), taking it by
reference, and rounds according to the specified rounding mode. An Ordering
is
also returned, indicating whether the returned value is less than, equal to, or
greater than the exact value. If bits
is negative, then the returned Ordering
is always Equal
, even if the higher bits of the result are lost.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$, and let $g$ be the function that just returns the first
element of the pair, without the Ordering
:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then
$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(-bits, 0)
.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(-bits, 0)
.
§Panics
Let $k$ be bits
. Panics if $k$ is positive and rm
is RoundingMode::Exact
but
self
is not divisible by $2^k$.
§Examples
See here.
type Output = Natural
source§impl ShrRound<i8> for Natural
impl ShrRound<i8> for Natural
source§fn shr_round(self, bits: i8, rm: RoundingMode) -> (Natural, Ordering)
fn shr_round(self, bits: i8, rm: RoundingMode) -> (Natural, Ordering)
Shifts a Natural
right (divides or multiplies it by a power of 2), taking it by
value, and rounds according to the specified rounding mode. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater
than the exact value. If bits
is negative, then the returned Ordering
is
always Equal
, even if the higher bits of the result are lost.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$, and let $g$ be the function that just returns the first
element of the pair, without the Ordering
:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then
$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(-bits, 0)
.
§Panics
Let $k$ be bits
. Panics if $k$ is positive and rm
is RoundingMode::Exact
but
self
is not divisible by $2^k$.
§Examples
See here.
type Output = Natural
source§impl<'a> ShrRound<isize> for &'a Natural
impl<'a> ShrRound<isize> for &'a Natural
source§fn shr_round(self, bits: isize, rm: RoundingMode) -> (Natural, Ordering)
fn shr_round(self, bits: isize, rm: RoundingMode) -> (Natural, Ordering)
Shifts a Natural
right (divides or multiplies it by a power of 2), taking it by
reference, and rounds according to the specified rounding mode. An Ordering
is
also returned, indicating whether the returned value is less than, equal to, or
greater than the exact value. If bits
is negative, then the returned Ordering
is always Equal
, even if the higher bits of the result are lost.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$, and let $g$ be the function that just returns the first
element of the pair, without the Ordering
:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then
$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(-bits, 0)
.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(-bits, 0)
.
§Panics
Let $k$ be bits
. Panics if $k$ is positive and rm
is RoundingMode::Exact
but
self
is not divisible by $2^k$.
§Examples
See here.
type Output = Natural
source§impl ShrRound<isize> for Natural
impl ShrRound<isize> for Natural
source§fn shr_round(self, bits: isize, rm: RoundingMode) -> (Natural, Ordering)
fn shr_round(self, bits: isize, rm: RoundingMode) -> (Natural, Ordering)
Shifts a Natural
right (divides or multiplies it by a power of 2), taking it by
value, and rounds according to the specified rounding mode. An Ordering
is also
returned, indicating whether the returned value is less than, equal to, or greater
than the exact value. If bits
is negative, then the returned Ordering
is
always Equal
, even if the higher bits of the result are lost.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$, and let $g$ be the function that just returns the first
element of the pair, without the Ordering
:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then
$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(-bits, 0)
.
§Panics
Let $k$ be bits
. Panics if $k$ is positive and rm
is RoundingMode::Exact
but
self
is not divisible by $2^k$.
§Examples
See here.
type Output = Natural
source§impl<'a> ShrRound<u128> for &'a Natural
impl<'a> ShrRound<u128> for &'a Natural
source§fn shr_round(self, bits: u128, rm: RoundingMode) -> (Natural, Ordering)
fn shr_round(self, bits: u128, rm: RoundingMode) -> (Natural, Ordering)
Shifts a Natural
right (divides it by a power of 2), taking it by reference, and
rounds according to the specified rounding mode. An Ordering
is also returned,
indicating whether the returned value is less than, equal to, or greater than the
exact value.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$, and let $g$ be the function that just returns the first
element of the pair, without the Ordering
:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then
$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.
§Worst-case complexity
$T(n) = O(n)$
$M(m) = O(m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(1, self.significant_bits() - bits)
.
§Panics
Let $k$ be bits
. Panics if rm
is RoundingMode::Exact
but self
is not
divisible by $2^k$.
§Examples
See here.
type Output = Natural
source§impl ShrRound<u128> for Natural
impl ShrRound<u128> for Natural
source§fn shr_round(self, bits: u128, rm: RoundingMode) -> (Natural, Ordering)
fn shr_round(self, bits: u128, rm: RoundingMode) -> (Natural, Ordering)
Shifts a Natural
right (divides it by a power of 2), taking it by value, and
rounds according to the specified rounding mode. An Ordering
is also returned,
indicating whether the returned value is less than, equal to, or greater than the
exact value.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$, and let $g$ be the function that just returns the first
element of the pair, without the Ordering
:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then
$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory and $n$ is self.significant_bits()
.
§Panics
Let $k$ be bits
. Panics if rm
is RoundingMode::Exact
but self
is not
divisible by $2^k$.
§Examples
See here.
type Output = Natural
source§impl<'a> ShrRound<u16> for &'a Natural
impl<'a> ShrRound<u16> for &'a Natural
source§fn shr_round(self, bits: u16, rm: RoundingMode) -> (Natural, Ordering)
fn shr_round(self, bits: u16, rm: RoundingMode) -> (Natural, Ordering)
Shifts a Natural
right (divides it by a power of 2), taking it by reference, and
rounds according to the specified rounding mode. An Ordering
is also returned,
indicating whether the returned value is less than, equal to, or greater than the
exact value.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$, and let $g$ be the function that just returns the first
element of the pair, without the Ordering
:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then
$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.
§Worst-case complexity
$T(n) = O(n)$
$M(m) = O(m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(1, self.significant_bits() - bits)
.
§Panics
Let $k$ be bits
. Panics if rm
is RoundingMode::Exact
but self
is not
divisible by $2^k$.
§Examples
See here.
type Output = Natural
source§impl ShrRound<u16> for Natural
impl ShrRound<u16> for Natural
source§fn shr_round(self, bits: u16, rm: RoundingMode) -> (Natural, Ordering)
fn shr_round(self, bits: u16, rm: RoundingMode) -> (Natural, Ordering)
Shifts a Natural
right (divides it by a power of 2), taking it by value, and
rounds according to the specified rounding mode. An Ordering
is also returned,
indicating whether the returned value is less than, equal to, or greater than the
exact value.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$, and let $g$ be the function that just returns the first
element of the pair, without the Ordering
:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then
$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory and $n$ is self.significant_bits()
.
§Panics
Let $k$ be bits
. Panics if rm
is RoundingMode::Exact
but self
is not
divisible by $2^k$.
§Examples
See here.
type Output = Natural
source§impl<'a> ShrRound<u32> for &'a Natural
impl<'a> ShrRound<u32> for &'a Natural
source§fn shr_round(self, bits: u32, rm: RoundingMode) -> (Natural, Ordering)
fn shr_round(self, bits: u32, rm: RoundingMode) -> (Natural, Ordering)
Shifts a Natural
right (divides it by a power of 2), taking it by reference, and
rounds according to the specified rounding mode. An Ordering
is also returned,
indicating whether the returned value is less than, equal to, or greater than the
exact value.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$, and let $g$ be the function that just returns the first
element of the pair, without the Ordering
:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then
$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.
§Worst-case complexity
$T(n) = O(n)$
$M(m) = O(m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(1, self.significant_bits() - bits)
.
§Panics
Let $k$ be bits
. Panics if rm
is RoundingMode::Exact
but self
is not
divisible by $2^k$.
§Examples
See here.
type Output = Natural
source§impl ShrRound<u32> for Natural
impl ShrRound<u32> for Natural
source§fn shr_round(self, bits: u32, rm: RoundingMode) -> (Natural, Ordering)
fn shr_round(self, bits: u32, rm: RoundingMode) -> (Natural, Ordering)
Shifts a Natural
right (divides it by a power of 2), taking it by value, and
rounds according to the specified rounding mode. An Ordering
is also returned,
indicating whether the returned value is less than, equal to, or greater than the
exact value.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$, and let $g$ be the function that just returns the first
element of the pair, without the Ordering
:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then
$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory and $n$ is self.significant_bits()
.
§Panics
Let $k$ be bits
. Panics if rm
is RoundingMode::Exact
but self
is not
divisible by $2^k$.
§Examples
See here.
type Output = Natural
source§impl<'a> ShrRound<u64> for &'a Natural
impl<'a> ShrRound<u64> for &'a Natural
source§fn shr_round(self, bits: u64, rm: RoundingMode) -> (Natural, Ordering)
fn shr_round(self, bits: u64, rm: RoundingMode) -> (Natural, Ordering)
Shifts a Natural
right (divides it by a power of 2), taking it by reference, and
rounds according to the specified rounding mode. An Ordering
is also returned,
indicating whether the returned value is less than, equal to, or greater than the
exact value.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$, and let $g$ be the function that just returns the first
element of the pair, without the Ordering
:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then
$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.
§Worst-case complexity
$T(n) = O(n)$
$M(m) = O(m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(1, self.significant_bits() - bits)
.
§Panics
Let $k$ be bits
. Panics if rm
is RoundingMode::Exact
but self
is not
divisible by $2^k$.
§Examples
See here.
type Output = Natural
source§impl ShrRound<u64> for Natural
impl ShrRound<u64> for Natural
source§fn shr_round(self, bits: u64, rm: RoundingMode) -> (Natural, Ordering)
fn shr_round(self, bits: u64, rm: RoundingMode) -> (Natural, Ordering)
Shifts a Natural
right (divides it by a power of 2), taking it by value, and
rounds according to the specified rounding mode. An Ordering
is also returned,
indicating whether the returned value is less than, equal to, or greater than the
exact value.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$, and let $g$ be the function that just returns the first
element of the pair, without the Ordering
:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then
$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory and $n$ is self.significant_bits()
.
§Panics
Let $k$ be bits
. Panics if rm
is RoundingMode::Exact
but self
is not
divisible by $2^k$.
§Examples
See here.
type Output = Natural
source§impl<'a> ShrRound<u8> for &'a Natural
impl<'a> ShrRound<u8> for &'a Natural
source§fn shr_round(self, bits: u8, rm: RoundingMode) -> (Natural, Ordering)
fn shr_round(self, bits: u8, rm: RoundingMode) -> (Natural, Ordering)
Shifts a Natural
right (divides it by a power of 2), taking it by reference, and
rounds according to the specified rounding mode. An Ordering
is also returned,
indicating whether the returned value is less than, equal to, or greater than the
exact value.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$, and let $g$ be the function that just returns the first
element of the pair, without the Ordering
:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then
$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.
§Worst-case complexity
$T(n) = O(n)$
$M(m) = O(m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(1, self.significant_bits() - bits)
.
§Panics
Let $k$ be bits
. Panics if rm
is RoundingMode::Exact
but self
is not
divisible by $2^k$.
§Examples
See here.
type Output = Natural
source§impl ShrRound<u8> for Natural
impl ShrRound<u8> for Natural
source§fn shr_round(self, bits: u8, rm: RoundingMode) -> (Natural, Ordering)
fn shr_round(self, bits: u8, rm: RoundingMode) -> (Natural, Ordering)
Shifts a Natural
right (divides it by a power of 2), taking it by value, and
rounds according to the specified rounding mode. An Ordering
is also returned,
indicating whether the returned value is less than, equal to, or greater than the
exact value.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$, and let $g$ be the function that just returns the first
element of the pair, without the Ordering
:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then
$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory and $n$ is self.significant_bits()
.
§Panics
Let $k$ be bits
. Panics if rm
is RoundingMode::Exact
but self
is not
divisible by $2^k$.
§Examples
See here.
type Output = Natural
source§impl<'a> ShrRound<usize> for &'a Natural
impl<'a> ShrRound<usize> for &'a Natural
source§fn shr_round(self, bits: usize, rm: RoundingMode) -> (Natural, Ordering)
fn shr_round(self, bits: usize, rm: RoundingMode) -> (Natural, Ordering)
Shifts a Natural
right (divides it by a power of 2), taking it by reference, and
rounds according to the specified rounding mode. An Ordering
is also returned,
indicating whether the returned value is less than, equal to, or greater than the
exact value.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$, and let $g$ be the function that just returns the first
element of the pair, without the Ordering
:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then
$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.
§Worst-case complexity
$T(n) = O(n)$
$M(m) = O(m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(1, self.significant_bits() - bits)
.
§Panics
Let $k$ be bits
. Panics if rm
is RoundingMode::Exact
but self
is not
divisible by $2^k$.
§Examples
See here.
type Output = Natural
source§impl ShrRound<usize> for Natural
impl ShrRound<usize> for Natural
source§fn shr_round(self, bits: usize, rm: RoundingMode) -> (Natural, Ordering)
fn shr_round(self, bits: usize, rm: RoundingMode) -> (Natural, Ordering)
Shifts a Natural
right (divides it by a power of 2), taking it by value, and
rounds according to the specified rounding mode. An Ordering
is also returned,
indicating whether the returned value is less than, equal to, or greater than the
exact value.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$, and let $g$ be the function that just returns the first
element of the pair, without the Ordering
:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Then
$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory and $n$ is self.significant_bits()
.
§Panics
Let $k$ be bits
. Panics if rm
is RoundingMode::Exact
but self
is not
divisible by $2^k$.
§Examples
See here.
type Output = Natural
source§impl ShrRoundAssign<i128> for Natural
impl ShrRoundAssign<i128> for Natural
source§fn shr_round_assign(&mut self, bits: i128, rm: RoundingMode) -> Ordering
fn shr_round_assign(&mut self, bits: i128, rm: RoundingMode) -> Ordering
Shifts a Natural
right (divides or multiplies it by a power of 2) and rounds
according to the specified rounding mode, in place. An Ordering
is returned,
indicating whether the assigned value is less than, equal to, or greater than the
exact value. If bits
is negative, then the returned Ordering
is always
Equal
, even if the higher bits of the result are lost.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
See the ShrRound
documentation for details.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(-bits, 0)
.
§Panics
Let $k$ be bits
. Panics if $k$ is positive and rm
is RoundingMode::Exact
but
self
is not divisible by $2^k$.
§Examples
See here.
source§impl ShrRoundAssign<i16> for Natural
impl ShrRoundAssign<i16> for Natural
source§fn shr_round_assign(&mut self, bits: i16, rm: RoundingMode) -> Ordering
fn shr_round_assign(&mut self, bits: i16, rm: RoundingMode) -> Ordering
Shifts a Natural
right (divides or multiplies it by a power of 2) and rounds
according to the specified rounding mode, in place. An Ordering
is returned,
indicating whether the assigned value is less than, equal to, or greater than the
exact value. If bits
is negative, then the returned Ordering
is always
Equal
, even if the higher bits of the result are lost.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
See the ShrRound
documentation for details.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(-bits, 0)
.
§Panics
Let $k$ be bits
. Panics if $k$ is positive and rm
is RoundingMode::Exact
but
self
is not divisible by $2^k$.
§Examples
See here.
source§impl ShrRoundAssign<i32> for Natural
impl ShrRoundAssign<i32> for Natural
source§fn shr_round_assign(&mut self, bits: i32, rm: RoundingMode) -> Ordering
fn shr_round_assign(&mut self, bits: i32, rm: RoundingMode) -> Ordering
Shifts a Natural
right (divides or multiplies it by a power of 2) and rounds
according to the specified rounding mode, in place. An Ordering
is returned,
indicating whether the assigned value is less than, equal to, or greater than the
exact value. If bits
is negative, then the returned Ordering
is always
Equal
, even if the higher bits of the result are lost.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
See the ShrRound
documentation for details.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(-bits, 0)
.
§Panics
Let $k$ be bits
. Panics if $k$ is positive and rm
is RoundingMode::Exact
but
self
is not divisible by $2^k$.
§Examples
See here.
source§impl ShrRoundAssign<i64> for Natural
impl ShrRoundAssign<i64> for Natural
source§fn shr_round_assign(&mut self, bits: i64, rm: RoundingMode) -> Ordering
fn shr_round_assign(&mut self, bits: i64, rm: RoundingMode) -> Ordering
Shifts a Natural
right (divides or multiplies it by a power of 2) and rounds
according to the specified rounding mode, in place. An Ordering
is returned,
indicating whether the assigned value is less than, equal to, or greater than the
exact value. If bits
is negative, then the returned Ordering
is always
Equal
, even if the higher bits of the result are lost.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
See the ShrRound
documentation for details.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(-bits, 0)
.
§Panics
Let $k$ be bits
. Panics if $k$ is positive and rm
is RoundingMode::Exact
but
self
is not divisible by $2^k$.
§Examples
See here.
source§impl ShrRoundAssign<i8> for Natural
impl ShrRoundAssign<i8> for Natural
source§fn shr_round_assign(&mut self, bits: i8, rm: RoundingMode) -> Ordering
fn shr_round_assign(&mut self, bits: i8, rm: RoundingMode) -> Ordering
Shifts a Natural
right (divides or multiplies it by a power of 2) and rounds
according to the specified rounding mode, in place. An Ordering
is returned,
indicating whether the assigned value is less than, equal to, or greater than the
exact value. If bits
is negative, then the returned Ordering
is always
Equal
, even if the higher bits of the result are lost.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
See the ShrRound
documentation for details.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(-bits, 0)
.
§Panics
Let $k$ be bits
. Panics if $k$ is positive and rm
is RoundingMode::Exact
but
self
is not divisible by $2^k$.
§Examples
See here.
source§impl ShrRoundAssign<isize> for Natural
impl ShrRoundAssign<isize> for Natural
source§fn shr_round_assign(&mut self, bits: isize, rm: RoundingMode) -> Ordering
fn shr_round_assign(&mut self, bits: isize, rm: RoundingMode) -> Ordering
Shifts a Natural
right (divides or multiplies it by a power of 2) and rounds
according to the specified rounding mode, in place. An Ordering
is returned,
indicating whether the assigned value is less than, equal to, or greater than the
exact value. If bits
is negative, then the returned Ordering
is always
Equal
, even if the higher bits of the result are lost.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>
.
To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
See the ShrRound
documentation for details.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is self.significant_bits()
, and
$m$ is max(-bits, 0)
.
§Panics
Let $k$ be bits
. Panics if $k$ is positive and rm
is RoundingMode::Exact
but
self
is not divisible by $2^k$.
§Examples
See here.
source§impl ShrRoundAssign<u128> for Natural
impl ShrRoundAssign<u128> for Natural
source§fn shr_round_assign(&mut self, bits: u128, rm: RoundingMode) -> Ordering
fn shr_round_assign(&mut self, bits: u128, rm: RoundingMode) -> Ordering
Shifts a Natural
right (divides it by a power of 2) and rounds according to the
specified rounding mode, in place. An Ordering
is returned, indicating whether
the assigned value is less than, equal to, or greater than the exact value.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>=
.
To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
See the ShrRound
documentation for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Let $k$ be bits
. Panics if rm
is RoundingMode::Exact
but self
is not
divisible by $2^k$.
§Examples
See here.
source§impl ShrRoundAssign<u16> for Natural
impl ShrRoundAssign<u16> for Natural
source§fn shr_round_assign(&mut self, bits: u16, rm: RoundingMode) -> Ordering
fn shr_round_assign(&mut self, bits: u16, rm: RoundingMode) -> Ordering
Shifts a Natural
right (divides it by a power of 2) and rounds according to the
specified rounding mode, in place. An Ordering
is returned, indicating whether
the assigned value is less than, equal to, or greater than the exact value.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>=
.
To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
See the ShrRound
documentation for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Let $k$ be bits
. Panics if rm
is RoundingMode::Exact
but self
is not
divisible by $2^k$.
§Examples
See here.
source§impl ShrRoundAssign<u32> for Natural
impl ShrRoundAssign<u32> for Natural
source§fn shr_round_assign(&mut self, bits: u32, rm: RoundingMode) -> Ordering
fn shr_round_assign(&mut self, bits: u32, rm: RoundingMode) -> Ordering
Shifts a Natural
right (divides it by a power of 2) and rounds according to the
specified rounding mode, in place. An Ordering
is returned, indicating whether
the assigned value is less than, equal to, or greater than the exact value.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>=
.
To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
See the ShrRound
documentation for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Let $k$ be bits
. Panics if rm
is RoundingMode::Exact
but self
is not
divisible by $2^k$.
§Examples
See here.
source§impl ShrRoundAssign<u64> for Natural
impl ShrRoundAssign<u64> for Natural
source§fn shr_round_assign(&mut self, bits: u64, rm: RoundingMode) -> Ordering
fn shr_round_assign(&mut self, bits: u64, rm: RoundingMode) -> Ordering
Shifts a Natural
right (divides it by a power of 2) and rounds according to the
specified rounding mode, in place. An Ordering
is returned, indicating whether
the assigned value is less than, equal to, or greater than the exact value.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>=
.
To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
See the ShrRound
documentation for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Let $k$ be bits
. Panics if rm
is RoundingMode::Exact
but self
is not
divisible by $2^k$.
§Examples
See here.
source§impl ShrRoundAssign<u8> for Natural
impl ShrRoundAssign<u8> for Natural
source§fn shr_round_assign(&mut self, bits: u8, rm: RoundingMode) -> Ordering
fn shr_round_assign(&mut self, bits: u8, rm: RoundingMode) -> Ordering
Shifts a Natural
right (divides it by a power of 2) and rounds according to the
specified rounding mode, in place. An Ordering
is returned, indicating whether
the assigned value is less than, equal to, or greater than the exact value.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>=
.
To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
See the ShrRound
documentation for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Let $k$ be bits
. Panics if rm
is RoundingMode::Exact
but self
is not
divisible by $2^k$.
§Examples
See here.
source§impl ShrRoundAssign<usize> for Natural
impl ShrRoundAssign<usize> for Natural
source§fn shr_round_assign(&mut self, bits: usize, rm: RoundingMode) -> Ordering
fn shr_round_assign(&mut self, bits: usize, rm: RoundingMode) -> Ordering
Shifts a Natural
right (divides it by a power of 2) and rounds according to the
specified rounding mode, in place. An Ordering
is returned, indicating whether
the assigned value is less than, equal to, or greater than the exact value.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using >>=
.
To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
See the ShrRound
documentation for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Let $k$ be bits
. Panics if rm
is RoundingMode::Exact
but self
is not
divisible by $2^k$.
§Examples
See here.
source§impl Sign for Natural
impl Sign for Natural
source§fn sign(&self) -> Ordering
fn sign(&self) -> Ordering
Compares a Natural
to zero.
Returns Greater
or Equal
depending on whether the Natural
is positive or zero,
respectively.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::arithmetic::traits::Sign;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
use core::cmp::Ordering;
assert_eq!(Natural::ZERO.sign(), Ordering::Equal);
assert_eq!(Natural::from(123u32).sign(), Ordering::Greater);
source§impl<'a> SignificantBits for &'a Natural
impl<'a> SignificantBits for &'a Natural
source§fn significant_bits(self) -> u64
fn significant_bits(self) -> u64
Returns the number of significant bits of a Natural
.
$$ f(n) = \begin{cases} 0 & \text{if} \quad n = 0, \\ \lfloor \log_2 n \rfloor + 1 & \text{if} \quad n > 0. \end{cases} $$
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::logic::traits::SignificantBits;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!(Natural::ZERO.significant_bits(), 0);
assert_eq!(Natural::from(100u32).significant_bits(), 7);
source§impl SqrtAssignRem for Natural
impl SqrtAssignRem for Natural
source§fn sqrt_assign_rem(&mut self) -> Natural
fn sqrt_assign_rem(&mut self) -> Natural
Replaces a Natural
with the floor of its square root and returns the remainder (the
difference between the original Natural
and the square of the floor).
$f(x) = x - \lfloor\sqrt{x}\rfloor^2$,
$x \gets \lfloor\sqrt{x}\rfloor$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::SqrtAssignRem;
use malachite_nz::natural::Natural;
let mut x = Natural::from(99u8);
assert_eq!(x.sqrt_assign_rem(), 18);
assert_eq!(x, 9);
let mut x = Natural::from(100u8);
assert_eq!(x.sqrt_assign_rem(), 0);
assert_eq!(x, 10);
let mut x = Natural::from(101u8);
assert_eq!(x.sqrt_assign_rem(), 1);
assert_eq!(x, 10);
let mut x = Natural::from(1000000000u32);
assert_eq!(x.sqrt_assign_rem(), 49116);
assert_eq!(x, 31622);
let mut x = Natural::from(10000000000u64);
assert_eq!(x.sqrt_assign_rem(), 0);
assert_eq!(x, 100000);
type RemOutput = Natural
source§impl<'a> SqrtRem for &'a Natural
impl<'a> SqrtRem for &'a Natural
source§fn sqrt_rem(self) -> (Natural, Natural)
fn sqrt_rem(self) -> (Natural, Natural)
Returns the floor of the square root of a Natural
and the remainder (the difference
between the Natural
and the square of the floor). The Natural
is taken by reference.
$f(x) = (\lfloor\sqrt{x}\rfloor, x - \lfloor\sqrt{x}\rfloor^2)$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::SqrtRem;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::from(99u8)).sqrt_rem().to_debug_string(), "(9, 18)");
assert_eq!((&Natural::from(100u8)).sqrt_rem().to_debug_string(), "(10, 0)");
assert_eq!((&Natural::from(101u8)).sqrt_rem().to_debug_string(), "(10, 1)");
assert_eq!((&Natural::from(1000000000u32)).sqrt_rem().to_debug_string(), "(31622, 49116)");
assert_eq!((&Natural::from(10000000000u64)).sqrt_rem().to_debug_string(), "(100000, 0)");
type SqrtOutput = Natural
type RemOutput = Natural
source§impl SqrtRem for Natural
impl SqrtRem for Natural
source§fn sqrt_rem(self) -> (Natural, Natural)
fn sqrt_rem(self) -> (Natural, Natural)
Returns the floor of the square root of a Natural
and the remainder (the difference
between the Natural
and the square of the floor). The Natural
is taken by value.
$f(x) = (\lfloor\sqrt{x}\rfloor, x - \lfloor\sqrt{x}\rfloor^2)$.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::SqrtRem;
use malachite_base::strings::ToDebugString;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(99u8).sqrt_rem().to_debug_string(), "(9, 18)");
assert_eq!(Natural::from(100u8).sqrt_rem().to_debug_string(), "(10, 0)");
assert_eq!(Natural::from(101u8).sqrt_rem().to_debug_string(), "(10, 1)");
assert_eq!(Natural::from(1000000000u32).sqrt_rem().to_debug_string(), "(31622, 49116)");
assert_eq!(Natural::from(10000000000u64).sqrt_rem().to_debug_string(), "(100000, 0)");
type SqrtOutput = Natural
type RemOutput = Natural
source§impl<'a> Square for &'a Natural
impl<'a> Square for &'a Natural
source§fn square(self) -> Natural
fn square(self) -> Natural
Squares a Natural
, taking it by reference.
$$ f(x) = x^2. $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::Square;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!((&Natural::ZERO).square(), 0);
assert_eq!((&Natural::from(123u32)).square(), 15129);
type Output = Natural
source§impl Square for Natural
impl Square for Natural
source§fn square(self) -> Natural
fn square(self) -> Natural
Squares a Natural
, taking it by value.
$$ f(x) = x^2. $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::Square;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!(Natural::ZERO.square(), 0);
assert_eq!(Natural::from(123u32).square(), 15129);
type Output = Natural
source§impl SquareAssign for Natural
impl SquareAssign for Natural
source§fn square_assign(&mut self)
fn square_assign(&mut self)
Squares a Natural
in place.
$$ x \gets x^2. $$
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::SquareAssign;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
let mut x = Natural::ZERO;
x.square_assign();
assert_eq!(x, 0);
let mut x = Natural::from(123u32);
x.square_assign();
assert_eq!(x, 15129);
source§impl<'a, 'b> Sub<&'a Natural> for &'b Natural
impl<'a, 'b> Sub<&'a Natural> for &'b Natural
source§fn sub(self, other: &'a Natural) -> Natural
fn sub(self, other: &'a Natural) -> Natural
Subtracts a Natural
by another Natural
, taking both by reference.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!(&Natural::from(123u32) - &Natural::ZERO, 123);
assert_eq!(&Natural::from(456u32) - &Natural::from(123u32), 333);
assert_eq!(
&(Natural::from(10u32).pow(12) * Natural::from(3u32)) - &Natural::from(10u32).pow(12),
2000000000000u64
);
source§impl<'a> Sub<&'a Natural> for Natural
impl<'a> Sub<&'a Natural> for Natural
source§fn sub(self, other: &'a Natural) -> Natural
fn sub(self, other: &'a Natural) -> Natural
Subtracts a Natural
by another Natural
, taking the first by value and the second by
reference.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(123u32) - &Natural::ZERO, 123);
assert_eq!(Natural::from(456u32) - &Natural::from(123u32), 333);
assert_eq!(
Natural::from(10u32).pow(12) * Natural::from(3u32) - &Natural::from(10u32).pow(12),
2000000000000u64
);
source§impl<'a> Sub<Natural> for &'a Natural
impl<'a> Sub<Natural> for &'a Natural
source§fn sub(self, other: Natural) -> Natural
fn sub(self, other: Natural) -> Natural
Subtracts a Natural
by another Natural
, taking the first by reference and the second
by value.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!(&Natural::from(123u32) - Natural::ZERO, 123);
assert_eq!(&Natural::from(456u32) - Natural::from(123u32), 333);
assert_eq!(
&(Natural::from(10u32).pow(12) * Natural::from(3u32)) - Natural::from(10u32).pow(12),
2000000000000u64
);
source§impl Sub for Natural
impl Sub for Natural
source§fn sub(self, other: Natural) -> Natural
fn sub(self, other: Natural) -> Natural
Subtracts a Natural
by another Natural
, taking both by value.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(123u32) - Natural::ZERO, 123);
assert_eq!(Natural::from(456u32) - Natural::from(123u32), 333);
assert_eq!(
Natural::from(10u32).pow(12) * Natural::from(3u32) - Natural::from(10u32).pow(12),
2000000000000u64
);
source§impl<'a> SubAssign<&'a Natural> for Natural
impl<'a> SubAssign<&'a Natural> for Natural
source§fn sub_assign(&mut self, other: &'a Natural)
fn sub_assign(&mut self, other: &'a Natural)
Subtracts a Natural
by another Natural
in place, taking the Natural
on the
right-hand side by reference.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is greater than self
.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_nz::natural::Natural;
let mut x = Natural::from(10u32).pow(12) * Natural::from(10u32);
x -= &Natural::from(10u32).pow(12);
x -= &(Natural::from(10u32).pow(12) * Natural::from(2u32));
x -= &(Natural::from(10u32).pow(12) * Natural::from(3u32));
x -= &(Natural::from(10u32).pow(12) * Natural::from(4u32));
assert_eq!(x, 0);
source§impl SubAssign for Natural
impl SubAssign for Natural
source§fn sub_assign(&mut self, other: Natural)
fn sub_assign(&mut self, other: Natural)
Subtracts a Natural
by another Natural
in place, taking the Natural
on the
right-hand side by value.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if other
is greater than self
.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_nz::natural::Natural;
let mut x = Natural::from(10u32).pow(12) * Natural::from(10u32);
x -= Natural::from(10u32).pow(12);
x -= Natural::from(10u32).pow(12) * Natural::from(2u32);
x -= Natural::from(10u32).pow(12) * Natural::from(3u32);
x -= Natural::from(10u32).pow(12) * Natural::from(4u32);
assert_eq!(x, 0);
source§impl<'a> SubMul<&'a Natural> for Natural
impl<'a> SubMul<&'a Natural> for Natural
source§fn sub_mul(self, y: &'a Natural, z: Natural) -> Natural
fn sub_mul(self, y: &'a Natural, z: Natural) -> Natural
Subtracts a Natural
by the product of two other Natural
s, taking the first and third
by value and the second by reference.
$$ f(x, y, z) = x - yz. $$
§Worst-case complexity
$T(n, m) = O(m + n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is max(y.significant_bits(), z.significant_bits())
, and $m$ is x.significant_bits()
.
§Panics
Panics if y * z
is greater than self
.
§Examples
use malachite_base::num::arithmetic::traits::{Pow, SubMul};
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(20u32).sub_mul(&Natural::from(3u32), Natural::from(4u32)), 8);
assert_eq!(
Natural::from(10u32).pow(12)
.sub_mul(&Natural::from(0x10000u32), Natural::from(0x10000u32)),
995705032704u64
);
type Output = Natural
source§impl<'a, 'b, 'c> SubMul<&'a Natural, &'b Natural> for &'c Natural
impl<'a, 'b, 'c> SubMul<&'a Natural, &'b Natural> for &'c Natural
source§fn sub_mul(self, y: &'a Natural, z: &'b Natural) -> Natural
fn sub_mul(self, y: &'a Natural, z: &'b Natural) -> Natural
Subtracts a Natural
by the product of two other Natural
s, taking all three by
reference.
$$ f(x, y, z) = x - yz. $$
§Worst-case complexity
$T(n, m) = O(m + n \log n \log\log n)$
$M(n, m) = O(m + n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is max(y.significant_bits(), z.significant_bits())
, and $m$ is x.significant_bits()
.
§Panics
Panics if y * z
is greater than self
.
§Examples
use malachite_base::num::arithmetic::traits::{Pow, SubMul};
use malachite_nz::natural::Natural;
assert_eq!((&Natural::from(20u32)).sub_mul(&Natural::from(3u32), &Natural::from(4u32)), 8);
assert_eq!(
(&Natural::from(10u32).pow(12))
.sub_mul(&Natural::from(0x10000u32), &Natural::from(0x10000u32)),
995705032704u64
);
type Output = Natural
source§impl<'a, 'b> SubMul<&'a Natural, &'b Natural> for Natural
impl<'a, 'b> SubMul<&'a Natural, &'b Natural> for Natural
source§fn sub_mul(self, y: &'a Natural, z: &'b Natural) -> Natural
fn sub_mul(self, y: &'a Natural, z: &'b Natural) -> Natural
Subtracts a Natural
by the product of two other Natural
s, taking the first by value
and the second and third by reference.
$$ f(x, y, z) = x - yz. $$
§Worst-case complexity
$T(n, m) = O(m + n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is max(y.significant_bits(), z.significant_bits())
, and $m$ is x.significant_bits()
.
§Panics
Panics if y * z
is greater than self
.
§Examples
use malachite_base::num::arithmetic::traits::{Pow, SubMul};
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(20u32).sub_mul(&Natural::from(3u32), &Natural::from(4u32)), 8);
assert_eq!(
Natural::from(10u32).pow(12)
.sub_mul(&Natural::from(0x10000u32), &Natural::from(0x10000u32)),
995705032704u64
);
type Output = Natural
source§impl<'a> SubMul<Natural, &'a Natural> for Natural
impl<'a> SubMul<Natural, &'a Natural> for Natural
source§fn sub_mul(self, y: Natural, z: &'a Natural) -> Natural
fn sub_mul(self, y: Natural, z: &'a Natural) -> Natural
Subtracts a Natural
by the product of two other Natural
s, taking the first two by
value and the third by reference.
$$ f(x, y, z) = x - yz. $$
§Worst-case complexity
$T(n, m) = O(m + n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is max(y.significant_bits(), z.significant_bits())
, and $m$ is x.significant_bits()
.
§Panics
Panics if y * z
is greater than self
.
§Examples
use malachite_base::num::arithmetic::traits::{Pow, SubMul};
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(20u32).sub_mul(Natural::from(3u32), &Natural::from(4u32)), 8);
assert_eq!(
Natural::from(10u32).pow(12)
.sub_mul(Natural::from(0x10000u32), &Natural::from(0x10000u32)),
995705032704u64
);
type Output = Natural
source§impl SubMul for Natural
impl SubMul for Natural
source§fn sub_mul(self, y: Natural, z: Natural) -> Natural
fn sub_mul(self, y: Natural, z: Natural) -> Natural
Subtracts a Natural
by the product of two other Natural
s, taking all three by value.
$$ f(x, y, z) = x - yz. $$
§Worst-case complexity
$T(n, m) = O(m + n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is max(y.significant_bits(), z.significant_bits())
, and $m$ is x.significant_bits()
.
§Panics
Panics if y * z
is greater than self
.
§Examples
use malachite_base::num::arithmetic::traits::{Pow, SubMul};
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(20u32).sub_mul(Natural::from(3u32), Natural::from(4u32)), 8);
assert_eq!(
Natural::from(10u32).pow(12)
.sub_mul(Natural::from(0x10000u32), Natural::from(0x10000u32)),
995705032704u64
);
type Output = Natural
source§impl<'a> SubMulAssign<&'a Natural> for Natural
impl<'a> SubMulAssign<&'a Natural> for Natural
source§fn sub_mul_assign(&mut self, y: &'a Natural, z: Natural)
fn sub_mul_assign(&mut self, y: &'a Natural, z: Natural)
Subtracts a Natural
by the product of two other Natural
s in place, taking the first
Natural
on the right-hand side by reference and the second by value.
$$ x \gets x - yz. $$
§Worst-case complexity
$T(n, m) = O(m + n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is max(y.significant_bits(), z.significant_bits())
, and $m$ is x.significant_bits()
.
§Panics
Panics if y * z
is greater than self
.
§Examples
use malachite_base::num::arithmetic::traits::{Pow, SubMulAssign};
use malachite_nz::natural::Natural;
let mut x = Natural::from(20u32);
x.sub_mul_assign(&Natural::from(3u32), Natural::from(4u32));
assert_eq!(x, 8);
let mut x = Natural::from(10u32).pow(12);
x.sub_mul_assign(&Natural::from(0x10000u32), Natural::from(0x10000u32));
assert_eq!(x, 995705032704u64);
source§impl<'a, 'b> SubMulAssign<&'a Natural, &'b Natural> for Natural
impl<'a, 'b> SubMulAssign<&'a Natural, &'b Natural> for Natural
source§fn sub_mul_assign(&mut self, y: &'a Natural, z: &'b Natural)
fn sub_mul_assign(&mut self, y: &'a Natural, z: &'b Natural)
Subtracts a Natural
by the product of two other Natural
s in place, taking both
Natural
s on the right-hand side by reference.
$$ x \gets x - yz. $$
§Worst-case complexity
$T(n, m) = O(m + n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is max(y.significant_bits(), z.significant_bits())
, and $m$ is x.significant_bits()
.
§Panics
Panics if y * z
is greater than self
.
§Examples
use malachite_base::num::arithmetic::traits::{Pow, SubMulAssign};
use malachite_nz::natural::Natural;
let mut x = Natural::from(20u32);
x.sub_mul_assign(&Natural::from(3u32), &Natural::from(4u32));
assert_eq!(x, 8);
let mut x = Natural::from(10u32).pow(12);
x.sub_mul_assign(&Natural::from(0x10000u32), &Natural::from(0x10000u32));
assert_eq!(x, 995705032704u64);
source§impl<'a> SubMulAssign<Natural, &'a Natural> for Natural
impl<'a> SubMulAssign<Natural, &'a Natural> for Natural
source§fn sub_mul_assign(&mut self, y: Natural, z: &'a Natural)
fn sub_mul_assign(&mut self, y: Natural, z: &'a Natural)
Subtracts a Natural
by the product of two other Natural
s in place, taking the first
Natural
on the right-hand side by value and the second by reference.
$$ x \gets x - yz. $$
§Worst-case complexity
$T(n, m) = O(m + n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is max(y.significant_bits(), z.significant_bits())
, and $m$ is x.significant_bits()
.
§Panics
Panics if y * z
is greater than self
.
§Examples
use malachite_base::num::arithmetic::traits::{Pow, SubMulAssign};
use malachite_nz::natural::Natural;
let mut x = Natural::from(20u32);
x.sub_mul_assign(Natural::from(3u32), &Natural::from(4u32));
assert_eq!(x, 8);
let mut x = Natural::from(10u32).pow(12);
x.sub_mul_assign(Natural::from(0x10000u32), &Natural::from(0x10000u32));
assert_eq!(x, 995705032704u64);
source§impl SubMulAssign for Natural
impl SubMulAssign for Natural
source§fn sub_mul_assign(&mut self, y: Natural, z: Natural)
fn sub_mul_assign(&mut self, y: Natural, z: Natural)
Subtracts a Natural
by the product of two other Natural
s in place, taking both
Natural
s on the right-hand side by value.
$$ x \gets x - yz. $$
§Worst-case complexity
$T(n, m) = O(m + n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, $n$ is max(y.significant_bits(), z.significant_bits())
, and $m$ is x.significant_bits()
.
§Panics
Panics if y * z
is greater than self
.
§Examples
use malachite_base::num::arithmetic::traits::{Pow, SubMulAssign};
use malachite_nz::natural::Natural;
let mut x = Natural::from(20u32);
x.sub_mul_assign(Natural::from(3u32), Natural::from(4u32));
assert_eq!(x, 8);
let mut x = Natural::from(10u32).pow(12);
x.sub_mul_assign(Natural::from(0x10000u32), Natural::from(0x10000u32));
assert_eq!(x, 995705032704u64);
source§impl Subfactorial for Natural
impl Subfactorial for Natural
source§fn subfactorial(n: u64) -> Natural
fn subfactorial(n: u64) -> Natural
Computes the subfactorial of a number.
The subfactorial of $n$ counts the number of derangements of a set of size $n$; a derangement is a permutation with no fixed points.
$$ f(n) = \ !n = \lfloor n!/e \rfloor. $$
$!n = O(n!) = O(\sqrt{n}(n/e)^n)$.
§Worst-case complexity
$T(n) = O(n^2)$
$M(n) = O(n)$
§Examples
use malachite_base::num::arithmetic::traits::Subfactorial;
use malachite_nz::natural::Natural;
assert_eq!(Natural::subfactorial(0), 1);
assert_eq!(Natural::subfactorial(1), 0);
assert_eq!(Natural::subfactorial(2), 1);
assert_eq!(Natural::subfactorial(3), 2);
assert_eq!(Natural::subfactorial(4), 9);
assert_eq!(Natural::subfactorial(5), 44);
assert_eq!(
Natural::subfactorial(100).to_string(),
"3433279598416380476519597752677614203236578380537578498354340028268518079332763243279\
1396429850988990237345920155783984828001486412574060553756854137069878601"
);
source§impl<'a> Sum<&'a Natural> for Natural
impl<'a> Sum<&'a Natural> for Natural
source§fn sum<I>(xs: I) -> Natural
fn sum<I>(xs: I) -> Natural
Adds up all the Natural
s in an iterator of Natural
references.
$$ f((x_i)_ {i=0}^{n-1}) = \sum_ {i=0}^{n-1} x_i. $$
§Worst-case complexity
$T(n) = O(n^2)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is
Natural::sum(xs.map(Natural::significant_bits))
.
§Examples
use malachite_base::vecs::vec_from_str;
use malachite_nz::natural::Natural;
use core::iter::Sum;
assert_eq!(Natural::sum(vec_from_str::<Natural>("[2, 3, 5, 7]").unwrap().iter()), 17);
source§impl Sum for Natural
impl Sum for Natural
source§fn sum<I>(xs: I) -> Natural
fn sum<I>(xs: I) -> Natural
Adds up all the Natural
s in an iterator.
$$ f((x_i)_ {i=0}^{n-1}) = \sum_ {i=0}^{n-1} x_i. $$
§Worst-case complexity
$T(n) = O(n^2)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is
Natural::sum(xs.map(Natural::significant_bits))
.
§Examples
use malachite_base::vecs::vec_from_str;
use malachite_nz::natural::Natural;
use core::iter::Sum;
assert_eq!(Natural::sum(vec_from_str::<Natural>("[2, 3, 5, 7]").unwrap().into_iter()), 17);
source§impl ToSci for Natural
impl ToSci for Natural
source§fn fmt_sci_valid(&self, options: ToSciOptions) -> bool
fn fmt_sci_valid(&self, options: ToSciOptions) -> bool
Determines whether a Natural
can be converted to a string using
to_sci
and a particular set of options.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::conversion::string::options::ToSciOptions;
use malachite_base::num::conversion::traits::ToSci;
use malachite_base::rounding_modes::RoundingMode;
use malachite_nz::natural::Natural;
let mut options = ToSciOptions::default();
assert!(Natural::from(123u8).fmt_sci_valid(options));
assert!(Natural::from(u128::MAX).fmt_sci_valid(options));
// u128::MAX has more than 16 significant digits
options.set_rounding_mode(RoundingMode::Exact);
assert!(!Natural::from(u128::MAX).fmt_sci_valid(options));
options.set_precision(50);
assert!(Natural::from(u128::MAX).fmt_sci_valid(options));
source§fn fmt_sci(&self, f: &mut Formatter<'_>, options: ToSciOptions) -> Result
fn fmt_sci(&self, f: &mut Formatter<'_>, options: ToSciOptions) -> Result
Converts a Natural
to a string using a specified base, possibly formatting the number
using scientific notation.
See ToSciOptions
for details on the available options. Note that setting
neg_exp_threshold
has no effect, since there is never a need to use negative exponents
when representing a Natural
.
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if options.rounding_mode
is Exact
, but the size options are such that the input
must be rounded.
§Examples
use malachite_base::num::conversion::string::options::ToSciOptions;
use malachite_base::num::conversion::traits::ToSci;
use malachite_base::rounding_modes::RoundingMode;
use malachite_nz::natural::Natural;
assert_eq!(format!("{}", Natural::from(u128::MAX).to_sci()), "3.402823669209385e38");
assert_eq!(Natural::from(u128::MAX).to_sci().to_string(), "3.402823669209385e38");
let n = Natural::from(123456u32);
let mut options = ToSciOptions::default();
assert_eq!(format!("{}", n.to_sci_with_options(options)), "123456");
assert_eq!(n.to_sci_with_options(options).to_string(), "123456");
options.set_precision(3);
assert_eq!(n.to_sci_with_options(options).to_string(), "1.23e5");
options.set_rounding_mode(RoundingMode::Ceiling);
assert_eq!(n.to_sci_with_options(options).to_string(), "1.24e5");
options.set_e_uppercase();
assert_eq!(n.to_sci_with_options(options).to_string(), "1.24E5");
options.set_force_exponent_plus_sign(true);
assert_eq!(n.to_sci_with_options(options).to_string(), "1.24E+5");
options = ToSciOptions::default();
options.set_base(36);
assert_eq!(n.to_sci_with_options(options).to_string(), "2n9c");
options.set_uppercase();
assert_eq!(n.to_sci_with_options(options).to_string(), "2N9C");
options.set_base(2);
options.set_precision(10);
assert_eq!(n.to_sci_with_options(options).to_string(), "1.1110001e16");
options.set_include_trailing_zeros(true);
assert_eq!(n.to_sci_with_options(options).to_string(), "1.111000100e16");
source§fn to_sci_with_options(&self, options: ToSciOptions) -> SciWrapper<'_, Self>
fn to_sci_with_options(&self, options: ToSciOptions) -> SciWrapper<'_, Self>
source§fn to_sci(&self) -> SciWrapper<'_, Self>
fn to_sci(&self) -> SciWrapper<'_, Self>
ToSciOptions
.source§impl ToStringBase for Natural
impl ToStringBase for Natural
source§fn to_string_base(&self, base: u8) -> String
fn to_string_base(&self, base: u8) -> String
Converts a Natural
to a String
using a specified base.
Digits from 0 to 9 become char
s from '0'
to '9'
. Digits from 10 to 35 become the
lowercase char
s 'a'
to 'z'
.
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if base
is less than 2 or greater than 36.
§Examples
use malachite_base::num::conversion::traits::ToStringBase;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(1000u32).to_string_base(2), "1111101000");
assert_eq!(Natural::from(1000u32).to_string_base(10), "1000");
assert_eq!(Natural::from(1000u32).to_string_base(36), "rs");
source§fn to_string_base_upper(&self, base: u8) -> String
fn to_string_base_upper(&self, base: u8) -> String
Converts a Natural
to a String
using a specified base.
Digits from 0 to 9 become char
s from '0'
to '9'
. Digits from 10 to 35 become the
uppercase char
s 'A'
to 'Z'
.
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Panics
Panics if base
is less than 2 or greater than 36.
§Examples
use malachite_base::num::conversion::traits::ToStringBase;
use malachite_nz::natural::Natural;
assert_eq!(Natural::from(1000u32).to_string_base_upper(2), "1111101000");
assert_eq!(Natural::from(1000u32).to_string_base_upper(10), "1000");
assert_eq!(Natural::from(1000u32).to_string_base_upper(36), "RS");
source§impl<'a> TryFrom<&'a Integer> for Natural
impl<'a> TryFrom<&'a Integer> for Natural
source§fn try_from(value: &'a Integer) -> Result<Natural, Self::Error>
fn try_from(value: &'a Integer) -> Result<Natural, Self::Error>
Converts an Integer
to a Natural
, taking the Natural
by reference. If the
Integer
is negative, an error is returned.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is value.significant_bits()
.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::strings::ToDebugString;
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;
assert_eq!(Natural::try_from(&Integer::from(123)).to_debug_string(), "Ok(123)");
assert_eq!(
Natural::try_from(&Integer::from(-123)).to_debug_string(),
"Err(NaturalFromIntegerError)"
);
assert_eq!(
Natural::try_from(&Integer::from(10u32).pow(12)).to_debug_string(),
"Ok(1000000000000)"
);
assert_eq!(
Natural::try_from(&(-Integer::from(10u32).pow(12))).to_debug_string(),
"Err(NaturalFromIntegerError)"
);
§type Error = NaturalFromIntegerError
type Error = NaturalFromIntegerError
source§impl<'a> TryFrom<&'a Natural> for f32
impl<'a> TryFrom<&'a Natural> for f32
source§impl<'a> TryFrom<&'a Natural> for f64
impl<'a> TryFrom<&'a Natural> for f64
source§impl<'a> TryFrom<&'a Natural> for i128
impl<'a> TryFrom<&'a Natural> for i128
source§impl<'a> TryFrom<&'a Natural> for i16
impl<'a> TryFrom<&'a Natural> for i16
source§impl<'a> TryFrom<&'a Natural> for i32
impl<'a> TryFrom<&'a Natural> for i32
source§impl<'a> TryFrom<&'a Natural> for i64
impl<'a> TryFrom<&'a Natural> for i64
source§impl<'a> TryFrom<&'a Natural> for i8
impl<'a> TryFrom<&'a Natural> for i8
source§impl<'a> TryFrom<&'a Natural> for isize
impl<'a> TryFrom<&'a Natural> for isize
source§impl<'a> TryFrom<&'a Natural> for u128
impl<'a> TryFrom<&'a Natural> for u128
source§impl<'a> TryFrom<&'a Natural> for u16
impl<'a> TryFrom<&'a Natural> for u16
source§impl<'a> TryFrom<&'a Natural> for u32
impl<'a> TryFrom<&'a Natural> for u32
source§impl<'a> TryFrom<&'a Natural> for u64
impl<'a> TryFrom<&'a Natural> for u64
source§impl<'a> TryFrom<&'a Natural> for u8
impl<'a> TryFrom<&'a Natural> for u8
source§impl<'a> TryFrom<&'a Natural> for usize
impl<'a> TryFrom<&'a Natural> for usize
source§impl TryFrom<Integer> for Natural
impl TryFrom<Integer> for Natural
source§fn try_from(value: Integer) -> Result<Natural, Self::Error>
fn try_from(value: Integer) -> Result<Natural, Self::Error>
Converts an Integer
to a Natural
, taking the Natural
by value. If the
Integer
is negative, an error is returned.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::strings::ToDebugString;
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;
assert_eq!(Natural::try_from(Integer::from(123)).to_debug_string(), "Ok(123)");
assert_eq!(
Natural::try_from(Integer::from(-123)).to_debug_string(),
"Err(NaturalFromIntegerError)"
);
assert_eq!(
Natural::try_from(Integer::from(10u32).pow(12)).to_debug_string(),
"Ok(1000000000000)"
);
assert_eq!(
Natural::try_from(-Integer::from(10u32).pow(12)).to_debug_string(),
"Err(NaturalFromIntegerError)"
);
§type Error = NaturalFromIntegerError
type Error = NaturalFromIntegerError
source§impl TryFrom<f32> for Natural
impl TryFrom<f32> for Natural
source§impl TryFrom<f64> for Natural
impl TryFrom<f64> for Natural
source§impl TryFrom<i128> for Natural
impl TryFrom<i128> for Natural
source§impl TryFrom<i16> for Natural
impl TryFrom<i16> for Natural
source§impl TryFrom<i32> for Natural
impl TryFrom<i32> for Natural
source§impl TryFrom<i64> for Natural
impl TryFrom<i64> for Natural
source§impl TryFrom<i8> for Natural
impl TryFrom<i8> for Natural
source§impl TryFrom<isize> for Natural
impl TryFrom<isize> for Natural
source§impl UpperHex for Natural
impl UpperHex for Natural
source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Converts a Natural
to a hexadecimal String
using uppercase characters.
Using the #
format flag prepends "0x"
to the string.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits()
.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_base::strings::ToUpperHexString;
use malachite_nz::natural::Natural;
use core::str::FromStr;
assert_eq!(Natural::ZERO.to_upper_hex_string(), "0");
assert_eq!(Natural::from(123u32).to_upper_hex_string(), "7B");
assert_eq!(
Natural::from_str("1000000000000").unwrap().to_upper_hex_string(),
"E8D4A51000"
);
assert_eq!(format!("{:07X}", Natural::from(123u32)), "000007B");
assert_eq!(format!("{:#X}", Natural::ZERO), "0x0");
assert_eq!(format!("{:#X}", Natural::from(123u32)), "0x7B");
assert_eq!(
format!("{:#X}", Natural::from_str("1000000000000").unwrap()),
"0xE8D4A51000"
);
assert_eq!(format!("{:#07X}", Natural::from(123u32)), "0x0007B");