Integer

Struct Integer 

pub struct Integer { /* private fields */ }
Expand description

An integer.

Any Integer whose absolute value is small enough to fit into a Limb is represented inline. Only integers outside this range incur the costs of heap-allocation.

Implementations§

§

impl Integer

pub const fn unsigned_abs_ref(&self) -> &Natural

Finds the absolute value of an Integer, taking the Integer by reference and returning a reference to the internal Natural absolute value.

$$ f(x) = |x|. $$

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_nz::integer::Integer;

assert_eq!(*Integer::ZERO.unsigned_abs_ref(), 0);
assert_eq!(*Integer::from(123).unsigned_abs_ref(), 123);
assert_eq!(*Integer::from(-123).unsigned_abs_ref(), 123);

pub fn mutate_unsigned_abs<F, T>(&mut self, f: F) -> T
where F: FnOnce(&mut Natural) -> T,

Mutates the absolute value of an Integer using a provided closure, and then returns whatever the closure returns.

This function is similar to the unsigned_abs_ref function, which returns a reference to the absolute value. A function that returns a mutable reference would be too dangerous, as it could leave the Integer in an invalid state (specifically, with a negative sign but a zero absolute value). So rather than returning a mutable reference, this function allows mutation of the absolute value using a closure. After the closure executes, this function ensures that the Integer remains valid.

There is only constant time and memory overhead on top of the time and memory used by the closure.

§Examples
use malachite_base::num::arithmetic::traits::DivAssignMod;
use malachite_base::num::basic::traits::Two;
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;

let mut n = Integer::from(-123);
let remainder = n.mutate_unsigned_abs(|x| x.div_assign_mod(Natural::TWO));
assert_eq!(n, -61);
assert_eq!(remainder, 1);

let mut n = Integer::from(-123);
n.mutate_unsigned_abs(|x| *x >>= 10);
assert_eq!(n, 0);
§

impl Integer

pub fn from_sign_and_abs(sign: bool, abs: Natural) -> Integer

Converts a sign and a Natural to an Integer, taking the Natural by value. The Natural becomes the Integer’s absolute value, and the sign indicates whether the Integer should be non-negative. If the Natural is zero, then the Integer will be non-negative regardless of the sign.

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;

assert_eq!(Integer::from_sign_and_abs(true, Natural::from(123u32)), 123);
assert_eq!(
    Integer::from_sign_and_abs(false, Natural::from(123u32)),
    -123
);

pub fn from_sign_and_abs_ref(sign: bool, abs: &Natural) -> Integer

Converts a sign and an Natural to an Integer, taking the Natural by reference. The Natural becomes the Integer’s absolute value, and the sign indicates whether the Integer should be non-negative. If the Natural is zero, then the Integer will be non-negative regardless of the sign.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, $n$ is abs.significant_bits().

§Examples
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;

assert_eq!(
    Integer::from_sign_and_abs_ref(true, &Natural::from(123u32)),
    123
);
assert_eq!(
    Integer::from_sign_and_abs_ref(false, &Natural::from(123u32)),
    -123
);
§

impl Integer

pub const fn const_from_unsigned(x: u64) -> Integer

Converts a Limb to an Integer.

This function is const, so it may be used to define constants.

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_nz::integer::Integer;

const TEN: Integer = Integer::const_from_unsigned(10);
assert_eq!(TEN, 10);

pub const fn const_from_signed(x: i64) -> Integer

Converts a SignedLimb to an Integer.

This function is const, so it may be used to define constants.

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_nz::integer::Integer;

const TEN: Integer = Integer::const_from_signed(10);
assert_eq!(TEN, 10);

const NEGATIVE_TEN: Integer = Integer::const_from_signed(-10);
assert_eq!(NEGATIVE_TEN, -10);
§

impl Integer

pub fn from_twos_complement_limbs_asc(xs: &[u64]) -> Integer

Converts a slice of limbs to an Integer, in ascending order, so that less significant limbs have lower indices in the input slice.

The limbs are in two’s complement, and the most significant bit of the limbs indicates the sign; if the bit is zero, the Integer is non-negative, and if the bit is one it is negative. If the slice is empty, zero is returned.

This function borrows a slice. If taking ownership of a Vec is possible instead, from_owned_twos_complement_limbs_asc is more efficient.

This function is more efficient than from_twos_complement_limbs_desc.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is xs.len().

§Examples
use malachite_base::num::basic::integers::PrimitiveInt;
use malachite_nz::integer::Integer;
use malachite_nz::platform::Limb;

if Limb::WIDTH == u32::WIDTH {
    assert_eq!(Integer::from_twos_complement_limbs_asc(&[]), 0);
    assert_eq!(Integer::from_twos_complement_limbs_asc(&[123]), 123);
    assert_eq!(Integer::from_twos_complement_limbs_asc(&[4294967173]), -123);
    // 10^12 = 232 * 2^32 + 3567587328
    assert_eq!(
        Integer::from_twos_complement_limbs_asc(&[3567587328, 232]),
        1000000000000u64
    );
    assert_eq!(
        Integer::from_twos_complement_limbs_asc(&[727379968, 4294967063]),
        -1000000000000i64
    );
}

pub fn from_twos_complement_limbs_desc(xs: &[u64]) -> Integer

Converts a slice of limbs to an Integer, in descending order, so that less significant limbs have higher indices in the input slice.

The limbs are in two’s complement, and the most significant bit of the limbs indicates the sign; if the bit is zero, the Integer is non-negative, and if the bit is one it is negative. If the slice is empty, zero is returned.

This function borrows a slice. If taking ownership of a Vec is possible instead, from_owned_twos_complement_limbs_desc is more efficient.

This function is less efficient than from_twos_complement_limbs_asc.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is xs.len().

§Examples
use malachite_base::num::basic::integers::PrimitiveInt;
use malachite_nz::integer::Integer;
use malachite_nz::platform::Limb;

if Limb::WIDTH == u32::WIDTH {
    assert_eq!(Integer::from_twos_complement_limbs_desc(&[]), 0);
    assert_eq!(Integer::from_twos_complement_limbs_desc(&[123]), 123);
    assert_eq!(
        Integer::from_twos_complement_limbs_desc(&[4294967173]),
        -123
    );
    // 10^12 = 232 * 2^32 + 3567587328
    assert_eq!(
        Integer::from_twos_complement_limbs_desc(&[232, 3567587328]),
        1000000000000u64
    );
    assert_eq!(
        Integer::from_twos_complement_limbs_desc(&[4294967063, 727379968]),
        -1000000000000i64
    );
}

pub fn from_owned_twos_complement_limbs_asc(xs: Vec<u64>) -> Integer

Converts a slice of limbs to an Integer, in ascending order, so that less significant limbs have lower indices in the input slice.

The limbs are in two’s complement, and the most significant bit of the limbs indicates the sign; if the bit is zero, the Integer is non-negative, and if the bit is one it is negative. If the slice is empty, zero is returned.

This function takes ownership of a Vec. If it’s necessary to borrow a slice instead, use from_twos_complement_limbs_asc

This function is more efficient than from_owned_twos_complement_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().

§Examples
use malachite_base::num::basic::integers::PrimitiveInt;
use malachite_nz::integer::Integer;
use malachite_nz::platform::Limb;

if Limb::WIDTH == u32::WIDTH {
    assert_eq!(Integer::from_owned_twos_complement_limbs_asc(vec![]), 0);
    assert_eq!(
        Integer::from_owned_twos_complement_limbs_asc(vec![123]),
        123
    );
    assert_eq!(
        Integer::from_owned_twos_complement_limbs_asc(vec![4294967173]),
        -123
    );
    // 10^12 = 232 * 2^32 + 3567587328
    assert_eq!(
        Integer::from_owned_twos_complement_limbs_asc(vec![3567587328, 232]),
        1000000000000i64
    );
    assert_eq!(
        Integer::from_owned_twos_complement_limbs_asc(vec![727379968, 4294967063]),
        -1000000000000i64
    );
}

pub fn from_owned_twos_complement_limbs_desc(xs: Vec<u64>) -> Integer

Converts a slice of limbs to an Integer, in descending order, so that less significant limbs have higher indices in the input slice.

The limbs are in two’s complement, and the most significant bit of the limbs indicates the sign; if the bit is zero, the Integer is non-negative, and if the bit is one it is negative. If the slice is empty, zero is returned.

This function takes ownership of a Vec. If it’s necessary to borrow a slice instead, use from_twos_complement_limbs_desc.

This function is less efficient than from_owned_twos_complement_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().

§Examples
use malachite_base::num::basic::integers::PrimitiveInt;
use malachite_nz::integer::Integer;
use malachite_nz::platform::Limb;

if Limb::WIDTH == u32::WIDTH {
    assert_eq!(Integer::from_owned_twos_complement_limbs_desc(vec![]), 0);
    assert_eq!(
        Integer::from_owned_twos_complement_limbs_desc(vec![123]),
        123
    );
    assert_eq!(
        Integer::from_owned_twos_complement_limbs_desc(vec![4294967173]),
        -123
    );
    // 10^12 = 232 * 2^32 + 3567587328
    assert_eq!(
        Integer::from_owned_twos_complement_limbs_desc(vec![232, 3567587328]),
        1000000000000i64
    );
    assert_eq!(
        Integer::from_owned_twos_complement_limbs_desc(vec![4294967063, 727379968]),
        -1000000000000i64
    );
}
§

impl Integer

pub fn to_twos_complement_limbs_asc(&self) -> Vec<u64>

Returns the limbs of an Integer, in ascending order, so that less significant limbs have lower indices in the output vector.

The limbs are in two’s complement, and the most significant bit of the limbs indicates the sign; if the bit is zero, the Integer is positive, and if the bit is one it is negative. There are no trailing zero limbs if the Integer is positive or trailing Limb::MAX limbs if the Integer is negative, except as necessary to include the correct sign bit. Zero is a special case: it contains no limbs.

This function borrows self. If taking ownership of self is possible, into_twos_complement_limbs_asc is more efficient.

This function is more efficient than to_twos_complement_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::integer::Integer;
use malachite_nz::platform::Limb;

if Limb::WIDTH == u32::WIDTH {
    assert!(Integer::ZERO.to_twos_complement_limbs_asc().is_empty());
    assert_eq!(Integer::from(123).to_twos_complement_limbs_asc(), &[123]);
    assert_eq!(
        Integer::from(-123).to_twos_complement_limbs_asc(),
        &[4294967173]
    );
    // 10^12 = 232 * 2^32 + 3567587328
    assert_eq!(
        Integer::from(10u32).pow(12).to_twos_complement_limbs_asc(),
        &[3567587328, 232]
    );
    assert_eq!(
        (-Integer::from(10u32).pow(12)).to_twos_complement_limbs_asc(),
        &[727379968, 4294967063]
    );
}

pub fn to_twos_complement_limbs_desc(&self) -> Vec<u64>

Returns the limbs of an Integer, in descending order, so that less significant limbs have higher indices in the output vector.

The limbs are in two’s complement, and the most significant bit of the limbs indicates the sign; if the bit is zero, the Integer is positive, and if the bit is one it is negative. There are no leading zero limbs if the Integer is non-negative or leading Limb::MAX limbs if the Integer is negative, except as necessary to include the correct sign bit. Zero is a special case: it contains no limbs.

This is similar to how BigIntegers in Java are represented.

This function borrows self. If taking ownership of self is possible, into_twos_complement_limbs_desc is more efficient.

This function is less efficient than to_twos_complement_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::integer::Integer;
use malachite_nz::platform::Limb;

if Limb::WIDTH == u32::WIDTH {
    assert!(Integer::ZERO.to_twos_complement_limbs_desc().is_empty());
    assert_eq!(Integer::from(123).to_twos_complement_limbs_desc(), &[123]);
    assert_eq!(
        Integer::from(-123).to_twos_complement_limbs_desc(),
        &[4294967173]
    );
    // 10^12 = 232 * 2^32 + 3567587328
    assert_eq!(
        Integer::from(10u32).pow(12).to_twos_complement_limbs_desc(),
        &[232, 3567587328]
    );
    assert_eq!(
        (-Integer::from(10u32).pow(12)).to_twos_complement_limbs_desc(),
        &[4294967063, 727379968]
    );
}

pub fn into_twos_complement_limbs_asc(self) -> Vec<u64>

Returns the limbs of an Integer, in ascending order, so that less significant limbs have lower indices in the output vector.

The limbs are in two’s complement, and the most significant bit of the limbs indicates the sign; if the bit is zero, the Integer is positive, and if the bit is one it is negative. There are no trailing zero limbs if the Integer is positive or trailing Limb::MAX limbs if the Integer is negative, except as necessary to include the correct sign bit. Zero is a special case: it contains no limbs.

This function takes ownership of self. If it’s necessary to borrow self instead, use to_twos_complement_limbs_asc.

This function is more efficient than into_twos_complement_limbs_desc.

§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::integer::Integer;
use malachite_nz::platform::Limb;

if Limb::WIDTH == u32::WIDTH {
    assert!(Integer::ZERO.into_twos_complement_limbs_asc().is_empty());
    assert_eq!(Integer::from(123).into_twos_complement_limbs_asc(), &[123]);
    assert_eq!(
        Integer::from(-123).into_twos_complement_limbs_asc(),
        &[4294967173]
    );
    // 10^12 = 232 * 2^32 + 3567587328
    assert_eq!(
        Integer::from(10u32)
            .pow(12)
            .into_twos_complement_limbs_asc(),
        &[3567587328, 232]
    );
    assert_eq!(
        (-Integer::from(10u32).pow(12)).into_twos_complement_limbs_asc(),
        &[727379968, 4294967063]
    );
}

pub fn into_twos_complement_limbs_desc(self) -> Vec<u64>

Returns the limbs of an Integer, in descending order, so that less significant limbs have higher indices in the output vector.

The limbs are in two’s complement, and the most significant bit of the limbs indicates the sign; if the bit is zero, the Integer is positive, and if the bit is one it is negative. There are no leading zero limbs if the Integer is non-negative or leading Limb::MAX limbs if the Integer is negative, except as necessary to include the correct sign bit. Zero is a special case: it contains no limbs.

This is similar to how BigIntegers in Java are represented.

This function takes ownership of self. If it’s necessary to borrow self instead, use to_twos_complement_limbs_desc.

This function is less efficient than into_twos_complement_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::integer::Integer;
use malachite_nz::platform::Limb;

if Limb::WIDTH == u32::WIDTH {
    assert!(Integer::ZERO.into_twos_complement_limbs_desc().is_empty());
    assert_eq!(Integer::from(123).into_twos_complement_limbs_desc(), &[123]);
    assert_eq!(
        Integer::from(-123).into_twos_complement_limbs_desc(),
        &[4294967173]
    );
    // 10^12 = 232 * 2^32 + 3567587328
    assert_eq!(
        Integer::from(10u32)
            .pow(12)
            .into_twos_complement_limbs_desc(),
        &[232, 3567587328]
    );
    assert_eq!(
        (-Integer::from(10u32).pow(12)).into_twos_complement_limbs_desc(),
        &[4294967063, 727379968]
    );
}

pub fn twos_complement_limbs(&self) -> TwosComplementLimbIterator<'_>

Returns a double-ended iterator over the twos-complement limbs of an Integer.

The forward order is ascending, so that less significant limbs appear first. There may be a most-significant sign-extension limb.

If it’s necessary to get a Vec of all the twos_complement limbs, consider using to_twos_complement_limbs_asc, to_twos_complement_limbs_desc, into_twos_complement_limbs_asc, or into_twos_complement_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::integer::Integer;
use malachite_nz::platform::Limb;

if Limb::WIDTH == u32::WIDTH {
    assert!(Integer::ZERO.twos_complement_limbs().next().is_none());
    assert_eq!(
        Integer::from(123).twos_complement_limbs().collect_vec(),
        &[123]
    );
    assert_eq!(
        Integer::from(-123).twos_complement_limbs().collect_vec(),
        &[4294967173]
    );
    // 10^12 = 232 * 2^32 + 3567587328
    assert_eq!(
        Integer::from(10u32)
            .pow(12)
            .twos_complement_limbs()
            .collect_vec(),
        &[3567587328, 232]
    );
    // Sign-extension for a non-negative `Integer`
    assert_eq!(
        Integer::from(4294967295i64)
            .twos_complement_limbs()
            .collect_vec(),
        &[4294967295, 0]
    );
    assert_eq!(
        (-Integer::from(10u32).pow(12))
            .twos_complement_limbs()
            .collect_vec(),
        &[727379968, 4294967063]
    );
    // Sign-extension for a negative `Integer`
    assert_eq!(
        (-Integer::from(4294967295i64))
            .twos_complement_limbs()
            .collect_vec(),
        &[1, 4294967295]
    );

    assert!(Integer::ZERO.twos_complement_limbs().next_back().is_none());
    assert_eq!(
        Integer::from(123)
            .twos_complement_limbs()
            .rev()
            .collect_vec(),
        &[123]
    );
    assert_eq!(
        Integer::from(-123)
            .twos_complement_limbs()
            .rev()
            .collect_vec(),
        &[4294967173]
    );
    // 10^12 = 232 * 2^32 + 3567587328
    assert_eq!(
        Integer::from(10u32)
            .pow(12)
            .twos_complement_limbs()
            .rev()
            .collect_vec(),
        &[232, 3567587328]
    );
    // Sign-extension for a non-negative `Integer`
    assert_eq!(
        Integer::from(4294967295i64)
            .twos_complement_limbs()
            .rev()
            .collect_vec(),
        &[0, 4294967295]
    );
    assert_eq!(
        (-Integer::from(10u32).pow(12))
            .twos_complement_limbs()
            .rev()
            .collect_vec(),
        &[4294967063, 727379968]
    );
    // Sign-extension for a negative `Integer`
    assert_eq!(
        (-Integer::from(4294967295i64))
            .twos_complement_limbs()
            .rev()
            .collect_vec(),
        &[4294967295, 1]
    );
}

pub fn twos_complement_limb_count(&self) -> u64

Returns the number of twos-complement limbs of an Integer. There may be a most-significant sign-extension limb, which is included in the count.

Zero has 0 limbs.

§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, PowerOf2};
use malachite_base::num::basic::integers::PrimitiveInt;
use malachite_base::num::basic::traits::{One, Zero};
use malachite_nz::integer::Integer;
use malachite_nz::platform::Limb;

if Limb::WIDTH == u32::WIDTH {
    assert_eq!(Integer::ZERO.twos_complement_limb_count(), 0);
    assert_eq!(Integer::from(123u32).twos_complement_limb_count(), 1);
    assert_eq!(Integer::from(10u32).pow(12).twos_complement_limb_count(), 2);

    let n = Integer::power_of_2(Limb::WIDTH - 1);
    assert_eq!((&n - Integer::ONE).twos_complement_limb_count(), 1);
    assert_eq!(n.twos_complement_limb_count(), 2);
    assert_eq!((&n + Integer::ONE).twos_complement_limb_count(), 2);
    assert_eq!((-(&n - Integer::ONE)).twos_complement_limb_count(), 1);
    assert_eq!((-&n).twos_complement_limb_count(), 1);
    assert_eq!((-(&n + Integer::ONE)).twos_complement_limb_count(), 2);
}
§

impl Integer

pub fn checked_count_ones(&self) -> Option<u64>

Counts the number of ones in the binary expansion of an Integer. If the Integer is negative, then the number of ones is infinite, so None is returned.

§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::integer::Integer;

assert_eq!(Integer::ZERO.checked_count_ones(), Some(0));
// 105 = 1101001b
assert_eq!(Integer::from(105).checked_count_ones(), Some(4));
assert_eq!(Integer::from(-105).checked_count_ones(), None);
// 10^12 = 1110100011010100101001010001000000000000b
assert_eq!(Integer::from(10u32).pow(12).checked_count_ones(), Some(13));
§

impl Integer

pub fn checked_count_zeros(&self) -> Option<u64>

Counts the number of zeros in the binary expansion of an Integer. If the Integer is non-negative, then the number of zeros is infinite, so None is returned.

§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::integer::Integer;

assert_eq!(Integer::ZERO.checked_count_zeros(), None);
// -105 = 10010111 in two's complement
assert_eq!(Integer::from(-105).checked_count_zeros(), Some(3));
assert_eq!(Integer::from(105).checked_count_zeros(), None);
// -10^12 = 10001011100101011010110101111000000000000 in two's complement
assert_eq!(
    (-Integer::from(10u32).pow(12)).checked_count_zeros(),
    Some(24)
);
§

impl Integer

pub fn trailing_zeros(&self) -> Option<u64>

Returns the number of trailing zeros in the binary expansion of an Integer (equivalently, the multiplicity of 2 in its prime factorization), or None is the Integer 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::integer::Integer;

assert_eq!(Integer::ZERO.trailing_zeros(), None);
assert_eq!(Integer::from(3).trailing_zeros(), Some(0));
assert_eq!(Integer::from(-72).trailing_zeros(), Some(3));
assert_eq!(Integer::from(100).trailing_zeros(), Some(2));
assert_eq!((-Integer::from(10u32).pow(12)).trailing_zeros(), Some(12));

Trait Implementations§

§

impl Abs for &Integer

§

fn abs(self) -> Integer

Takes the absolute value of an Integer, taking the Integer by reference.

$$ 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::arithmetic::traits::Abs;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::integer::Integer;

assert_eq!((&Integer::ZERO).abs(), 0);
assert_eq!((&Integer::from(123)).abs(), 123);
assert_eq!((&Integer::from(-123)).abs(), 123);
§

type Output = Integer

§

impl Abs for Integer

§

fn abs(self) -> Integer

Takes the absolute value of an Integer, taking the Integer by value.

$$ f(x) = |x|. $$

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::num::arithmetic::traits::Abs;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::integer::Integer;

assert_eq!(Integer::ZERO.abs(), 0);
assert_eq!(Integer::from(123).abs(), 123);
assert_eq!(Integer::from(-123).abs(), 123);
§

type Output = Integer

§

impl AbsAssign for Integer

§

fn abs_assign(&mut self)

Replaces an Integer with its absolute value.

$$ x \gets |x|. $$

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::num::arithmetic::traits::AbsAssign;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::integer::Integer;

let mut x = Integer::ZERO;
x.abs_assign();
assert_eq!(x, 0);

let mut x = Integer::from(123);
x.abs_assign();
assert_eq!(x, 123);

let mut x = Integer::from(-123);
x.abs_assign();
assert_eq!(x, 123);
§

impl AbsDiff<&Integer> for &Integer

§

fn abs_diff(self, other: &Integer) -> Natural

Computes the absolute value of the difference between two Integers, taking both by reference. A Natural is returned.

$$ 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::{AbsDiff, Pow};
use malachite_base::num::basic::traits::Zero;
use malachite_nz::integer::Integer;

assert_eq!((&Integer::from(123)).abs_diff(&Integer::ZERO), 123);
assert_eq!((&Integer::ZERO).abs_diff(&Integer::from(123)), 123);
assert_eq!((&Integer::from(456)).abs_diff(&Integer::from(-123)), 579);
assert_eq!((&Integer::from(123)).abs_diff(&Integer::from(-456)), 579);
assert_eq!(
    (&(Integer::from(10).pow(12) * Integer::from(3))).abs_diff(&Integer::from(10).pow(12)),
    2000000000000u64
);
assert_eq!(
    (&(-Integer::from(10).pow(12)))
        .abs_diff(&(-Integer::from(10).pow(12) * Integer::from(3))),
    2000000000000u64
);
§

type Output = Natural

§

impl AbsDiff<&Integer> for Integer

§

fn abs_diff(self, other: &Integer) -> Natural

Computes the absolute value of the difference between two Integers, taking the first by value and the second by reference. A Natural is returned.

$$ f(x, y) = |x - y|. $$

§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::arithmetic::traits::{AbsDiff, Pow};
use malachite_base::num::basic::traits::Zero;
use malachite_nz::integer::Integer;

assert_eq!(Integer::from(123).abs_diff(&Integer::ZERO), 123);
assert_eq!(Integer::ZERO.abs_diff(&Integer::from(123)), 123);
assert_eq!(Integer::from(456).abs_diff(&Integer::from(-123)), 579);
assert_eq!(Integer::from(123).abs_diff(&Integer::from(-456)), 579);
assert_eq!(
    (Integer::from(10).pow(12) * Integer::from(3)).abs_diff(&Integer::from(10).pow(12)),
    2000000000000u64
);
assert_eq!(
    (-Integer::from(10).pow(12)).abs_diff(&(-Integer::from(10).pow(12) * Integer::from(3))),
    2000000000000u64
);
§

type Output = Natural

§

impl AbsDiff<Integer> for &Integer

§

fn abs_diff(self, other: Integer) -> Natural

Computes the absolute value of the difference between two Integers, taking the first by reference and the second by value. A Natural is returned.

$$ 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::{AbsDiff, Pow};
use malachite_base::num::basic::traits::Zero;
use malachite_nz::integer::Integer;

assert_eq!((&Integer::from(123)).abs_diff(Integer::ZERO), 123);
assert_eq!((&Integer::ZERO).abs_diff(Integer::from(123)), 123);
assert_eq!((&Integer::from(456)).abs_diff(Integer::from(-123)), 579);
assert_eq!((&Integer::from(123)).abs_diff(Integer::from(-456)), 579);
assert_eq!(
    (&(Integer::from(10).pow(12) * Integer::from(3))).abs_diff(Integer::from(10).pow(12)),
    2000000000000u64
);
assert_eq!(
    (&(-Integer::from(10).pow(12))).abs_diff(-Integer::from(10).pow(12) * Integer::from(3)),
    2000000000000u64
);
§

type Output = Natural

§

impl AbsDiff for Integer

§

fn abs_diff(self, other: Integer) -> Natural

Computes the absolute value of the difference between two Integers, taking both by value. A Natural is returned.

$$ f(x, y) = |x - y|. $$

§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::{AbsDiff, Pow};
use malachite_base::num::basic::traits::Zero;
use malachite_nz::integer::Integer;

assert_eq!(Integer::from(123).abs_diff(Integer::ZERO), 123);
assert_eq!(Integer::ZERO.abs_diff(Integer::from(123)), 123);
assert_eq!(Integer::from(456).abs_diff(Integer::from(-123)), 579);
assert_eq!(Integer::from(123).abs_diff(Integer::from(-456)), 579);
assert_eq!(
    (Integer::from(10).pow(12) * Integer::from(3)).abs_diff(Integer::from(10).pow(12)),
    2000000000000u64
);
assert_eq!(
    (-Integer::from(10).pow(12)).abs_diff(-Integer::from(10).pow(12) * Integer::from(3)),
    2000000000000u64
);
§

type Output = Natural

§

impl<'a> AbsDiffAssign<&'a Integer> for Integer

§

fn abs_diff_assign(&mut self, other: &'a Integer)

Subtracts an Integer by another Integer in place and takes the absolute value, taking the Integer on the right-hand side by reference.

$$ x \gets |x - y|. $$

§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()).

§Panics

Panics if other is greater than self.

§Examples
use malachite_base::num::arithmetic::traits::{AbsDiffAssign, Pow};
use malachite_base::num::basic::traits::Zero;
use malachite_nz::integer::Integer;

let mut x = Integer::from(123);
x.abs_diff_assign(&Integer::ZERO);
assert_eq!(x, 123);

let mut x = Integer::ZERO;
x.abs_diff_assign(&Integer::from(123));
assert_eq!(x, 123);

let mut x = Integer::from(456);
x.abs_diff_assign(&Integer::from(-123));
assert_eq!(x, 579);

let mut x = Integer::from(-123);
x.abs_diff_assign(&Integer::from(456));
assert_eq!(x, 579);

let mut x = Integer::from(10).pow(12) * Integer::from(3);
x.abs_diff_assign(&Integer::from(10u32).pow(12));
assert_eq!(x, 2000000000000u64);

let mut x = -Integer::from(10u32).pow(12);
x.abs_diff_assign(&(-(Integer::from(10).pow(12) * Integer::from(3))));
assert_eq!(x, 2000000000000u64);
§

impl AbsDiffAssign for Integer

§

fn abs_diff_assign(&mut self, other: Integer)

Subtracts an Integer by another Integer in place and takes the absolute value, taking the Integer on the right-hand side by value.

$$ x \gets |x - y|. $$

§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()).

§Panics

Panics if other is greater than self.

§Examples
use malachite_base::num::arithmetic::traits::{AbsDiffAssign, Pow};
use malachite_base::num::basic::traits::Zero;
use malachite_nz::integer::Integer;

let mut x = Integer::from(123);
x.abs_diff_assign(Integer::ZERO);
assert_eq!(x, 123);

let mut x = Integer::ZERO;
x.abs_diff_assign(Integer::from(123));
assert_eq!(x, 123);

let mut x = Integer::from(456);
x.abs_diff_assign(Integer::from(-123));
assert_eq!(x, 579);

let mut x = Integer::from(-123);
x.abs_diff_assign(Integer::from(456));
assert_eq!(x, 579);

let mut x = Integer::from(10).pow(12) * Integer::from(3);
x.abs_diff_assign(Integer::from(10u32).pow(12));
assert_eq!(x, 2000000000000u64);

let mut x = -Integer::from(10u32).pow(12);
x.abs_diff_assign(-(Integer::from(10).pow(12) * Integer::from(3)));
assert_eq!(x, 2000000000000u64);
§

impl Add<&Integer> for &Integer

§

fn add(self, other: &Integer) -> Integer

Adds two Integers, 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::integer::Integer;

assert_eq!(&Integer::ZERO + &Integer::from(123), 123);
assert_eq!(&Integer::from(-123) + &Integer::ZERO, -123);
assert_eq!(&Integer::from(-123) + &Integer::from(456), 333);
assert_eq!(
    &-Integer::from(10u32).pow(12) + &(Integer::from(10u32).pow(12) << 1),
    1000000000000u64
);
§

type Output = Integer

The resulting type after applying the + operator.
§

impl Add<&Integer> for Integer

§

fn add(self, other: &Integer) -> Integer

Adds two Integers, 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::integer::Integer;

assert_eq!(Integer::ZERO + &Integer::from(123), 123);
assert_eq!(Integer::from(-123) + &Integer::ZERO, -123);
assert_eq!(Integer::from(-123) + &Integer::from(456), 333);
assert_eq!(
    -Integer::from(10u32).pow(12) + &(Integer::from(10u32).pow(12) << 1),
    1000000000000u64
);
§

type Output = Integer

The resulting type after applying the + operator.
§

impl Add<Integer> for &Integer

§

fn add(self, other: Integer) -> Integer

Adds two Integers, 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::integer::Integer;

assert_eq!(&Integer::ZERO + Integer::from(123), 123);
assert_eq!(&Integer::from(-123) + Integer::ZERO, -123);
assert_eq!(&Integer::from(-123) + Integer::from(456), 333);
assert_eq!(
    &-Integer::from(10u32).pow(12) + (Integer::from(10u32).pow(12) << 1),
    1000000000000u64
);
§

type Output = Integer

The resulting type after applying the + operator.
§

impl Add for Integer

§

fn add(self, other: Integer) -> Integer

Adds two Integers, 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::integer::Integer;

assert_eq!(Integer::ZERO + Integer::from(123), 123);
assert_eq!(Integer::from(-123) + Integer::ZERO, -123);
assert_eq!(Integer::from(-123) + Integer::from(456), 333);
assert_eq!(
    -Integer::from(10u32).pow(12) + (Integer::from(10u32).pow(12) << 1),
    1000000000000u64
);
§

type Output = Integer

The resulting type after applying the + operator.
§

impl AddAssign<&Integer> for Integer

§

fn add_assign(&mut self, other: &Integer)

Adds an Integer to an Integer in place, taking the Integer 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::integer::Integer;

let mut x = Integer::ZERO;
x += &(-Integer::from(10u32).pow(12));
x += &(Integer::from(10u32).pow(12) * Integer::from(2u32));
x += &(-Integer::from(10u32).pow(12) * Integer::from(3u32));
x += &(Integer::from(10u32).pow(12) * Integer::from(4u32));
assert_eq!(x, 2000000000000u64);
§

impl AddAssign for Integer

§

fn add_assign(&mut self, other: Integer)

Adds an Integer to an Integer in place, taking the Integer 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::integer::Integer;

let mut x = Integer::ZERO;
x += -Integer::from(10u32).pow(12);
x += Integer::from(10u32).pow(12) * Integer::from(2u32);
x += -Integer::from(10u32).pow(12) * Integer::from(3u32);
x += Integer::from(10u32).pow(12) * Integer::from(4u32);
assert_eq!(x, 2000000000000u64);
§

impl<'a> AddMul<&'a Integer> for Integer

§

fn add_mul(self, y: &'a Integer, z: Integer) -> Integer

Adds an Integer and the product of two other Integers, 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::integer::Integer;

assert_eq!(
    Integer::from(10u32).add_mul(&Integer::from(3u32), Integer::from(4u32)),
    22
);
assert_eq!(
    (-Integer::from(10u32).pow(12))
        .add_mul(&Integer::from(0x10000), -Integer::from(10u32).pow(12)),
    -65537000000000000i64
);
§

type Output = Integer

§

impl AddMul<&Integer, &Integer> for &Integer

§

fn add_mul(self, y: &Integer, z: &Integer) -> Integer

Adds an Integer and the product of two other Integers, 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::integer::Integer;

assert_eq!(
    (&Integer::from(10u32)).add_mul(&Integer::from(3u32), &Integer::from(4u32)),
    22
);
assert_eq!(
    (&-Integer::from(10u32).pow(12))
        .add_mul(&Integer::from(0x10000), &-Integer::from(10u32).pow(12)),
    -65537000000000000i64
);
§

type Output = Integer

§

impl<'a, 'b> AddMul<&'a Integer, &'b Integer> for Integer

§

fn add_mul(self, y: &'a Integer, z: &'b Integer) -> Integer

Adds an Integer and the product of two other Integers, 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::integer::Integer;

assert_eq!(
    Integer::from(10u32).add_mul(&Integer::from(3u32), &Integer::from(4u32)),
    22
);
assert_eq!(
    (-Integer::from(10u32).pow(12))
        .add_mul(&Integer::from(0x10000), &-Integer::from(10u32).pow(12)),
    -65537000000000000i64
);
§

type Output = Integer

§

impl<'a> AddMul<Integer, &'a Integer> for Integer

§

fn add_mul(self, y: Integer, z: &'a Integer) -> Integer

Adds an Integer and the product of two other Integers, 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::integer::Integer;

assert_eq!(
    Integer::from(10u32).add_mul(Integer::from(3u32), &Integer::from(4u32)),
    22
);
assert_eq!(
    (-Integer::from(10u32).pow(12))
        .add_mul(Integer::from(0x10000), &-Integer::from(10u32).pow(12)),
    -65537000000000000i64
);
§

type Output = Integer

§

impl AddMul for Integer

§

fn add_mul(self, y: Integer, z: Integer) -> Integer

Adds an Integer and the product of two other Integers, 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::integer::Integer;

assert_eq!(
    Integer::from(10u32).add_mul(Integer::from(3u32), Integer::from(4u32)),
    22
);
assert_eq!(
    (-Integer::from(10u32).pow(12))
        .add_mul(Integer::from(0x10000), -Integer::from(10u32).pow(12)),
    -65537000000000000i64
);
§

type Output = Integer

§

impl<'a> AddMulAssign<&'a Integer> for Integer

§

fn add_mul_assign(&mut self, y: &'a Integer, z: Integer)

Adds the product of two other Integers to an Integer in place, taking the first Integer 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::integer::Integer;

let mut x = Integer::from(10u32);
x.add_mul_assign(&Integer::from(3u32), Integer::from(4u32));
assert_eq!(x, 22);

let mut x = -Integer::from(10u32).pow(12);
x.add_mul_assign(&Integer::from(0x10000), -Integer::from(10u32).pow(12));
assert_eq!(x, -65537000000000000i64);
§

impl<'a, 'b> AddMulAssign<&'a Integer, &'b Integer> for Integer

§

fn add_mul_assign(&mut self, y: &'a Integer, z: &'b Integer)

Adds the product of two other Integers to an Integer in place, taking both Integers 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::integer::Integer;

let mut x = Integer::from(10u32);
x.add_mul_assign(&Integer::from(3u32), &Integer::from(4u32));
assert_eq!(x, 22);

let mut x = -Integer::from(10u32).pow(12);
x.add_mul_assign(&Integer::from(0x10000), &-Integer::from(10u32).pow(12));
assert_eq!(x, -65537000000000000i64);
§

impl<'a> AddMulAssign<Integer, &'a Integer> for Integer

§

fn add_mul_assign(&mut self, y: Integer, z: &'a Integer)

Adds the product of two other Integers to an Integer in place, taking the first Integer 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::integer::Integer;

let mut x = Integer::from(10u32);
x.add_mul_assign(Integer::from(3u32), &Integer::from(4u32));
assert_eq!(x, 22);

let mut x = -Integer::from(10u32).pow(12);
x.add_mul_assign(Integer::from(0x10000), &-Integer::from(10u32).pow(12));
assert_eq!(x, -65537000000000000i64);
§

impl AddMulAssign for Integer

§

fn add_mul_assign(&mut self, y: Integer, z: Integer)

Adds the product of two other Integers to an Integer in place, taking both Integers 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::integer::Integer;

let mut x = Integer::from(10u32);
x.add_mul_assign(Integer::from(3u32), Integer::from(4u32));
assert_eq!(x, 22);

let mut x = -Integer::from(10u32).pow(12);
x.add_mul_assign(Integer::from(0x10000), -Integer::from(10u32).pow(12));
assert_eq!(x, -65537000000000000i64);
§

impl Binary for Integer

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Converts an Integer 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 core::str::FromStr;
use malachite_base::num::basic::traits::Zero;
use malachite_base::strings::ToBinaryString;
use malachite_nz::integer::Integer;

assert_eq!(Integer::ZERO.to_binary_string(), "0");
assert_eq!(Integer::from(123).to_binary_string(), "1111011");
assert_eq!(
    Integer::from_str("1000000000000")
        .unwrap()
        .to_binary_string(),
    "1110100011010100101001010001000000000000"
);
assert_eq!(format!("{:011b}", Integer::from(123)), "00001111011");
assert_eq!(Integer::from(-123).to_binary_string(), "-1111011");
assert_eq!(
    Integer::from_str("-1000000000000")
        .unwrap()
        .to_binary_string(),
    "-1110100011010100101001010001000000000000"
);
assert_eq!(format!("{:011b}", Integer::from(-123)), "-0001111011");

assert_eq!(format!("{:#b}", Integer::ZERO), "0b0");
assert_eq!(format!("{:#b}", Integer::from(123)), "0b1111011");
assert_eq!(
    format!("{:#b}", Integer::from_str("1000000000000").unwrap()),
    "0b1110100011010100101001010001000000000000"
);
assert_eq!(format!("{:#011b}", Integer::from(123)), "0b001111011");
assert_eq!(format!("{:#b}", Integer::from(-123)), "-0b1111011");
assert_eq!(
    format!("{:#b}", Integer::from_str("-1000000000000").unwrap()),
    "-0b1110100011010100101001010001000000000000"
);
assert_eq!(format!("{:#011b}", Integer::from(-123)), "-0b01111011");
§

impl<'a> BinomialCoefficient<&'a Integer> for Integer

§

fn binomial_coefficient(n: &'a Integer, k: &'a Integer) -> Integer

Computes the binomial coefficient of two Integers, taking both by reference.

The second argument must be non-negative, but the first may be negative. If it is, the identity $\binom{-n}{k} = (-1)^k \binom{n+k-1}{k}$ is used.

$$ f(n, k) = \begin{cases} \binom{n}{k} & \text{if} \quad n \geq 0, \\ (-1)^k \binom{-n+k-1}{k} & \text{if} \quad n < 0. \end{cases} $$

§Worst-case complexity

TODO

§Panics

Panics if $k$ is negative.

§Examples
use malachite_base::num::arithmetic::traits::BinomialCoefficient;
use malachite_nz::integer::Integer;

assert_eq!(
    Integer::binomial_coefficient(&Integer::from(4), &Integer::from(0)),
    1
);
assert_eq!(
    Integer::binomial_coefficient(&Integer::from(4), &Integer::from(1)),
    4
);
assert_eq!(
    Integer::binomial_coefficient(&Integer::from(4), &Integer::from(2)),
    6
);
assert_eq!(
    Integer::binomial_coefficient(&Integer::from(4), &Integer::from(3)),
    4
);
assert_eq!(
    Integer::binomial_coefficient(&Integer::from(4), &Integer::from(4)),
    1
);
assert_eq!(
    Integer::binomial_coefficient(&Integer::from(10), &Integer::from(5)),
    252
);
assert_eq!(
    Integer::binomial_coefficient(&Integer::from(100), &Integer::from(50)).to_string(),
    "100891344545564193334812497256"
);

assert_eq!(
    Integer::binomial_coefficient(&Integer::from(-3), &Integer::from(0)),
    1
);
assert_eq!(
    Integer::binomial_coefficient(&Integer::from(-3), &Integer::from(1)),
    -3
);
assert_eq!(
    Integer::binomial_coefficient(&Integer::from(-3), &Integer::from(2)),
    6
);
assert_eq!(
    Integer::binomial_coefficient(&Integer::from(-3), &Integer::from(3)),
    -10
);
§

impl BinomialCoefficient for Integer

§

fn binomial_coefficient(n: Integer, k: Integer) -> Integer

Computes the binomial coefficient of two Integers, taking both by value.

The second argument must be non-negative, but the first may be negative. If it is, the identity $\binom{-n}{k} = (-1)^k \binom{n+k-1}{k}$ is used.

$$ f(n, k) = \begin{cases} \binom{n}{k} & \text{if} \quad n \geq 0, \\ (-1)^k \binom{-n+k-1}{k} & \text{if} \quad n < 0. \end{cases} $$

§Worst-case complexity

TODO

§Panics

Panics if $k$ is negative.

§Examples
use malachite_base::num::arithmetic::traits::BinomialCoefficient;
use malachite_nz::integer::Integer;

assert_eq!(
    Integer::binomial_coefficient(Integer::from(4), Integer::from(0)),
    1
);
assert_eq!(
    Integer::binomial_coefficient(Integer::from(4), Integer::from(1)),
    4
);
assert_eq!(
    Integer::binomial_coefficient(Integer::from(4), Integer::from(2)),
    6
);
assert_eq!(
    Integer::binomial_coefficient(Integer::from(4), Integer::from(3)),
    4
);
assert_eq!(
    Integer::binomial_coefficient(Integer::from(4), Integer::from(4)),
    1
);
assert_eq!(
    Integer::binomial_coefficient(Integer::from(10), Integer::from(5)),
    252
);
assert_eq!(
    Integer::binomial_coefficient(Integer::from(100), Integer::from(50)).to_string(),
    "100891344545564193334812497256"
);

assert_eq!(
    Integer::binomial_coefficient(Integer::from(-3), Integer::from(0)),
    1
);
assert_eq!(
    Integer::binomial_coefficient(Integer::from(-3), Integer::from(1)),
    -3
);
assert_eq!(
    Integer::binomial_coefficient(Integer::from(-3), Integer::from(2)),
    6
);
assert_eq!(
    Integer::binomial_coefficient(Integer::from(-3), Integer::from(3)),
    -10
);
§

impl BitAccess for Integer

Provides functions for accessing and modifying the $i$th bit of a Integer, or the coefficient of $2^i$ in its two’s complement binary expansion.

§Examples

use malachite_base::num::basic::traits::{NegativeOne, Zero};
use malachite_base::num::logic::traits::BitAccess;
use malachite_nz::integer::Integer;

let mut x = Integer::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 = Integer::from(-0x100);
x.assign_bit(2, true);
x.assign_bit(5, true);
x.assign_bit(6, true);
assert_eq!(x, -156);
x.assign_bit(2, false);
x.assign_bit(5, false);
x.assign_bit(6, false);
assert_eq!(x, -256);

let mut x = Integer::ZERO;
x.flip_bit(10);
assert_eq!(x, 1024);
x.flip_bit(10);
assert_eq!(x, 0);

let mut x = Integer::NEGATIVE_ONE;
x.flip_bit(10);
assert_eq!(x, -1025);
x.flip_bit(10);
assert_eq!(x, -1);
§

fn get_bit(&self, index: u64) -> bool

Determines whether the $i$th bit of an Integer, or the coefficient of $2^i$ in its two’s complement binary expansion, is 0 or 1.

false means 0 and true means 1. Getting bits beyond the Integer’s width is allowed; those bits are false if the Integer is non-negative and true if it is negative.

If $n \geq 0$, let $$ n = \sum_{i=0}^\infty 2^{b_i}; $$ but if $n < 0$, let $$ -n - 1 = \sum_{i=0}^\infty 2^{1 - b_i}, $$ where for all $i$, $b_i\in \{0, 1\}$.

$f(n, i) = (b_i = 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::arithmetic::traits::Pow;
use malachite_base::num::logic::traits::BitAccess;
use malachite_nz::integer::Integer;

assert_eq!(Integer::from(123).get_bit(2), false);
assert_eq!(Integer::from(123).get_bit(3), true);
assert_eq!(Integer::from(123).get_bit(100), false);
assert_eq!(Integer::from(-123).get_bit(0), true);
assert_eq!(Integer::from(-123).get_bit(1), false);
assert_eq!(Integer::from(-123).get_bit(100), true);
assert_eq!(Integer::from(10u32).pow(12).get_bit(12), true);
assert_eq!(Integer::from(10u32).pow(12).get_bit(100), false);
assert_eq!((-Integer::from(10u32).pow(12)).get_bit(12), true);
assert_eq!((-Integer::from(10u32).pow(12)).get_bit(100), true);
§

fn set_bit(&mut self, index: u64)

Sets the $i$th bit of an Integer, or the coefficient of $2^i$ in its two’s complement binary expansion, to 1.

If $n \geq 0$, let $$ n = \sum_{i=0}^\infty 2^{b_i}; $$ but if $n < 0$, let $$ -n - 1 = \sum_{i=0}^\infty 2^{1 - b_i}, $$ where for all $i$, $b_i\in \{0, 1\}$. $$ 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::basic::traits::Zero;
use malachite_base::num::logic::traits::BitAccess;
use malachite_nz::integer::Integer;

let mut x = Integer::ZERO;
x.set_bit(2);
x.set_bit(5);
x.set_bit(6);
assert_eq!(x, 100);

let mut x = Integer::from(-0x100);
x.set_bit(2);
x.set_bit(5);
x.set_bit(6);
assert_eq!(x, -156);
§

fn clear_bit(&mut self, index: u64)

Sets the $i$th bit of an Integer, or the coefficient of $2^i$ in its binary expansion, to 0.

If $n \geq 0$, let $$ n = \sum_{i=0}^\infty 2^{b_i}; $$ but if $n < 0$, let $$ -n - 1 = \sum_{i=0}^\infty 2^{1 - b_i}, $$ where for all $i$, $b_i\in \{0, 1\}$. $$ 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(n)$

where $T$ is time, $M$ is additional memory, and $n$ is index.

§Examples
use malachite_base::num::logic::traits::BitAccess;
use malachite_nz::integer::Integer;

let mut x = Integer::from(0x7f);
x.clear_bit(0);
x.clear_bit(1);
x.clear_bit(3);
x.clear_bit(4);
assert_eq!(x, 100);

let mut x = Integer::from(-156);
x.clear_bit(2);
x.clear_bit(5);
x.clear_bit(6);
assert_eq!(x, -256);
§

fn assign_bit(&mut self, index: u64, bit: bool)

Sets the bit at index to whichever value bit is. Read more
§

fn flip_bit(&mut self, index: u64)

Sets the bit at index to the opposite of its original value. Read more
§

impl BitAnd<&Integer> for &Integer

§

fn bitand(self, other: &Integer) -> Integer

Takes the bitwise and of two Integers, 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 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::integer::Integer;

assert_eq!(&Integer::from(-123) & &Integer::from(-456), -512);
assert_eq!(
    &-Integer::from(10u32).pow(12) & &-(Integer::from(10u32).pow(12) + Integer::ONE),
    -1000000004096i64
);
§

type Output = Integer

The resulting type after applying the & operator.
§

impl BitAnd<&Integer> for Integer

§

fn bitand(self, other: &Integer) -> Integer

Takes the bitwise and of two Integers, taking the first by value and the second by reference.

$$ f(x, y) = x \wedge y. $$

§Worst-case complexity

$T(n) = O(n)$

$M(m) = O(m)$

where $T$ is time, $M$ is additional memory, $n$ is max(self.significant_bits(), other.significant_bits()), and $m$ is other.significant_bits().

§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_nz::integer::Integer;

assert_eq!(Integer::from(-123) & &Integer::from(-456), -512);
assert_eq!(
    -Integer::from(10u32).pow(12) & &-(Integer::from(10u32).pow(12) + Integer::ONE),
    -1000000004096i64
);
§

type Output = Integer

The resulting type after applying the & operator.
§

impl BitAnd<Integer> for &Integer

§

fn bitand(self, other: Integer) -> Integer

Takes the bitwise and of two Integers, taking the first by reference and the seocnd by value.

$$ f(x, y) = x \wedge y. $$

§Worst-case complexity

$T(n) = O(n)$

$M(m) = O(m)$

where $T$ is time, $M$ is additional memory, $n$ is max(self.significant_bits(), other.significant_bits()), and $m$ is self.significant_bits().

§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_nz::integer::Integer;

assert_eq!(&Integer::from(-123) & Integer::from(-456), -512);
assert_eq!(
    &-Integer::from(10u32).pow(12) & -(Integer::from(10u32).pow(12) + Integer::ONE),
    -1000000004096i64
);
§

type Output = Integer

The resulting type after applying the & operator.
§

impl BitAnd for Integer

§

fn bitand(self, other: Integer) -> Integer

Takes the bitwise and of two Integers, 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 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::integer::Integer;

assert_eq!(Integer::from(-123) & Integer::from(-456), -512);
assert_eq!(
    -Integer::from(10u32).pow(12) & -(Integer::from(10u32).pow(12) + Integer::ONE),
    -1000000004096i64
);
§

type Output = Integer

The resulting type after applying the & operator.
§

impl BitAndAssign<&Integer> for Integer

§

fn bitand_assign(&mut self, other: &Integer)

Bitwise-ands an Integer with another Integer in place, taking the Integer on the right-hand side by reference.

$$ x \gets x \wedge y. $$

§Worst-case complexity

$T(n) = O(n)$

$M(m) = O(m)$

where $T$ is time, $M$ is additional memory, $n$ is max(self.significant_bits(), other.significant_bits()), and $m$ is other.significant_bits().

§Examples
use malachite_base::num::basic::traits::NegativeOne;
use malachite_nz::integer::Integer;

let mut x = Integer::NEGATIVE_ONE;
x &= &Integer::from(0x70ffffff);
x &= &Integer::from(0x7ff0_ffff);
x &= &Integer::from(0x7ffff0ff);
x &= &Integer::from(0x7ffffff0);
assert_eq!(x, 0x70f0f0f0);
§

impl BitAndAssign for Integer

§

fn bitand_assign(&mut self, other: Integer)

Bitwise-ands an Integer with another Integer in place, taking the Integer 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 max(self.significant_bits(), other.significant_bits()).

§Examples
use malachite_base::num::basic::traits::NegativeOne;
use malachite_nz::integer::Integer;

let mut x = Integer::NEGATIVE_ONE;
x &= Integer::from(0x70ffffff);
x &= Integer::from(0x7ff0_ffff);
x &= Integer::from(0x7ffff0ff);
x &= Integer::from(0x7ffffff0);
assert_eq!(x, 0x70f0f0f0);
§

impl BitBlockAccess for Integer

§

fn get_bits(&self, start: u64, end: u64) -> Natural

Extracts a block of adjacent two’s complement bits from an Integer, taking the Integer 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.

If $n \geq 0$, let $$ n = \sum_{i=0}^\infty 2^{b_i}; $$ but if $n < 0$, let $$ -n - 1 = \sum_{i=0}^\infty 2^{1 - b_i}, $$ where for all $i$, $b_i\in \{0, 1\}$. 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 max(self.significant_bits(), end).

§Panics

Panics if start > end.

§Examples
use core::str::FromStr;
use malachite_base::num::basic::traits::Zero;
use malachite_base::num::logic::traits::BitBlockAccess;
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;

assert_eq!(
    (-Natural::from(0xabcdef0112345678u64)).get_bits(16, 48),
    Natural::from(0x10feedcbu32)
);
assert_eq!(
    Integer::from(0xabcdef0112345678u64).get_bits(4, 16),
    Natural::from(0x567u32)
);
assert_eq!(
    (-Natural::from(0xabcdef0112345678u64)).get_bits(0, 100),
    Natural::from_str("1267650600215849587758112418184").unwrap()
);
assert_eq!(
    Integer::from(0xabcdef0112345678u64).get_bits(10, 10),
    Natural::ZERO
);
§

fn get_bits_owned(self, start: u64, end: u64) -> Natural

Extracts a block of adjacent two’s complement bits from an Integer, taking the Integer 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.

If $n \geq 0$, let $$ n = \sum_{i=0}^\infty 2^{b_i}; $$ but if $n < 0$, let $$ -n - 1 = \sum_{i=0}^\infty 2^{1 - b_i}, $$ where for all $i$, $b_i\in \{0, 1\}$. 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 max(self.significant_bits(), end).

§Panics

Panics if start > end.

§Examples
use core::str::FromStr;
use malachite_base::num::basic::traits::Zero;
use malachite_base::num::logic::traits::BitBlockAccess;
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;

assert_eq!(
    (-Natural::from(0xabcdef0112345678u64)).get_bits_owned(16, 48),
    Natural::from(0x10feedcbu32)
);
assert_eq!(
    Integer::from(0xabcdef0112345678u64).get_bits_owned(4, 16),
    Natural::from(0x567u32)
);
assert_eq!(
    (-Natural::from(0xabcdef0112345678u64)).get_bits_owned(0, 100),
    Natural::from_str("1267650600215849587758112418184").unwrap()
);
assert_eq!(
    Integer::from(0xabcdef0112345678u64).get_bits_owned(10, 10),
    Natural::ZERO
);
§

fn assign_bits(&mut self, start: u64, end: u64, bits: &Natural)

Replaces a block of adjacent two’s complement bits in an Integer 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.

Let $$ m = \sum_{i=0}^k 2^{d_i}, $$ where for all $i$, $d_i\in \{0, 1\}$.

If $n \geq 0$, let $$ n = \sum_{i=0}^\infty 2^{b_i}; $$ but if $n < 0$, let $$ -n - 1 = \sum_{i=0}^\infty 2^{1 - b_i}, $$ where for all $i$, $b_i\in \{0, 1\}$. Then $$ n \gets \sum_{i=0}^\infty 2^{c_i}, $$ where $$ \{c_0, c_1, c_2, \ldots \} = \{b_0, b_1, b_2, \ldots, b_{p-1}, d_0, d_1, \ldots, d_{p-q-1}, b_q, b_{q+1}, \ldots \}. $$

§Worst-case complexity

$T(n) = O(n)$

$M(m) = O(m)$

where $T$ is time, $M$ is additional memory, $n$ is max(self.significant_bits(), end), and $m$ is self.significant_bits().

§Panics

Panics if start > end.

§Examples
use malachite_base::num::logic::traits::BitBlockAccess;
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;

let mut n = Integer::from(123);
n.assign_bits(5, 7, &Natural::from(456u32));
assert_eq!(n.to_string(), "27");

let mut n = Integer::from(-123);
n.assign_bits(64, 128, &Natural::from(456u32));
assert_eq!(n.to_string(), "-340282366920938455033212565746503123067");

let mut n = Integer::from(-123);
n.assign_bits(80, 100, &Natural::from(456u32));
assert_eq!(n.to_string(), "-1267098121128665515963862483067");
§

type Bits = Natural

§

impl BitConvertible for Integer

§

fn to_bits_asc(&self) -> Vec<bool>

Returns a Vec containing the twos-complement bits of an Integer in ascending order: least- to most-significant.

The most significant bit indicates the sign; if the bit is false, the Integer is positive, and if the bit is true it is negative. There are no trailing false bits if the Integer is positive or trailing true bits if the Integer is negative, except as necessary to include the correct sign bit. Zero is a special case: it contains no bits.

This function is more efficient than to_bits_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::basic::traits::Zero;
use malachite_base::num::logic::traits::BitConvertible;
use malachite_nz::integer::Integer;

assert!(Integer::ZERO.to_bits_asc().is_empty());
// 105 = 01101001b, with a leading false bit to indicate sign
assert_eq!(
    Integer::from(105).to_bits_asc(),
    &[true, false, false, true, false, true, true, false]
);
// -105 = 10010111 in two's complement, with a leading true bit to indicate sign
assert_eq!(
    Integer::from(-105).to_bits_asc(),
    &[true, true, true, false, true, false, false, true]
);
§

fn to_bits_desc(&self) -> Vec<bool>

Returns a Vec containing the twos-complement bits of an Integer in descending order: most- to least-significant.

The most significant bit indicates the sign; if the bit is false, the Integer is positive, and if the bit is true it is negative. There are no leading false bits if the Integer is positive or leading true bits if the Integer is negative, except as necessary to include the correct sign bit. Zero is a special case: it contains no bits.

This is similar to how BigIntegers in Java are represented.

This function is less efficient than to_bits_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::basic::traits::Zero;
use malachite_base::num::logic::traits::BitConvertible;
use malachite_nz::integer::Integer;

assert!(Integer::ZERO.to_bits_desc().is_empty());
// 105 = 01101001b, with a leading false bit to indicate sign
assert_eq!(
    Integer::from(105).to_bits_desc(),
    &[false, true, true, false, true, false, false, true]
);
// -105 = 10010111 in two's complement, with a leading true bit to indicate sign
assert_eq!(
    Integer::from(-105).to_bits_desc(),
    &[true, false, false, true, false, true, true, true]
);
§

fn from_bits_asc<I>(xs: I) -> Integer
where I: Iterator<Item = bool>,

Converts an iterator of twos-complement bits into an Integer. The bits should be in ascending order (least- to most-significant).

Let $k$ be bits.count(). If $k = 0$ or $b_{k-1}$ is false, then $$ 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.

If $b_{k-1}$ is true, then $$ f((b_i)_ {i=0}^{k-1}) = \left ( \sum_{i=0}^{k-1}2^i [b_i] \right ) - 2^k. $$

§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 core::iter::empty;
use malachite_base::num::logic::traits::BitConvertible;
use malachite_nz::integer::Integer;

assert_eq!(Integer::from_bits_asc(empty()), 0);
// 105 = 1101001b
assert_eq!(
    Integer::from_bits_asc(
        [true, false, false, true, false, true, true, false]
            .iter()
            .cloned()
    ),
    105
);
// -105 = 10010111 in two's complement, with a leading true bit to indicate sign
assert_eq!(
    Integer::from_bits_asc(
        [true, true, true, false, true, false, false, true]
            .iter()
            .cloned()
    ),
    -105
);
§

fn from_bits_desc<I>(xs: I) -> Integer
where I: Iterator<Item = bool>,

Converts an iterator of twos-complement bits into an Integer. The bits should be in descending order (most- to least-significant).

If bits is empty or $b_0$ is false, then $$ 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.

If $b_0$ is true, then $$ f((b_i)_ {i=0}^{k-1}) = \left ( \sum_{i=0}^{k-1}2^{k-i-1} [b_i] \right ) - 2^k. $$

§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 core::iter::empty;
use malachite_base::num::logic::traits::BitConvertible;
use malachite_nz::integer::Integer;

assert_eq!(Integer::from_bits_desc(empty()), 0);
// 105 = 1101001b
assert_eq!(
    Integer::from_bits_desc(
        [false, true, true, false, true, false, false, true]
            .iter()
            .cloned()
    ),
    105
);
// -105 = 10010111 in two's complement, with a leading true bit to indicate sign
assert_eq!(
    Integer::from_bits_desc(
        [true, false, false, true, false, true, true, true]
            .iter()
            .cloned()
    ),
    -105
);
§

impl<'a> BitIterable for &'a Integer

§

fn bits(self) -> IntegerBitIterator<'a>

Returns a double-ended iterator over the bits of an Integer.

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, except for possibly a most-significant sign-extension bit.

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 itertools::Itertools;
use malachite_base::num::basic::traits::Zero;
use malachite_base::num::logic::traits::BitIterable;
use malachite_nz::integer::Integer;

assert_eq!(Integer::ZERO.bits().next(), None);
// 105 = 01101001b, with a leading false bit to indicate sign
assert_eq!(
    Integer::from(105).bits().collect_vec(),
    &[true, false, false, true, false, true, true, false]
);
// -105 = 10010111 in two's complement, with a leading true bit to indicate sign
assert_eq!(
    Integer::from(-105).bits().collect_vec(),
    &[true, true, true, false, true, false, false, true]
);

assert_eq!(Integer::ZERO.bits().next_back(), None);
// 105 = 01101001b, with a leading false bit to indicate sign
assert_eq!(
    Integer::from(105).bits().rev().collect_vec(),
    &[false, true, true, false, true, false, false, true]
);
// -105 = 10010111 in two's complement, with a leading true bit to indicate sign
assert_eq!(
    Integer::from(-105).bits().rev().collect_vec(),
    &[true, false, false, true, false, true, true, true]
);
§

type BitIterator = IntegerBitIterator<'a>

§

impl BitOr<&Integer> for &Integer

§

fn bitor(self, other: &Integer) -> Integer

Takes the bitwise or of two Integers, 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::integer::Integer;

assert_eq!(&Integer::from(-123) | &Integer::from(-456), -67);
assert_eq!(
    &-Integer::from(10u32).pow(12) | &-(Integer::from(10u32).pow(12) + Integer::ONE),
    -999999995905i64
);
§

type Output = Integer

The resulting type after applying the | operator.
§

impl<'a> BitOr<&'a Integer> for Integer

§

fn bitor(self, other: &'a Integer) -> Integer

Takes the bitwise or of two Integers, taking the first by value and the second by reference.

$$ f(x, y) = x \vee y. $$

§Worst-case complexity

$T(n) = O(n)$

$M(m) = O(m)$

where $T$ is time, $M$ is additional memory, $n$ is max(self.significant_bits(), other.significant_bits()), and $m$ is other.significant_bits().

§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_nz::integer::Integer;

assert_eq!(Integer::from(-123) | &Integer::from(-456), -67);
assert_eq!(
    -Integer::from(10u32).pow(12) | &-(Integer::from(10u32).pow(12) + Integer::ONE),
    -999999995905i64
);
§

type Output = Integer

The resulting type after applying the | operator.
§

impl BitOr<Integer> for &Integer

§

fn bitor(self, other: Integer) -> Integer

Takes the bitwise or of two Integers, taking the first by reference and the second by value.

$$ f(x, y) = x \vee y. $$

§Worst-case complexity

$T(n) = O(n)$

$M(m) = O(m)$

where $T$ is time, $M$ is additional memory, $n$ is max(self.significant_bits(), other.significant_bits()), and $m$ is self.significant_bits().

§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_nz::integer::Integer;

assert_eq!(&Integer::from(-123) | Integer::from(-456), -67);
assert_eq!(
    &-Integer::from(10u32).pow(12) | -(Integer::from(10u32).pow(12) + Integer::ONE),
    -999999995905i64
);
§

type Output = Integer

The resulting type after applying the | operator.
§

impl BitOr for Integer

§

fn bitor(self, other: Integer) -> Integer

Takes the bitwise or of two Integers, taking both by value.

$$ f(x, y) = x \vee y. $$

§Worst-case complexity

$T(n) = O(n)$

$M(m) = O(m)$

where $T$ is time, $M$ is additional memory, $n$ is max(self.significant_bits(), other.significant_bits()), and $m$ 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::integer::Integer;

assert_eq!(Integer::from(-123) | Integer::from(-456), -67);
assert_eq!(
    -Integer::from(10u32).pow(12) | -(Integer::from(10u32).pow(12) + Integer::ONE),
    -999999995905i64
);
§

type Output = Integer

The resulting type after applying the | operator.
§

impl<'a> BitOrAssign<&'a Integer> for Integer

§

fn bitor_assign(&mut self, other: &'a Integer)

Bitwise-ors an Integer with another Integer in place, taking the Integer on the right-hand side by reference.

§Worst-case complexity

$T(n) = O(n)$

$M(m) = O(m)$

where $T$ is time, $M$ is additional memory, $n$ is max(self.significant_bits(), other.significant_bits()), and $m$ is other.significant_bits().

§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_nz::integer::Integer;

let mut x = Integer::ZERO;
x |= &Integer::from(0x0000000f);
x |= &Integer::from(0x00000f00);
x |= &Integer::from(0x000f_0000);
x |= &Integer::from(0x0f000000);
assert_eq!(x, 0x0f0f_0f0f);
§

impl BitOrAssign for Integer

§

fn bitor_assign(&mut self, other: Integer)

Bitwise-ors an Integer with another Integer in place, taking the Integer on the right-hand side by value.

§Worst-case complexity

$T(n) = O(n)$

$M(m) = O(m)$

where $T$ is time, $M$ is additional memory, $n$ is max(self.significant_bits(), other.significant_bits()), and $m$ is min(self.significant_bits(), other.significant_bits()).

§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_nz::integer::Integer;

let mut x = Integer::ZERO;
x |= Integer::from(0x0000000f);
x |= Integer::from(0x00000f00);
x |= Integer::from(0x000f_0000);
x |= Integer::from(0x0f000000);
assert_eq!(x, 0x0f0f_0f0f);
§

impl BitScan for &Integer

§

fn index_of_next_false_bit(self, starting_index: u64) -> Option<u64>

Given an Integer and a starting index, searches the Integer for the smallest index of a false bit that is greater than or equal to the starting index.

If the [Integer] is negative, and the starting index is too large and there are no more false bits above it, None is returned.

§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::integer::Integer;

assert_eq!(
    (-Integer::from(0x500000000u64)).index_of_next_false_bit(0),
    Some(0)
);
assert_eq!(
    (-Integer::from(0x500000000u64)).index_of_next_false_bit(20),
    Some(20)
);
assert_eq!(
    (-Integer::from(0x500000000u64)).index_of_next_false_bit(31),
    Some(31)
);
assert_eq!(
    (-Integer::from(0x500000000u64)).index_of_next_false_bit(32),
    Some(34)
);
assert_eq!(
    (-Integer::from(0x500000000u64)).index_of_next_false_bit(33),
    Some(34)
);
assert_eq!(
    (-Integer::from(0x500000000u64)).index_of_next_false_bit(34),
    Some(34)
);
assert_eq!(
    (-Integer::from(0x500000000u64)).index_of_next_false_bit(35),
    None
);
assert_eq!(
    (-Integer::from(0x500000000u64)).index_of_next_false_bit(100),
    None
);
§

fn index_of_next_true_bit(self, starting_index: u64) -> Option<u64>

Given an Integer and a starting index, searches the Integer for the smallest index of a true bit that is greater than or equal to the starting index.

If the Integer is non-negative, and the starting index is too large and there are no more true bits above it, None is returned.

§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::integer::Integer;

assert_eq!(
    (-Integer::from(0x500000000u64)).index_of_next_true_bit(0),
    Some(32)
);
assert_eq!(
    (-Integer::from(0x500000000u64)).index_of_next_true_bit(20),
    Some(32)
);
assert_eq!(
    (-Integer::from(0x500000000u64)).index_of_next_true_bit(31),
    Some(32)
);
assert_eq!(
    (-Integer::from(0x500000000u64)).index_of_next_true_bit(32),
    Some(32)
);
assert_eq!(
    (-Integer::from(0x500000000u64)).index_of_next_true_bit(33),
    Some(33)
);
assert_eq!(
    (-Integer::from(0x500000000u64)).index_of_next_true_bit(34),
    Some(35)
);
assert_eq!(
    (-Integer::from(0x500000000u64)).index_of_next_true_bit(35),
    Some(35)
);
assert_eq!(
    (-Integer::from(0x500000000u64)).index_of_next_true_bit(36),
    Some(36)
);
assert_eq!(
    (-Integer::from(0x500000000u64)).index_of_next_true_bit(100),
    Some(100)
);
§

impl BitXor<&Integer> for &Integer

§

fn bitxor(self, other: &Integer) -> Integer

Takes the bitwise xor of two Integers, taking both by reference.

$$ f(x, y) = x \oplus y. $$

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::integer::Integer;

assert_eq!(&Integer::from(-123) ^ &Integer::from(-456), 445);
assert_eq!(
    &-Integer::from(10u32).pow(12) ^ &-(Integer::from(10u32).pow(12) + Integer::ONE),
    8191
);
§

type Output = Integer

The resulting type after applying the ^ operator.
§

impl BitXor<&Integer> for Integer

§

fn bitxor(self, other: &Integer) -> Integer

Takes the bitwise xor of two Integers, taking the first by value and the second by reference.

$$ f(x, y) = x \oplus y. $$

§Worst-case complexity

$T(n) = O(n)$

$M(m) = O(m)$

where $T$ is time, $M$ is additional memory, $n$ is max(self.significant_bits(), other.significant_bits()), and $m$ is other.significant_bits().

§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_nz::integer::Integer;

assert_eq!(Integer::from(-123) ^ &Integer::from(-456), 445);
assert_eq!(
    -Integer::from(10u32).pow(12) ^ &-(Integer::from(10u32).pow(12) + Integer::ONE),
    8191
);
§

type Output = Integer

The resulting type after applying the ^ operator.
§

impl BitXor<Integer> for &Integer

§

fn bitxor(self, other: Integer) -> Integer

Takes the bitwise xor of two Integers, taking the first by reference and the second by value.

$$ f(x, y) = x \oplus y. $$

§Worst-case complexity

$T(n) = O(n)$

$M(m) = O(m)$

where $T$ is time, $M$ is additional memory, $n$ is max(self.significant_bits(), other.significant_bits()), and $m$ is self.significant_bits().

§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::One;
use malachite_nz::integer::Integer;

assert_eq!(&Integer::from(-123) ^ Integer::from(-456), 445);
assert_eq!(
    &-Integer::from(10u32).pow(12) ^ -(Integer::from(10u32).pow(12) + Integer::ONE),
    8191
);
§

type Output = Integer

The resulting type after applying the ^ operator.
§

impl BitXor for Integer

§

fn bitxor(self, other: Integer) -> Integer

Takes the bitwise xor of two Integers, 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 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::integer::Integer;

assert_eq!(Integer::from(-123) ^ Integer::from(-456), 445);
assert_eq!(
    -Integer::from(10u32).pow(12) ^ -(Integer::from(10u32).pow(12) + Integer::ONE),
    8191
);
§

type Output = Integer

The resulting type after applying the ^ operator.
§

impl BitXorAssign<&Integer> for Integer

§

fn bitxor_assign(&mut self, other: &Integer)

Bitwise-xors an Integer with another Integer in place, taking the Integer on the right-hand side by reference.

$$ x \gets x \oplus y. $$

§Worst-case complexity

$T(n) = O(n)$

$M(m) = O(m)$

where $T$ is time, $M$ is additional memory, $n$ is max(self.significant_bits(), other.significant_bits()), and $m$ is other.significant_bits().

§Examples
use malachite_nz::integer::Integer;

let mut x = Integer::from(u32::MAX);
x ^= &Integer::from(0x0000000f);
x ^= &Integer::from(0x00000f00);
x ^= &Integer::from(0x000f_0000);
x ^= &Integer::from(0x0f000000);
assert_eq!(x, 0xf0f0_f0f0u32);
§

impl BitXorAssign for Integer

§

fn bitxor_assign(&mut self, other: Integer)

Bitwise-xors an Integer with another Integer in place, taking the Integer 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 max(self.significant_bits(), other.significant_bits()).

§Examples
use malachite_nz::integer::Integer;

let mut x = Integer::from(u32::MAX);
x ^= Integer::from(0x0000000f);
x ^= Integer::from(0x00000f00);
x ^= Integer::from(0x000f_0000);
x ^= Integer::from(0x0f000000);
assert_eq!(x, 0xf0f0_f0f0u32);
§

impl CeilingDivAssignMod<&Integer> for Integer

§

fn ceiling_div_assign_mod(&mut self, other: &Integer) -> Integer

Divides an Integer by another Integer in place, taking the Integer on the right-hand side by reference and returning the remainder. The quotient is rounded towards positive infinity and the remainder has the opposite sign as the second Integer.

The quotient and remainder satisfy $x = qy + r$ and $0 \leq |r| < |y|$.

$$ f(x, y) = x - y\left \lceil\frac{x}{y} \right \rceil, $$ $$ 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::CeilingDivAssignMod;
use malachite_nz::integer::Integer;

// 3 * 10 + -7 = 23
let mut x = Integer::from(23);
assert_eq!(x.ceiling_div_assign_mod(&Integer::from(10)), -7);
assert_eq!(x, 3);

// -2 * -10 + 3 = 23
let mut x = Integer::from(23);
assert_eq!(x.ceiling_div_assign_mod(&Integer::from(-10)), 3);
assert_eq!(x, -2);

// -2 * 10 + -3 = -23
let mut x = Integer::from(-23);
assert_eq!(x.ceiling_div_assign_mod(&Integer::from(10)), -3);
assert_eq!(x, -2);

// 3 * -10 + 7 = -23
let mut x = Integer::from(-23);
assert_eq!(x.ceiling_div_assign_mod(&Integer::from(-10)), 7);
assert_eq!(x, 3);
§

type ModOutput = Integer

§

impl CeilingDivAssignMod for Integer

§

fn ceiling_div_assign_mod(&mut self, other: Integer) -> Integer

Divides an Integer by another Integer in place, taking the Integer on the right-hand side by value and returning the remainder. The quotient is rounded towards positive infinity and the remainder has the opposite sign as the second Integer.

The quotient and remainder satisfy $x = qy + r$ and $0 \leq |r| < |y|$.

$$ f(x, y) = x - y\left \lceil\frac{x}{y} \right \rceil, $$ $$ 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::CeilingDivAssignMod;
use malachite_nz::integer::Integer;

// 3 * 10 + -7 = 23
let mut x = Integer::from(23);
assert_eq!(x.ceiling_div_assign_mod(Integer::from(10)), -7);
assert_eq!(x, 3);

// -2 * -10 + 3 = 23
let mut x = Integer::from(23);
assert_eq!(x.ceiling_div_assign_mod(Integer::from(-10)), 3);
assert_eq!(x, -2);

// -2 * 10 + -3 = -23
let mut x = Integer::from(-23);
assert_eq!(x.ceiling_div_assign_mod(Integer::from(10)), -3);
assert_eq!(x, -2);

// 3 * -10 + 7 = -23
let mut x = Integer::from(-23);
assert_eq!(x.ceiling_div_assign_mod(Integer::from(-10)), 7);
assert_eq!(x, 3);
§

type ModOutput = Integer

§

impl CeilingDivMod<&Integer> for &Integer

§

fn ceiling_div_mod(self, other: &Integer) -> (Integer, Integer)

Divides an Integer by another Integer, taking both by reference and returning the quotient and remainder. The quotient is rounded towards positive infinity and the remainder has the opposite sign as the second Integer.

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 x - y\left \lceil \frac{x}{y} \right \rceil \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::CeilingDivMod;
use malachite_base::strings::ToDebugString;
use malachite_nz::integer::Integer;

// 3 * 10 + -7 = 23
assert_eq!(
    (&Integer::from(23))
        .ceiling_div_mod(&Integer::from(10))
        .to_debug_string(),
    "(3, -7)"
);

// -2 * -10 + 3 = 23
assert_eq!(
    (&Integer::from(23))
        .ceiling_div_mod(&Integer::from(-10))
        .to_debug_string(),
    "(-2, 3)"
);

// -2 * 10 + -3 = -23
assert_eq!(
    (&Integer::from(-23))
        .ceiling_div_mod(&Integer::from(10))
        .to_debug_string(),
    "(-2, -3)"
);

// 3 * -10 + 7 = -23
assert_eq!(
    (&Integer::from(-23))
        .ceiling_div_mod(&Integer::from(-10))
        .to_debug_string(),
    "(3, 7)"
);
§

type DivOutput = Integer

§

type ModOutput = Integer

§

impl CeilingDivMod<&Integer> for Integer

§

fn ceiling_div_mod(self, other: &Integer) -> (Integer, Integer)

Divides an Integer by another Integer, taking both the first by value and the second by reference and returning the quotient and remainder. The quotient is rounded towards positive infinity and the remainder has the opposite sign as the second Integer.

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 x - y\left \lceil \frac{x}{y} \right \rceil \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::CeilingDivMod;
use malachite_base::strings::ToDebugString;
use malachite_nz::integer::Integer;

// 3 * 10 + -7 = 23
assert_eq!(
    Integer::from(23)
        .ceiling_div_mod(&Integer::from(10))
        .to_debug_string(),
    "(3, -7)"
);

// -2 * -10 + 3 = 23
assert_eq!(
    Integer::from(23)
        .ceiling_div_mod(&Integer::from(-10))
        .to_debug_string(),
    "(-2, 3)"
);

// -2 * 10 + -3 = -23
assert_eq!(
    Integer::from(-23)
        .ceiling_div_mod(&Integer::from(10))
        .to_debug_string(),
    "(-2, -3)"
);

// 3 * -10 + 7 = -23
assert_eq!(
    Integer::from(-23)
        .ceiling_div_mod(&Integer::from(-10))
        .to_debug_string(),
    "(3, 7)"
);
§

type DivOutput = Integer

§

type ModOutput = Integer

§

impl CeilingDivMod<Integer> for &Integer

§

fn ceiling_div_mod(self, other: Integer) -> (Integer, Integer)

Divides an Integer by another Integer, taking the first by reference and the second by value and returning the quotient and remainder. The quotient is rounded towards positive infinity and the remainder has the opposite sign as the second Integer.

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 x - y\left \lceil \frac{x}{y} \right \rceil \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::CeilingDivMod;
use malachite_base::strings::ToDebugString;
use malachite_nz::integer::Integer;

// 3 * 10 + -7 = 23
assert_eq!(
    (&Integer::from(23))
        .ceiling_div_mod(Integer::from(10))
        .to_debug_string(),
    "(3, -7)"
);

// -2 * -10 + 3 = 23
assert_eq!(
    (&Integer::from(23))
        .ceiling_div_mod(Integer::from(-10))
        .to_debug_string(),
    "(-2, 3)"
);

// -2 * 10 + -3 = -23
assert_eq!(
    (&Integer::from(-23))
        .ceiling_div_mod(Integer::from(10))
        .to_debug_string(),
    "(-2, -3)"
);

// 3 * -10 + 7 = -23
assert_eq!(
    (&Integer::from(-23))
        .ceiling_div_mod(Integer::from(-10))
        .to_debug_string(),
    "(3, 7)"
);
§

type DivOutput = Integer

§

type ModOutput = Integer

§

impl CeilingDivMod for Integer

§

fn ceiling_div_mod(self, other: Integer) -> (Integer, Integer)

Divides an Integer by another Integer, taking both by value and returning the quotient and remainder. The quotient is rounded towards positive infinity and the remainder has the opposite sign as the second Integer.

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 x - y\left \lceil \frac{x}{y} \right \rceil \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::CeilingDivMod;
use malachite_base::strings::ToDebugString;
use malachite_nz::integer::Integer;

// 3 * 10 + -7 = 23
assert_eq!(
    Integer::from(23)
        .ceiling_div_mod(Integer::from(10))
        .to_debug_string(),
    "(3, -7)"
);

// -2 * -10 + 3 = 23
assert_eq!(
    Integer::from(23)
        .ceiling_div_mod(Integer::from(-10))
        .to_debug_string(),
    "(-2, 3)"
);

// -2 * 10 + -3 = -23
assert_eq!(
    Integer::from(-23)
        .ceiling_div_mod(Integer::from(10))
        .to_debug_string(),
    "(-2, -3)"
);

// 3 * -10 + 7 = -23
assert_eq!(
    Integer::from(-23)
        .ceiling_div_mod(Integer::from(-10))
        .to_debug_string(),
    "(3, 7)"
);
§

type DivOutput = Integer

§

type ModOutput = Integer

§

impl CeilingMod<&Integer> for &Integer

§

fn ceiling_mod(self, other: &Integer) -> Integer

Divides an Integer by another Integer, taking both by reference and returning just the remainder. The remainder has the opposite sign as the second Integer.

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 \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::CeilingMod;
use malachite_nz::integer::Integer;

// 2 * 10 + 3 = 23
assert_eq!((&Integer::from(23)).ceiling_mod(&Integer::from(10)), -7);

// -3 * -10 + -7 = 23
assert_eq!((&Integer::from(23)).ceiling_mod(&Integer::from(-10)), 3);

// -3 * 10 + 7 = -23
assert_eq!((&Integer::from(-23)).ceiling_mod(&Integer::from(10)), -3);

// 2 * -10 + -3 = -23
assert_eq!((&Integer::from(-23)).ceiling_mod(&Integer::from(-10)), 7);
§

type Output = Integer

§

impl CeilingMod<&Integer> for Integer

§

fn ceiling_mod(self, other: &Integer) -> Integer

Divides an Integer by another Integer, taking the first by value and the second by reference and returning just the remainder. The remainder has the opposite sign as the second Integer.

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 \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::CeilingMod;
use malachite_nz::integer::Integer;

// 2 * 10 + 3 = 23
assert_eq!(Integer::from(23).ceiling_mod(&Integer::from(10)), -7);

// -3 * -10 + -7 = 23
assert_eq!(Integer::from(23).ceiling_mod(&Integer::from(-10)), 3);

// -3 * 10 + 7 = -23
assert_eq!(Integer::from(-23).ceiling_mod(&Integer::from(10)), -3);

// 2 * -10 + -3 = -23
assert_eq!(Integer::from(-23).ceiling_mod(&Integer::from(-10)), 7);
§

type Output = Integer

§

impl CeilingMod<Integer> for &Integer

§

fn ceiling_mod(self, other: Integer) -> Integer

Divides an Integer by another Integer, taking the first by reference and the second by value and returning just the remainder. The remainder has the opposite sign as the second Integer.

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 \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::CeilingMod;
use malachite_nz::integer::Integer;

// 2 * 10 + 3 = 23
assert_eq!((&Integer::from(23)).ceiling_mod(Integer::from(10)), -7);

// -3 * -10 + -7 = 23
assert_eq!((&Integer::from(23)).ceiling_mod(Integer::from(-10)), 3);

// -3 * 10 + 7 = -23
assert_eq!((&Integer::from(-23)).ceiling_mod(Integer::from(10)), -3);

// 2 * -10 + -3 = -23
assert_eq!((&Integer::from(-23)).ceiling_mod(Integer::from(-10)), 7);
§

type Output = Integer

§

impl CeilingMod for Integer

§

fn ceiling_mod(self, other: Integer) -> Integer

Divides an Integer by another Integer, taking both by value and returning just the remainder. The remainder has the opposite sign as the second Integer.

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 \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::CeilingMod;
use malachite_nz::integer::Integer;

// 2 * 10 + 3 = 23
assert_eq!(Integer::from(23).ceiling_mod(Integer::from(10)), -7);

// -3 * -10 + -7 = 23
assert_eq!(Integer::from(23).ceiling_mod(Integer::from(-10)), 3);

// -3 * 10 + 7 = -23
assert_eq!(Integer::from(-23).ceiling_mod(Integer::from(10)), -3);

// 2 * -10 + -3 = -23
assert_eq!(Integer::from(-23).ceiling_mod(Integer::from(-10)), 7);
§

type Output = Integer

§

impl CeilingModAssign<&Integer> for Integer

§

fn ceiling_mod_assign(&mut self, other: &Integer)

Divides an Integer by another Integer, taking the Integer on the right-hand side by reference and replacing the first number by the remainder. The remainder has the opposite sign as the second number.

If the quotient were computed, the quotient and remainder would satisfy $x = qy + r$ and $0 \leq |r| < |y|$.

$$ x \gets x - y\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::CeilingModAssign;
use malachite_nz::integer::Integer;

// 2 * 10 + 3 = 23
let mut x = Integer::from(23);
x.ceiling_mod_assign(&Integer::from(10));
assert_eq!(x, -7);

// -3 * -10 + -7 = 23
let mut x = Integer::from(23);
x.ceiling_mod_assign(&Integer::from(-10));
assert_eq!(x, 3);

// -3 * 10 + 7 = -23
let mut x = Integer::from(-23);
x.ceiling_mod_assign(&Integer::from(10));
assert_eq!(x, -3);

// 2 * -10 + -3 = -23
let mut x = Integer::from(-23);
x.ceiling_mod_assign(&Integer::from(-10));
assert_eq!(x, 7);
§

impl CeilingModAssign for Integer

§

fn ceiling_mod_assign(&mut self, other: Integer)

Divides an Integer by another Integer, taking the Integer on the right-hand side by value and replacing the first number by the remainder. The remainder has the opposite sign as the second number.

If the quotient were computed, the quotient and remainder would satisfy $x = qy + r$ and $0 \leq |r| < |y|$.

$$ x \gets x - y\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::CeilingModAssign;
use malachite_nz::integer::Integer;

// 2 * 10 + 3 = 23
let mut x = Integer::from(23);
x.ceiling_mod_assign(Integer::from(10));
assert_eq!(x, -7);

// -3 * -10 + -7 = 23
let mut x = Integer::from(23);
x.ceiling_mod_assign(Integer::from(-10));
assert_eq!(x, 3);

// -3 * 10 + 7 = -23
let mut x = Integer::from(-23);
x.ceiling_mod_assign(Integer::from(10));
assert_eq!(x, -3);

// 2 * -10 + -3 = -23
let mut x = Integer::from(-23);
x.ceiling_mod_assign(Integer::from(-10));
assert_eq!(x, 7);
§

impl CeilingModPowerOf2 for &Integer

§

fn ceiling_mod_power_of_2(self, pow: u64) -> Integer

Divides an Integer by $2^k$, taking it by reference and returning just the remainder. The remainder is non-positive.

If the quotient were computed, the quotient and remainder would satisfy $x = q2^k + r$ and $0 \leq -r < 2^k$.

$$ f(x, y) = x - 2^k\left \lceil \frac{x}{2^k} \right \rceil. $$

§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::CeilingModPowerOf2;
use malachite_nz::integer::Integer;

// 2 * 2^8 + -252 = 260
assert_eq!((&Integer::from(260)).ceiling_mod_power_of_2(8), -252);
// -100 * 2^4 + -11 = -1611
assert_eq!((&Integer::from(-1611)).ceiling_mod_power_of_2(4), -11);
§

type Output = Integer

§

impl CeilingModPowerOf2 for Integer

§

fn ceiling_mod_power_of_2(self, pow: u64) -> Integer

Divides an Integer by $2^k$, taking it by value and returning just the remainder. The remainder is non-positive.

If the quotient were computed, the quotient and remainder would satisfy $x = q2^k + r$ and $0 \leq -r < 2^k$.

$$ f(x, y) = x - 2^k\left \lceil \frac{x}{2^k} \right \rceil. $$

§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::CeilingModPowerOf2;
use malachite_nz::integer::Integer;

// 2 * 2^8 + -252 = 260
assert_eq!(Integer::from(260).ceiling_mod_power_of_2(8), -252);

// -100 * 2^4 + -11 = -1611
assert_eq!(Integer::from(-1611).ceiling_mod_power_of_2(4), -11);
§

type Output = Integer

§

impl CeilingModPowerOf2Assign for Integer

§

fn ceiling_mod_power_of_2_assign(&mut self, pow: u64)

Divides an Integer by $2^k$, replacing the Integer by the remainder. The remainder is non-positive.

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 \lceil\frac{x}{2^k} \right \rceil. $$

§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::CeilingModPowerOf2Assign;
use malachite_nz::integer::Integer;

// 2 * 2^8 + -252 = 260
let mut x = Integer::from(260);
x.ceiling_mod_power_of_2_assign(8);
assert_eq!(x, -252);

// -100 * 2^4 + -11 = -1611
let mut x = Integer::from(-1611);
x.ceiling_mod_power_of_2_assign(4);
assert_eq!(x, -11);
§

impl CeilingRoot<u64> for &Integer

§

fn ceiling_root(self, exp: u64) -> Integer

Returns the ceiling of the $n$th root of an Integer, taking the Integer 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, or if exp is even and self is negative.

§Examples
use malachite_base::num::arithmetic::traits::CeilingRoot;
use malachite_nz::integer::Integer;

assert_eq!(Integer::from(999).ceiling_root(3), 10);
assert_eq!(Integer::from(1000).ceiling_root(3), 10);
assert_eq!(Integer::from(1001).ceiling_root(3), 11);
assert_eq!(Integer::from(100000000000i64).ceiling_root(5), 159);
assert_eq!(Integer::from(-100000000000i64).ceiling_root(5), -158);
§

type Output = Integer

§

impl CeilingRoot<u64> for Integer

§

fn ceiling_root(self, exp: u64) -> Integer

Returns the ceiling of the $n$th root of an Integer, taking the Integer 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, or if exp is even and self is negative.

§Examples
use malachite_base::num::arithmetic::traits::CeilingRoot;
use malachite_nz::integer::Integer;

assert_eq!(Integer::from(999).ceiling_root(3), 10);
assert_eq!(Integer::from(1000).ceiling_root(3), 10);
assert_eq!(Integer::from(1001).ceiling_root(3), 11);
assert_eq!(Integer::from(100000000000i64).ceiling_root(5), 159);
assert_eq!(Integer::from(-100000000000i64).ceiling_root(5), -158);
§

type Output = Integer

§

impl CeilingRootAssign<u64> for Integer

§

fn ceiling_root_assign(&mut self, exp: u64)

Replaces an Integer 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, or if exp is even and self is negative.

§Examples
use malachite_base::num::arithmetic::traits::CeilingRootAssign;
use malachite_nz::integer::Integer;

let mut x = Integer::from(999);
x.ceiling_root_assign(3);
assert_eq!(x, 10);

let mut x = Integer::from(1000);
x.ceiling_root_assign(3);
assert_eq!(x, 10);

let mut x = Integer::from(1001);
x.ceiling_root_assign(3);
assert_eq!(x, 11);

let mut x = Integer::from(100000000000i64);
x.ceiling_root_assign(5);
assert_eq!(x, 159);

let mut x = Integer::from(-100000000000i64);
x.ceiling_root_assign(5);
assert_eq!(x, -158);
§

impl CeilingSqrt for &Integer

§

fn ceiling_sqrt(self) -> Integer

Returns the ceiling of the square root of an Integer, taking it by reference.

$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().

§Panics

Panics if self is negative.

§Examples
use malachite_base::num::arithmetic::traits::CeilingSqrt;
use malachite_nz::integer::Integer;

assert_eq!(Integer::from(99).ceiling_sqrt(), 10);
assert_eq!(Integer::from(100).ceiling_sqrt(), 10);
assert_eq!(Integer::from(101).ceiling_sqrt(), 11);
assert_eq!(Integer::from(1000000000).ceiling_sqrt(), 31623);
assert_eq!(Integer::from(10000000000u64).ceiling_sqrt(), 100000);
§

type Output = Integer

§

impl CeilingSqrt for Integer

§

fn ceiling_sqrt(self) -> Integer

Returns the ceiling of the square root of an Integer, 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().

§Panics

Panics if self is negative.

§Examples
use malachite_base::num::arithmetic::traits::CeilingSqrt;
use malachite_nz::integer::Integer;

assert_eq!(Integer::from(99).ceiling_sqrt(), 10);
assert_eq!(Integer::from(100).ceiling_sqrt(), 10);
assert_eq!(Integer::from(101).ceiling_sqrt(), 11);
assert_eq!(Integer::from(1000000000).ceiling_sqrt(), 31623);
assert_eq!(Integer::from(10000000000u64).ceiling_sqrt(), 100000);
§

type Output = Integer

§

impl CeilingSqrtAssign for Integer

§

fn ceiling_sqrt_assign(&mut self)

Replaces an Integer 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().

§Panics

Panics if self is negative.

§Examples
use malachite_base::num::arithmetic::traits::CeilingSqrtAssign;
use malachite_nz::integer::Integer;

let mut x = Integer::from(99u8);
x.ceiling_sqrt_assign();
assert_eq!(x, 10);

let mut x = Integer::from(100);
x.ceiling_sqrt_assign();
assert_eq!(x, 10);

let mut x = Integer::from(101);
x.ceiling_sqrt_assign();
assert_eq!(x, 11);

let mut x = Integer::from(1000000000);
x.ceiling_sqrt_assign();
assert_eq!(x, 31623);

let mut x = Integer::from(10000000000u64);
x.ceiling_sqrt_assign();
assert_eq!(x, 100000);
§

impl CheckedDiv<&Integer> for &Integer

§

fn checked_div(self, other: &Integer) -> Option<Integer>

Divides an Integer by another Integer, 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 Integer 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::integer::Integer;

// -2 * -10 + 3 = 23
assert_eq!(
    (&Integer::from(23))
        .checked_div(&Integer::from(-10))
        .to_debug_string(),
    "Some(-2)"
);
assert_eq!((&Integer::ONE).checked_div(&Integer::ZERO), None);
§

type Output = Integer

§

impl CheckedDiv<&Integer> for Integer

§

fn checked_div(self, other: &Integer) -> Option<Integer>

Divides an Integer by another Integer, 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 Integer 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::integer::Integer;

// -2 * -10 + 3 = 23
assert_eq!(
    Integer::from(23)
        .checked_div(&Integer::from(-10))
        .to_debug_string(),
    "Some(-2)"
);
assert_eq!(Integer::ONE.checked_div(&Integer::ZERO), None);
§

type Output = Integer

§

impl CheckedDiv<Integer> for &Integer

§

fn checked_div(self, other: Integer) -> Option<Integer>

Divides an Integer by another Integer, 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 Integer 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::integer::Integer;

// -2 * -10 + 3 = 23
assert_eq!(
    (&Integer::from(23))
        .checked_div(Integer::from(-10))
        .to_debug_string(),
    "Some(-2)"
);
assert_eq!((&Integer::ONE).checked_div(Integer::ZERO), None);
§

type Output = Integer

§

impl CheckedDiv for Integer

§

fn checked_div(self, other: Integer) -> Option<Integer>

Divides an Integer by another Integer, 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 Integer 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::integer::Integer;

// -2 * -10 + 3 = 23
assert_eq!(
    Integer::from(23)
        .checked_div(Integer::from(-10))
        .to_debug_string(),
    "Some(-2)"
);
assert_eq!(Integer::ONE.checked_div(Integer::ZERO), None);
§

type Output = Integer

§

impl CheckedHammingDistance<&Integer> for &Integer

§

fn checked_hamming_distance(self, other: &Integer) -> Option<u64>

Determines the Hamming distance between two Integers.

The two Integers have infinitely many leading zeros or infinitely many leading ones, depending on their signs. If they are both non-negative or both negative, the Hamming distance is finite. If one is non-negative and the other is negative, the Hamming distance is infinite, so None is returned.

§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::logic::traits::CheckedHammingDistance;
use malachite_nz::integer::Integer;

assert_eq!(
    Integer::from(123).checked_hamming_distance(&Integer::from(123)),
    Some(0)
);
// 105 = 1101001b, 123 = 1111011
assert_eq!(
    Integer::from(-105).checked_hamming_distance(&Integer::from(-123)),
    Some(2)
);
assert_eq!(
    Integer::from(-105).checked_hamming_distance(&Integer::from(123)),
    None
);
§

impl CheckedRoot<u64> for &Integer

§

fn checked_root(self, exp: u64) -> Option<Integer>

Returns the the $n$th root of an Integer, or None if the Integer is not a perfect $n$th power. The Integer 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, or if exp is even and self is negative.

§Examples
use malachite_base::num::arithmetic::traits::CheckedRoot;
use malachite_base::strings::ToDebugString;
use malachite_nz::integer::Integer;

assert_eq!(
    (&Integer::from(999)).checked_root(3).to_debug_string(),
    "None"
);
assert_eq!(
    (&Integer::from(1000)).checked_root(3).to_debug_string(),
    "Some(10)"
);
assert_eq!(
    (&Integer::from(1001)).checked_root(3).to_debug_string(),
    "None"
);
assert_eq!(
    (&Integer::from(100000000000i64))
        .checked_root(5)
        .to_debug_string(),
    "None"
);
assert_eq!(
    (&Integer::from(-100000000000i64))
        .checked_root(5)
        .to_debug_string(),
    "None"
);
assert_eq!(
    (&Integer::from(10000000000i64))
        .checked_root(5)
        .to_debug_string(),
    "Some(100)"
);
assert_eq!(
    (&Integer::from(-10000000000i64))
        .checked_root(5)
        .to_debug_string(),
    "Some(-100)"
);
§

type Output = Integer

§

impl CheckedRoot<u64> for Integer

§

fn checked_root(self, exp: u64) -> Option<Integer>

Returns the the $n$th root of an Integer, or None if the Integer is not a perfect $n$th power. The Integer 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, or if exp is even and self is negative.

§Examples
use malachite_base::num::arithmetic::traits::CheckedRoot;
use malachite_base::strings::ToDebugString;
use malachite_nz::integer::Integer;

assert_eq!(Integer::from(999).checked_root(3).to_debug_string(), "None");
assert_eq!(
    Integer::from(1000).checked_root(3).to_debug_string(),
    "Some(10)"
);
assert_eq!(
    Integer::from(1001).checked_root(3).to_debug_string(),
    "None"
);
assert_eq!(
    Integer::from(100000000000i64)
        .checked_root(5)
        .to_debug_string(),
    "None"
);
assert_eq!(
    Integer::from(-100000000000i64)
        .checked_root(5)
        .to_debug_string(),
    "None"
);
assert_eq!(
    Integer::from(10000000000i64)
        .checked_root(5)
        .to_debug_string(),
    "Some(100)"
);
assert_eq!(
    Integer::from(-10000000000i64)
        .checked_root(5)
        .to_debug_string(),
    "Some(-100)"
);
§

type Output = Integer

§

impl CheckedSqrt for &Integer

§

fn checked_sqrt(self) -> Option<Integer>

Returns the the square root of an Integer, or None if it is not a perfect square. The Integer is taken by reference.

$$ 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().

§Panics

Panics if self is negative.

§Examples
use malachite_base::num::arithmetic::traits::CheckedSqrt;
use malachite_base::strings::ToDebugString;
use malachite_nz::integer::Integer;

assert_eq!(
    (&Integer::from(99u8)).checked_sqrt().to_debug_string(),
    "None"
);
assert_eq!(
    (&Integer::from(100u8)).checked_sqrt().to_debug_string(),
    "Some(10)"
);
assert_eq!(
    (&Integer::from(101u8)).checked_sqrt().to_debug_string(),
    "None"
);
assert_eq!(
    (&Integer::from(1000000000u32))
        .checked_sqrt()
        .to_debug_string(),
    "None"
);
assert_eq!(
    (&Integer::from(10000000000u64))
        .checked_sqrt()
        .to_debug_string(),
    "Some(100000)"
);
§

type Output = Integer

§

impl CheckedSqrt for Integer

§

fn checked_sqrt(self) -> Option<Integer>

Returns the the square root of an Integer, or None if it is not a perfect square. The Integer 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().

§Panics

Panics if self is negative.

§Examples
use malachite_base::num::arithmetic::traits::CheckedSqrt;
use malachite_base::strings::ToDebugString;
use malachite_nz::integer::Integer;

assert_eq!(Integer::from(99u8).checked_sqrt().to_debug_string(), "None");
assert_eq!(
    Integer::from(100u8).checked_sqrt().to_debug_string(),
    "Some(10)"
);
assert_eq!(
    Integer::from(101u8).checked_sqrt().to_debug_string(),
    "None"
);
assert_eq!(
    Integer::from(1000000000u32)
        .checked_sqrt()
        .to_debug_string(),
    "None"
);
assert_eq!(
    Integer::from(10000000000u64)
        .checked_sqrt()
        .to_debug_string(),
    "Some(100000)"
);
§

type Output = Integer

§

impl Clone for Integer

§

fn clone(&self) -> Integer

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl<'a> ConvertibleFrom<&'a Integer> for Natural

§

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
);
§

impl<'a> ConvertibleFrom<&'a Integer> for u32

§

fn convertible_from(value: &Integer) -> bool

Determines whether an Integer can be converted to an unsigned primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

impl ConvertibleFrom<&Rational> for Integer

§

fn convertible_from(x: &Rational) -> bool

Determines whether a [Rational] can be converted to an Integer, taking the [Rational] by reference.

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::num::conversion::traits::ConvertibleFrom;
use malachite_nz::integer::Integer;
use malachite_q::Rational;

assert_eq!(Integer::convertible_from(&Rational::from(123)), true);
assert_eq!(Integer::convertible_from(&Rational::from(-123)), true);
assert_eq!(
    Integer::convertible_from(&Rational::from_signeds(22, 7)),
    false
);
§

impl ConvertibleFrom<Integer> for Natural

§

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
);
§

impl ConvertibleFrom<f32> for Integer

§

fn convertible_from(value: f32) -> bool

Determines whether a primitive float can be exactly converted to an Integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

impl ConvertibleFrom<f64> for Integer

§

fn convertible_from(value: f64) -> bool

Determines whether a primitive float can be exactly converted to an Integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

Source§

impl DcForgivingDefault for Integer

Source§

fn dc_forgiving_default() -> Self

Produces a placeholder value when a required field or element is missing or malformed in forgiving mode.
Source§

impl DcMixedDecode for Integer

Source§

fn decode_dc_node( ctx: &mut DcProjectionContext<'_, '_>, node_id: NodeId, ) -> Result<Self>

Projects an instance from the given syntax node_id under ctx. Read more
Source§

fn decode_dc_document( ctx: &mut DcProjectionContext<'_, '_>, roots: &[NodeId], ) -> Result<(Self, usize)>

Projects a document and returns the number of roots consumed. Read more
Source§

impl DcMixedEncode for Integer

Source§

fn encode_dc_mixed_to(&self, mst: &mut DcWriter<'_>) -> Result<()>

Serializes a record without a document header. Read more
Source§

fn encode_dc_mixed(&self, mst: &mut DcMstring) -> Result<()>

Source§

fn encode_dc_mixed_with_context( &self, mst: &mut DcMstring, context: &SharedValueContext, ) -> Result<()>

Source§

fn encode_format_elements_with_context( &self, format: DcChar, mst: &mut DcMstring, context: &SharedValueContext, ) -> Result<()>

Source§

fn write_dc_mixed(&self, output: &mut dyn Write) -> Result<()>

Writes a complete DcMM document, including its header.
Source§

fn to_dc_mixed(&self) -> Result<DcMstring>

Encodes a new mixed-mode string, not a preserved source string.
Source§

fn to_dc_string(&self) -> Result<DcString>

Encodes a new DcUtf string, explicitly converting any encapsulations.
Source§

fn encode_dc_mixed_to_with_context( &self, mst: &mut DcWriter<'_>, _context: &SharedValueContext, ) -> Result<()>

Encodes with explicit definitions already persisted by the caller.
Source§

fn encode_format_elements_to_with_context( &self, format: DcChar, mst: &mut DcWriter<'_>, context: &SharedValueContext, ) -> Result<()>

Encodes this value inside a Dc 511 [format] ... Dc 512 format representation container.
§

impl Debug for Integer

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Converts an Integer 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 core::str::FromStr;
use malachite_base::num::basic::traits::Zero;
use malachite_base::strings::ToDebugString;
use malachite_nz::integer::Integer;

assert_eq!(Integer::ZERO.to_debug_string(), "0");

assert_eq!(Integer::from(123).to_debug_string(), "123");
assert_eq!(
    Integer::from_str("1000000000000")
        .unwrap()
        .to_debug_string(),
    "1000000000000"
);
assert_eq!(format!("{:05?}", Integer::from(123)), "00123");

assert_eq!(Integer::from(-123).to_debug_string(), "-123");
assert_eq!(
    Integer::from_str("-1000000000000")
        .unwrap()
        .to_debug_string(),
    "-1000000000000"
);
assert_eq!(format!("{:05?}", Integer::from(-123)), "-0123");
§

impl Default for Integer

§

fn default() -> Integer

The default value of an Integer, 0.

§

impl Display for Integer

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Converts an Integer 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 core::str::FromStr;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::integer::Integer;

assert_eq!(Integer::ZERO.to_string(), "0");

assert_eq!(Integer::from(123).to_string(), "123");
assert_eq!(
    Integer::from_str("1000000000000").unwrap().to_string(),
    "1000000000000"
);
assert_eq!(format!("{:05}", Integer::from(123)), "00123");

assert_eq!(Integer::from(-123).to_string(), "-123");
assert_eq!(
    Integer::from_str("-1000000000000").unwrap().to_string(),
    "-1000000000000"
);
assert_eq!(format!("{:05}", Integer::from(-123)), "-0123");
§

impl Div<&Integer> for &Integer

§

fn div(self, other: &Integer) -> Integer

Divides an Integer by another Integer, taking both by reference. The quotient is rounded towards zero. The quotient and remainder (which is not computed) satisfy $x = qy + r$ and $0 \leq |r| < |y|$.

$$ f(x, y) = \operatorname{sgn}(xy) \left \lfloor \left | \frac{x}{y} \right | \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::integer::Integer;

// 2 * 10 + 3 = 23
assert_eq!(&Integer::from(23) / &Integer::from(10), 2);

// -2 * -10 + 3 = 23
assert_eq!(&Integer::from(23) / &Integer::from(-10), -2);

// -2 * 10 + -3 = -23
assert_eq!(&Integer::from(-23) / &Integer::from(10), -2);

// 2 * -10 + -3 = -23
assert_eq!(&Integer::from(-23) / &Integer::from(-10), 2);
§

type Output = Integer

The resulting type after applying the / operator.
§

impl Div<&Integer> for Integer

§

fn div(self, other: &Integer) -> Integer

Divides an Integer by another Integer, taking the first by value and the second by reference. The quotient is rounded towards zero. The quotient and remainder (which is not computed) satisfy $x = qy + r$ and $0 \leq |r| < |y|$.

$$ f(x, y) = \operatorname{sgn}(xy) \left \lfloor \left | \frac{x}{y} \right | \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::integer::Integer;

// 2 * 10 + 3 = 23
assert_eq!(Integer::from(23) / &Integer::from(10), 2);

// -2 * -10 + 3 = 23
assert_eq!(Integer::from(23) / &Integer::from(-10), -2);

// -2 * 10 + -3 = -23
assert_eq!(Integer::from(-23) / &Integer::from(10), -2);

// 2 * -10 + -3 = -23
assert_eq!(Integer::from(-23) / &Integer::from(-10), 2);
§

type Output = Integer

The resulting type after applying the / operator.
§

impl Div<Integer> for &Integer

§

fn div(self, other: Integer) -> Integer

Divides an Integer by another Integer, taking the first by reference and the second by value. The quotient is rounded towards zero. The quotient and remainder (which is not computed) satisfy $x = qy + r$ and $0 \leq |r| < |y|$.

$$ f(x, y) = \operatorname{sgn}(xy) \left \lfloor \left | \frac{x}{y} \right | \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::integer::Integer;

// 2 * 10 + 3 = 23
assert_eq!(&Integer::from(23) / Integer::from(10), 2);

// -2 * -10 + 3 = 23
assert_eq!(&Integer::from(23) / Integer::from(-10), -2);

// -2 * 10 + -3 = -23
assert_eq!(&Integer::from(-23) / Integer::from(10), -2);

// 2 * -10 + -3 = -23
assert_eq!(&Integer::from(-23) / Integer::from(-10), 2);
§

type Output = Integer

The resulting type after applying the / operator.
§

impl Div for Integer

§

fn div(self, other: Integer) -> Integer

Divides an Integer by another Integer, taking both by value. The quotient is rounded towards zero. The quotient and remainder (which is not computed) satisfy $x = qy + r$ and $0 \leq |r| < |y|$.

$$ f(x, y) = \operatorname{sgn}(xy) \left \lfloor \left | \frac{x}{y} \right | \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::integer::Integer;

// 2 * 10 + 3 = 23
assert_eq!(Integer::from(23) / Integer::from(10), 2);

// -2 * -10 + 3 = 23
assert_eq!(Integer::from(23) / Integer::from(-10), -2);

// -2 * 10 + -3 = -23
assert_eq!(Integer::from(-23) / Integer::from(10), -2);

// 2 * -10 + -3 = -23
assert_eq!(Integer::from(-23) / Integer::from(-10), 2);
§

type Output = Integer

The resulting type after applying the / operator.
§

impl DivAssign<&Integer> for Integer

§

fn div_assign(&mut self, other: &Integer)

Divides an Integer by another Integer in place, taking the Integer on the right-hand side by reference. The quotient is rounded towards zero. The quotient and remainder (which is not computed) satisfy $x = qy + r$ and $0 \leq |r| < |y|$.

$$ x \gets \operatorname{sgn}(xy) \left \lfloor \left | \frac{x}{y} \right | \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::integer::Integer;

// 2 * 10 + 3 = 23
let mut x = Integer::from(23);
x /= &Integer::from(10);
assert_eq!(x, 2);

// -2 * -10 + 3 = 23
let mut x = Integer::from(23);
x /= &Integer::from(-10);
assert_eq!(x, -2);

// -2 * 10 + -3 = -23
let mut x = Integer::from(-23);
x /= &Integer::from(10);
assert_eq!(x, -2);

// 2 * -10 + -3 = -23
let mut x = Integer::from(-23);
x /= &Integer::from(-10);
assert_eq!(x, 2);
§

impl DivAssign for Integer

§

fn div_assign(&mut self, other: Integer)

Divides an Integer by another Integer in place, taking the Integer on the right-hand side by value. The quotient is rounded towards zero. The quotient and remainder (which is not computed) satisfy $x = qy + r$ and $0 \leq |r| < |y|$.

$$ x \gets \operatorname{sgn}(xy) \left \lfloor \left | \frac{x}{y} \right | \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::integer::Integer;

// 2 * 10 + 3 = 23
let mut x = Integer::from(23);
x /= Integer::from(10);
assert_eq!(x, 2);

// -2 * -10 + 3 = 23
let mut x = Integer::from(23);
x /= Integer::from(-10);
assert_eq!(x, -2);

// -2 * 10 + -3 = -23
let mut x = Integer::from(-23);
x /= Integer::from(10);
assert_eq!(x, -2);

// 2 * -10 + -3 = -23
let mut x = Integer::from(-23);
x /= Integer::from(-10);
assert_eq!(x, 2);
§

impl DivAssignEuclidean<&Integer> for Integer

§

fn div_assign_euclidean(&mut self, other: &Integer) -> Natural

Divides an Integer by another Integer in place, taking the Integer on the right-hand side by reference and returning the remainder. The quotient is rounded so that the remainder is nonnegative.

The quotient and remainder satisfy $x = qy + r$ and $0 \leq r < |y|$.

$$ f(x, y) = x - y \operatorname{sgn}(y) \left \lfloor \frac{x}{|y|} \right \rfloor, $$ $$ x \gets \operatorname{sgn}(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::DivAssignEuclidean;
use malachite_nz::integer::Integer;

// 3 * -10 + 7 = -23
let mut x = Integer::from(-23);
assert_eq!(x.div_assign_euclidean(&Integer::from(-10)), 7);
assert_eq!(x, 3);
§

type ModOutput = Natural

§

impl DivAssignEuclidean for Integer

§

fn div_assign_euclidean(&mut self, other: Integer) -> Natural

Divides an Integer by another Integer in place, taking the Integer on the right-hand side by value and returning the remainder. The quotient is rounded so that the remainder is nonnegative.

The quotient and remainder satisfy $x = qy + r$ and $0 \leq r < |y|$.

$$ f(x, y) = x - y \operatorname{sgn}(y) \left \lfloor \frac{x}{|y|} \right \rfloor, $$ $$ x \gets \operatorname{sgn}(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::DivAssignEuclidean;
use malachite_nz::integer::Integer;

// -3 * 10 + 7 = -23
let mut x = Integer::from(-23);
assert_eq!(x.div_assign_euclidean(Integer::from(10)), 7);
assert_eq!(x, -3);
§

type ModOutput = Natural

§

impl DivAssignMod<&Integer> for Integer

§

fn div_assign_mod(&mut self, other: &Integer) -> Integer

Divides an Integer by another Integer in place, taking the Integer on the right-hand side by reference and returning the remainder. The quotient is rounded towards negative infinity, and the remainder has the same sign as the second Integer.

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::integer::Integer;

// 2 * 10 + 3 = 23
let mut x = Integer::from(23);
assert_eq!(x.div_assign_mod(&Integer::from(10)), 3);
assert_eq!(x, 2);

// -3 * -10 + -7 = 23
let mut x = Integer::from(23);
assert_eq!(x.div_assign_mod(&Integer::from(-10)), -7);
assert_eq!(x, -3);

// -3 * 10 + 7 = -23
let mut x = Integer::from(-23);
assert_eq!(x.div_assign_mod(&Integer::from(10)), 7);
assert_eq!(x, -3);

// 2 * -10 + -3 = -23
let mut x = Integer::from(-23);
assert_eq!(x.div_assign_mod(&Integer::from(-10)), -3);
assert_eq!(x, 2);
§

type ModOutput = Integer

§

impl DivAssignMod for Integer

§

fn div_assign_mod(&mut self, other: Integer) -> Integer

Divides an Integer by another Integer in place, taking the Integer on the right-hand side by value and returning the remainder. The quotient is rounded towards negative infinity, and the remainder has the same sign as the second Integer.

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::integer::Integer;

// 2 * 10 + 3 = 23
let mut x = Integer::from(23);
assert_eq!(x.div_assign_mod(Integer::from(10)), 3);
assert_eq!(x, 2);

// -3 * -10 + -7 = 23
let mut x = Integer::from(23);
assert_eq!(x.div_assign_mod(Integer::from(-10)), -7);
assert_eq!(x, -3);

// -3 * 10 + 7 = -23
let mut x = Integer::from(-23);
assert_eq!(x.div_assign_mod(Integer::from(10)), 7);
assert_eq!(x, -3);

// 2 * -10 + -3 = -23
let mut x = Integer::from(-23);
assert_eq!(x.div_assign_mod(Integer::from(-10)), -3);
assert_eq!(x, 2);
§

type ModOutput = Integer

§

impl DivAssignRem<&Integer> for Integer

§

fn div_assign_rem(&mut self, other: &Integer) -> Integer

Divides an Integer by another Integer in place, taking the Integer on the right-hand side by reference and returning the remainder. The quotient is rounded towards zero and the remainder has the same sign as the first Integer.

The quotient and remainder satisfy $x = qy + r$ and $0 \leq |r| < |y|$.

$$ f(x, y) = x - y \operatorname{sgn}(xy) \left \lfloor \left | \frac{x}{y} \right | \right \rfloor, $$ $$ x \gets \operatorname{sgn}(xy) \left \lfloor \left | \frac{x}{y} \right | \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::DivAssignRem;
use malachite_nz::integer::Integer;

// 2 * 10 + 3 = 23
let mut x = Integer::from(23);
assert_eq!(x.div_assign_rem(&Integer::from(10)), 3);
assert_eq!(x, 2);

// -2 * -10 + 3 = 23
let mut x = Integer::from(23);
assert_eq!(x.div_assign_rem(&Integer::from(-10)), 3);
assert_eq!(x, -2);

// -2 * 10 + -3 = -23
let mut x = Integer::from(-23);
assert_eq!(x.div_assign_rem(&Integer::from(10)), -3);
assert_eq!(x, -2);

// 2 * -10 + -3 = -23
let mut x = Integer::from(-23);
assert_eq!(x.div_assign_rem(&Integer::from(-10)), -3);
assert_eq!(x, 2);
§

type RemOutput = Integer

§

impl DivAssignRem for Integer

§

fn div_assign_rem(&mut self, other: Integer) -> Integer

Divides an Integer by another Integer in place, taking the Integer on the right-hand side by value and returning the remainder. The quotient is rounded towards zero and the remainder has the same sign as the first Integer.

The quotient and remainder satisfy $x = qy + r$ and $0 \leq |r| < |y|$.

$$ f(x, y) = x - y \operatorname{sgn}(xy) \left \lfloor \left | \frac{x}{y} \right | \right \rfloor, $$ $$ x \gets \operatorname{sgn}(xy) \left \lfloor \left | \frac{x}{y} \right | \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::DivAssignRem;
use malachite_nz::integer::Integer;

// 2 * 10 + 3 = 23
let mut x = Integer::from(23);
assert_eq!(x.div_assign_rem(Integer::from(10)), 3);
assert_eq!(x, 2);

// -2 * -10 + 3 = 23
let mut x = Integer::from(23);
assert_eq!(x.div_assign_rem(Integer::from(-10)), 3);
assert_eq!(x, -2);

// -2 * 10 + -3 = -23
let mut x = Integer::from(-23);
assert_eq!(x.div_assign_rem(Integer::from(10)), -3);
assert_eq!(x, -2);

// 2 * -10 + -3 = -23
let mut x = Integer::from(-23);
assert_eq!(x.div_assign_rem(Integer::from(-10)), -3);
assert_eq!(x, 2);
§

type RemOutput = Integer

§

impl DivEuclidean<&Integer> for &Integer

§

fn div_euclidean(self, other: &Integer) -> (Integer, Natural)

Divides an Integer by another Integer, taking both by reference and returning the quotient and remainder. The quotient is rounded so that the remainder is nonnegative; the remainder is returned as a Natural.

The quotient and remainder satisfy $x = qy + r$ and $0 \leq r < |y|$.

$$ f(x, y) = \left ( \operatorname{sgn}(y) \left \lfloor \frac{x}{|y|} \right \rfloor, \space x - y \operatorname{sgn}(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::DivEuclidean;
use malachite_base::strings::ToDebugString;
use malachite_nz::integer::Integer;

// 3 * -10 + 7 = -23
assert_eq!(
    (&Integer::from(-23))
        .div_euclidean(&Integer::from(-10))
        .to_debug_string(),
    "(3, 7)"
);
§

type DivOutput = Integer

§

type ModOutput = Natural

§

impl DivEuclidean<&Integer> for Integer

§

fn div_euclidean(self, other: &Integer) -> (Integer, Natural)

Divides an Integer by another Integer, taking the first by value and the second by reference and returning the quotient and remainder. The quotient is rounded so that the remainder is nonnegative; the remainder is returned as a Natural.

The quotient and remainder satisfy $x = qy + r$ and $0 \leq r < |y|$.

$$ f(x, y) = \left ( \operatorname{sgn}(y) \left \lfloor \frac{x}{|y|} \right \rfloor, \space x - y \operatorname{sgn}(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::DivEuclidean;
use malachite_base::strings::ToDebugString;
use malachite_nz::integer::Integer;

// -3 * 10 + 7 = -23
assert_eq!(
    Integer::from(-23)
        .div_euclidean(&Integer::from(10))
        .to_debug_string(),
    "(-3, 7)"
);
§

type DivOutput = Integer

§

type ModOutput = Natural

§

impl DivEuclidean<Integer> for &Integer

§

fn div_euclidean(self, other: Integer) -> (Integer, Natural)

Divides an Integer by another Integer, taking the first by reference and the second by value and returning the quotient and remainder. The quotient is rounded so that the remainder is nonnegative; the remainder is returned as a Natural.

The quotient and remainder satisfy $x = qy + r$ and $0 \leq r < |y|$.

$$ f(x, y) = \left ( \operatorname{sgn}(y) \left \lfloor \frac{x}{|y|} \right \rfloor, \space x - y \operatorname{sgn}(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::DivEuclidean;
use malachite_base::strings::ToDebugString;
use malachite_nz::integer::Integer;

// -2 * -10 + 3 = 23
assert_eq!(
    (&Integer::from(23))
        .div_euclidean(Integer::from(-10))
        .to_debug_string(),
    "(-2, 3)"
);
§

type DivOutput = Integer

§

type ModOutput = Natural

§

impl DivEuclidean for Integer

§

fn div_euclidean(self, other: Integer) -> (Integer, Natural)

Divides an Integer by another Integer, taking both by value and returning the quotient and remainder. The quotient is rounded so that the remainder is nonnegative; the remainder is returned as a Natural.

The quotient and remainder satisfy $x = qy + r$ and $0 \leq r < |y|$.

$$ f(x, y) = \left ( \operatorname{sgn}(y) \left \lfloor \frac{x}{|y|} \right \rfloor, \space x - y \operatorname{sgn}(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::DivEuclidean;
use malachite_base::strings::ToDebugString;
use malachite_nz::integer::Integer;

// 2 * 10 + 3 = 23
assert_eq!(
    Integer::from(23)
        .div_euclidean(Integer::from(10))
        .to_debug_string(),
    "(2, 3)"
);

// 3 * -10 + 7 = -23
assert_eq!(
    Integer::from(-23)
        .div_euclidean(Integer::from(-10))
        .to_debug_string(),
    "(3, 7)"
);
§

type DivOutput = Integer

§

type ModOutput = Natural

§

impl DivExact<&Integer> for &Integer

§

fn div_exact(self, other: &Integer) -> Integer

Divides an Integer by another Integer, taking both by reference. The first Integer 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, Exact).

§Panics

Panics if other is zero. May panic if self is not divisible by other.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::DivExact;
use malachite_nz::integer::Integer;

// -123 * 456 = -56088
assert_eq!(
    (&Integer::from(-56088)).div_exact(&Integer::from(456)),
    -123
);

// -123456789000 * -987654321000 = 121932631112635269000000
assert_eq!(
    (&Integer::from_str("121932631112635269000000").unwrap())
        .div_exact(&Integer::from_str("-987654321000").unwrap()),
    -123456789000i64
);
§

type Output = Integer

§

impl DivExact<&Integer> for Integer

§

fn div_exact(self, other: &Integer) -> Integer

Divides an Integer by another Integer, taking the first by value and the second by reference. The first Integer 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, 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 core::str::FromStr;
use malachite_base::num::arithmetic::traits::DivExact;
use malachite_nz::integer::Integer;

// -123 * 456 = -56088
assert_eq!(Integer::from(-56088).div_exact(&Integer::from(456)), -123);

// -123456789000 * -987654321000 = 121932631112635269000000
assert_eq!(
    Integer::from_str("121932631112635269000000")
        .unwrap()
        .div_exact(&Integer::from_str("-987654321000").unwrap()),
    -123456789000i64
);
§

type Output = Integer

§

impl DivExact<Integer> for &Integer

§

fn div_exact(self, other: Integer) -> Integer

Divides an Integer by another Integer, taking the first by reference and the second by value. The first Integer 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, 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 core::str::FromStr;
use malachite_base::num::arithmetic::traits::DivExact;
use malachite_nz::integer::Integer;

// -123 * 456 = -56088
assert_eq!((&Integer::from(-56088)).div_exact(Integer::from(456)), -123);

// -123456789000 * -987654321000 = 121932631112635269000000
assert_eq!(
    (&Integer::from_str("121932631112635269000000").unwrap())
        .div_exact(Integer::from_str("-987654321000").unwrap()),
    -123456789000i64
);
§

type Output = Integer

§

impl DivExact for Integer

§

fn div_exact(self, other: Integer) -> Integer

Divides an Integer by another Integer, taking both by value. The first Integer 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, 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 core::str::FromStr;
use malachite_base::num::arithmetic::traits::DivExact;
use malachite_nz::integer::Integer;

// -123 * 456 = -56088
assert_eq!(Integer::from(-56088).div_exact(Integer::from(456)), -123);

// -123456789000 * -987654321000 = 121932631112635269000000
assert_eq!(
    Integer::from_str("121932631112635269000000")
        .unwrap()
        .div_exact(Integer::from_str("-987654321000").unwrap()),
    -123456789000i64
);
§

type Output = Integer

§

impl DivExactAssign<&Integer> for Integer

§

fn div_exact_assign(&mut self, other: &Integer)

Divides an Integer by another Integer in place, taking the Integer on the right-hand side by reference. The first Integer 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, 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 core::str::FromStr;
use malachite_base::num::arithmetic::traits::DivExactAssign;
use malachite_nz::integer::Integer;

// -123 * 456 = -56088
let mut x = Integer::from(-56088);
x.div_exact_assign(&Integer::from(456));
assert_eq!(x, -123);

// -123456789000 * -987654321000 = 121932631112635269000000
let mut x = Integer::from_str("121932631112635269000000").unwrap();
x.div_exact_assign(&Integer::from_str("-987654321000").unwrap());
assert_eq!(x, -123456789000i64);
§

impl DivExactAssign for Integer

§

fn div_exact_assign(&mut self, other: Integer)

Divides an Integer by another Integer in place, taking the Integer on the right-hand side by value. The first Integer 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, 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 core::str::FromStr;
use malachite_base::num::arithmetic::traits::DivExactAssign;
use malachite_nz::integer::Integer;

// -123 * 456 = -56088
let mut x = Integer::from(-56088);
x.div_exact_assign(Integer::from(456));
assert_eq!(x, -123);

// -123456789000 * -987654321000 = 121932631112635269000000
let mut x = Integer::from_str("121932631112635269000000").unwrap();
x.div_exact_assign(Integer::from_str("-987654321000").unwrap());
assert_eq!(x, -123456789000i64);
§

impl DivMod<&Integer> for &Integer

§

fn div_mod(self, other: &Integer) -> (Integer, Integer)

Divides an Integer by another Integer, taking both by reference and returning the quotient and remainder. The quotient is rounded towards negative infinity, and the remainder has the same sign as the second Integer.

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::integer::Integer;

// 2 * 10 + 3 = 23
assert_eq!(
    (&Integer::from(23))
        .div_mod(&Integer::from(10))
        .to_debug_string(),
    "(2, 3)"
);

// -3 * -10 + -7 = 23
assert_eq!(
    (&Integer::from(23))
        .div_mod(&Integer::from(-10))
        .to_debug_string(),
    "(-3, -7)"
);

// -3 * 10 + 7 = -23
assert_eq!(
    (&Integer::from(-23))
        .div_mod(&Integer::from(10))
        .to_debug_string(),
    "(-3, 7)"
);

// 2 * -10 + -3 = -23
assert_eq!(
    (&Integer::from(-23))
        .div_mod(&Integer::from(-10))
        .to_debug_string(),
    "(2, -3)"
);
§

type DivOutput = Integer

§

type ModOutput = Integer

§

impl DivMod<&Integer> for Integer

§

fn div_mod(self, other: &Integer) -> (Integer, Integer)

Divides an Integer by another Integer, taking the first by value and the second by reference and returning the quotient and remainder. The quotient is rounded towards negative infinity, and the remainder has the same sign as the second Integer.

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::integer::Integer;

// 2 * 10 + 3 = 23
assert_eq!(
    Integer::from(23)
        .div_mod(&Integer::from(10))
        .to_debug_string(),
    "(2, 3)"
);

// -3 * -10 + -7 = 23
assert_eq!(
    Integer::from(23)
        .div_mod(&Integer::from(-10))
        .to_debug_string(),
    "(-3, -7)"
);

// -3 * 10 + 7 = -23
assert_eq!(
    Integer::from(-23)
        .div_mod(&Integer::from(10))
        .to_debug_string(),
    "(-3, 7)"
);

// 2 * -10 + -3 = -23
assert_eq!(
    Integer::from(-23)
        .div_mod(&Integer::from(-10))
        .to_debug_string(),
    "(2, -3)"
);
§

type DivOutput = Integer

§

type ModOutput = Integer

§

impl DivMod<Integer> for &Integer

§

fn div_mod(self, other: Integer) -> (Integer, Integer)

Divides an Integer by another Integer, taking the first by reference and the second by value and returning the quotient and remainder. The quotient is rounded towards negative infinity, and the remainder has the same sign as the second Integer.

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::integer::Integer;

// 2 * 10 + 3 = 23
assert_eq!(
    (&Integer::from(23))
        .div_mod(Integer::from(10))
        .to_debug_string(),
    "(2, 3)"
);

// -3 * -10 + -7 = 23
assert_eq!(
    (&Integer::from(23))
        .div_mod(Integer::from(-10))
        .to_debug_string(),
    "(-3, -7)"
);

// -3 * 10 + 7 = -23
assert_eq!(
    (&Integer::from(-23))
        .div_mod(Integer::from(10))
        .to_debug_string(),
    "(-3, 7)"
);

// 2 * -10 + -3 = -23
assert_eq!(
    (&Integer::from(-23))
        .div_mod(Integer::from(-10))
        .to_debug_string(),
    "(2, -3)"
);
§

type DivOutput = Integer

§

type ModOutput = Integer

§

impl DivMod for Integer

§

fn div_mod(self, other: Integer) -> (Integer, Integer)

Divides an Integer by another Integer, taking both by value and returning the quotient and remainder. The quotient is rounded towards negative infinity, and the remainder has the same sign as the second Integer.

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::integer::Integer;

// 2 * 10 + 3 = 23
assert_eq!(
    Integer::from(23)
        .div_mod(Integer::from(10))
        .to_debug_string(),
    "(2, 3)"
);

// -3 * -10 + -7 = 23
assert_eq!(
    Integer::from(23)
        .div_mod(Integer::from(-10))
        .to_debug_string(),
    "(-3, -7)"
);

// -3 * 10 + 7 = -23
assert_eq!(
    Integer::from(-23)
        .div_mod(Integer::from(10))
        .to_debug_string(),
    "(-3, 7)"
);

// 2 * -10 + -3 = -23
assert_eq!(
    Integer::from(-23)
        .div_mod(Integer::from(-10))
        .to_debug_string(),
    "(2, -3)"
);
§

type DivOutput = Integer

§

type ModOutput = Integer

§

impl DivRem<&Integer> for &Integer

§

fn div_rem(self, other: &Integer) -> (Integer, Integer)

Divides an Integer by another Integer, taking both by reference and returning the quotient and remainder. The quotient is rounded towards zero and the remainder has the same sign as the first Integer.

The quotient and remainder satisfy $x = qy + r$ and $0 \leq |r| < |y|$.

$$ f(x, y) = \left ( \operatorname{sgn}(xy) \left \lfloor \left | \frac{x}{y} \right | \right \rfloor, \space x - y \operatorname{sgn}(xy) \left \lfloor \left | \frac{x}{y} \right | \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::DivRem;
use malachite_base::strings::ToDebugString;
use malachite_nz::integer::Integer;

// 2 * 10 + 3 = 23
assert_eq!(
    (&Integer::from(23))
        .div_rem(&Integer::from(10))
        .to_debug_string(),
    "(2, 3)"
);

// -2 * -10 + 3 = 23
assert_eq!(
    (&Integer::from(23))
        .div_rem(&Integer::from(-10))
        .to_debug_string(),
    "(-2, 3)"
);

// -2 * 10 + -3 = -23
assert_eq!(
    (&Integer::from(-23))
        .div_rem(&Integer::from(10))
        .to_debug_string(),
    "(-2, -3)"
);

// 2 * -10 + -3 = -23
assert_eq!(
    (&Integer::from(-23))
        .div_rem(&Integer::from(-10))
        .to_debug_string(),
    "(2, -3)"
);
§

type DivOutput = Integer

§

type RemOutput = Integer

§

impl DivRem<&Integer> for Integer

§

fn div_rem(self, other: &Integer) -> (Integer, Integer)

Divides an Integer by another Integer, taking the first by value and the second by reference and returning the quotient and remainder. The quotient is rounded towards zero and the remainder has the same sign as the first Integer.

The quotient and remainder satisfy $x = qy + r$ and $0 \leq |r| < |y|$.

$$ f(x, y) = \left ( \operatorname{sgn}(xy) \left \lfloor \left | \frac{x}{y} \right | \right \rfloor, \space x - y \operatorname{sgn}(xy) \left \lfloor \left | \frac{x}{y} \right | \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::DivRem;
use malachite_base::strings::ToDebugString;
use malachite_nz::integer::Integer;

// 2 * 10 + 3 = 23
assert_eq!(
    Integer::from(23)
        .div_rem(&Integer::from(10))
        .to_debug_string(),
    "(2, 3)"
);

// -2 * -10 + 3 = 23
assert_eq!(
    Integer::from(23)
        .div_rem(&Integer::from(-10))
        .to_debug_string(),
    "(-2, 3)"
);

// -2 * 10 + -3 = -23
assert_eq!(
    Integer::from(-23)
        .div_rem(&Integer::from(10))
        .to_debug_string(),
    "(-2, -3)"
);

// 2 * -10 + -3 = -23
assert_eq!(
    Integer::from(-23)
        .div_rem(&Integer::from(-10))
        .to_debug_string(),
    "(2, -3)"
);
§

type DivOutput = Integer

§

type RemOutput = Integer

§

impl DivRem<Integer> for &Integer

§

fn div_rem(self, other: Integer) -> (Integer, Integer)

Divides an Integer by another Integer, taking the first by reference and the second by value and returning the quotient and remainder. The quotient is rounded towards zero and the remainder has the same sign as the first Integer.

The quotient and remainder satisfy $x = qy + r$ and $0 \leq |r| < |y|$.

$$ f(x, y) = \left ( \operatorname{sgn}(xy) \left \lfloor \left | \frac{x}{y} \right | \right \rfloor, \space x - y \operatorname{sgn}(xy) \left \lfloor \left | \frac{x}{y} \right | \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::DivRem;
use malachite_base::strings::ToDebugString;
use malachite_nz::integer::Integer;

// 2 * 10 + 3 = 23
assert_eq!(
    (&Integer::from(23))
        .div_rem(Integer::from(10))
        .to_debug_string(),
    "(2, 3)"
);

// -2 * -10 + 3 = 23
assert_eq!(
    (&Integer::from(23))
        .div_rem(Integer::from(-10))
        .to_debug_string(),
    "(-2, 3)"
);

// -2 * 10 + -3 = -23
assert_eq!(
    (&Integer::from(-23))
        .div_rem(Integer::from(10))
        .to_debug_string(),
    "(-2, -3)"
);

// 2 * -10 + -3 = -23
assert_eq!(
    (&Integer::from(-23))
        .div_rem(Integer::from(-10))
        .to_debug_string(),
    "(2, -3)"
);
§

type DivOutput = Integer

§

type RemOutput = Integer

§

impl DivRem for Integer

§

fn div_rem(self, other: Integer) -> (Integer, Integer)

Divides an Integer by another Integer, taking both by value and returning the quotient and remainder. The quotient is rounded towards zero and the remainder has the same sign as the first Integer.

The quotient and remainder satisfy $x = qy + r$ and $0 \leq |r| < |y|$.

$$ f(x, y) = \left ( \operatorname{sgn}(xy) \left \lfloor \left | \frac{x}{y} \right | \right \rfloor, \space x - y \operatorname{sgn}(xy) \left \lfloor \left | \frac{x}{y} \right | \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::DivRem;
use malachite_base::strings::ToDebugString;
use malachite_nz::integer::Integer;

// 2 * 10 + 3 = 23
assert_eq!(
    Integer::from(23)
        .div_rem(Integer::from(10))
        .to_debug_string(),
    "(2, 3)"
);

// -2 * -10 + 3 = 23
assert_eq!(
    Integer::from(23)
        .div_rem(Integer::from(-10))
        .to_debug_string(),
    "(-2, 3)"
);

// -2 * 10 + -3 = -23
assert_eq!(
    Integer::from(-23)
        .div_rem(Integer::from(10))
        .to_debug_string(),
    "(-2, -3)"
);

// 2 * -10 + -3 = -23
assert_eq!(
    Integer::from(-23)
        .div_rem(Integer::from(-10))
        .to_debug_string(),
    "(2, -3)"
);
§

type DivOutput = Integer

§

type RemOutput = Integer

§

impl DivRound<&Integer> for &Integer

§

fn div_round(self, other: &Integer, rm: RoundingMode) -> (Integer, Ordering)

Divides an Integer by another Integer, 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}) = \operatorname{sgn}(q) \lfloor |q| \rfloor. $$

$$ g(x, y, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil. $$

$$ g(x, y, \mathrm{Floor}) = \lfloor q \rfloor. $$

$$ 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 & 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 \Z$.

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 core::cmp::Ordering::*;
use malachite_base::num::arithmetic::traits::{DivRound, Pow};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_nz::integer::Integer;

assert_eq!(
    (&Integer::from(-10)).div_round(&Integer::from(4), Down),
    (Integer::from(-2), Greater)
);
assert_eq!(
    (&-Integer::from(10u32).pow(12)).div_round(&Integer::from(3), Floor),
    (Integer::from(-333333333334i64), Less)
);
assert_eq!(
    Integer::from(-10).div_round(&Integer::from(4), Up),
    (Integer::from(-3), Less)
);
assert_eq!(
    (&-Integer::from(10u32).pow(12)).div_round(&Integer::from(3), Ceiling),
    (Integer::from(-333333333333i64), Greater)
);
assert_eq!(
    (&Integer::from(-10)).div_round(&Integer::from(5), Exact),
    (Integer::from(-2), Equal)
);
assert_eq!(
    (&Integer::from(-10)).div_round(&Integer::from(3), Nearest),
    (Integer::from(-3), Greater)
);
assert_eq!(
    (&Integer::from(-20)).div_round(&Integer::from(3), Nearest),
    (Integer::from(-7), Less)
);
assert_eq!(
    (&Integer::from(-10)).div_round(&Integer::from(4), Nearest),
    (Integer::from(-2), Greater)
);
assert_eq!(
    (&Integer::from(-14)).div_round(&Integer::from(4), Nearest),
    (Integer::from(-4), Less)
);

assert_eq!(
    (&Integer::from(-10)).div_round(&Integer::from(-4), Down),
    (Integer::from(2), Less)
);
assert_eq!(
    (&-Integer::from(10u32).pow(12)).div_round(&Integer::from(-3), Floor),
    (Integer::from(333333333333i64), Less)
);
assert_eq!(
    (&Integer::from(-10)).div_round(&Integer::from(-4), Up),
    (Integer::from(3), Greater)
);
assert_eq!(
    (&-Integer::from(10u32).pow(12)).div_round(&Integer::from(-3), Ceiling),
    (Integer::from(333333333334i64), Greater)
);
assert_eq!(
    (&Integer::from(-10)).div_round(&Integer::from(-5), Exact),
    (Integer::from(2), Equal)
);
assert_eq!(
    (&Integer::from(-10)).div_round(&Integer::from(-3), Nearest),
    (Integer::from(3), Less)
);
assert_eq!(
    (&Integer::from(-20)).div_round(&Integer::from(-3), Nearest),
    (Integer::from(7), Greater)
);
assert_eq!(
    (&Integer::from(-10)).div_round(&Integer::from(-4), Nearest),
    (Integer::from(2), Less)
);
assert_eq!(
    (&Integer::from(-14)).div_round(&Integer::from(-4), Nearest),
    (Integer::from(4), Greater)
);
§

type Output = Integer

§

impl DivRound<&Integer> for Integer

§

fn div_round(self, other: &Integer, rm: RoundingMode) -> (Integer, Ordering)

Divides an Integer by another Integer, 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}) = \operatorname{sgn}(q) \lfloor |q| \rfloor. $$

$$ g(x, y, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil. $$

$$ g(x, y, \mathrm{Floor}) = \lfloor q \rfloor. $$

$$ 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 & 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 \Z$.

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 core::cmp::Ordering::*;
use malachite_base::num::arithmetic::traits::{DivRound, Pow};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_nz::integer::Integer;

assert_eq!(
    Integer::from(-10).div_round(&Integer::from(4), Down),
    (Integer::from(-2), Greater)
);
assert_eq!(
    (-Integer::from(10u32).pow(12)).div_round(&Integer::from(3), Floor),
    (Integer::from(-333333333334i64), Less)
);
assert_eq!(
    Integer::from(-10).div_round(&Integer::from(4), Up),
    (Integer::from(-3), Less)
);
assert_eq!(
    (-Integer::from(10u32).pow(12)).div_round(&Integer::from(3), Ceiling),
    (Integer::from(-333333333333i64), Greater)
);
assert_eq!(
    Integer::from(-10).div_round(&Integer::from(5), Exact),
    (Integer::from(-2), Equal)
);
assert_eq!(
    Integer::from(-10).div_round(&Integer::from(3), Nearest),
    (Integer::from(-3), Greater)
);
assert_eq!(
    Integer::from(-20).div_round(&Integer::from(3), Nearest),
    (Integer::from(-7), Less)
);
assert_eq!(
    Integer::from(-10).div_round(&Integer::from(4), Nearest),
    (Integer::from(-2), Greater)
);
assert_eq!(
    Integer::from(-14).div_round(&Integer::from(4), Nearest),
    (Integer::from(-4), Less)
);

assert_eq!(
    Integer::from(-10).div_round(&Integer::from(-4), Down),
    (Integer::from(2), Less)
);
assert_eq!(
    (-Integer::from(10u32).pow(12)).div_round(&Integer::from(-3), Floor),
    (Integer::from(333333333333i64), Less)
);
assert_eq!(
    Integer::from(-10).div_round(&Integer::from(-4), Up),
    (Integer::from(3), Greater)
);
assert_eq!(
    (-Integer::from(10u32).pow(12)).div_round(&Integer::from(-3), Ceiling),
    (Integer::from(333333333334i64), Greater)
);
assert_eq!(
    Integer::from(-10).div_round(&Integer::from(-5), Exact),
    (Integer::from(2), Equal)
);
assert_eq!(
    Integer::from(-10).div_round(&Integer::from(-3), Nearest),
    (Integer::from(3), Less)
);
assert_eq!(
    Integer::from(-20).div_round(&Integer::from(-3), Nearest),
    (Integer::from(7), Greater)
);
assert_eq!(
    Integer::from(-10).div_round(&Integer::from(-4), Nearest),
    (Integer::from(2), Less)
);
assert_eq!(
    Integer::from(-14).div_round(&Integer::from(-4), Nearest),
    (Integer::from(4), Greater)
);
§

type Output = Integer

§

impl DivRound<Integer> for &Integer

§

fn div_round(self, other: Integer, rm: RoundingMode) -> (Integer, Ordering)

Divides an Integer by another Integer, 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}) = \operatorname{sgn}(q) \lfloor |q| \rfloor. $$

$$ g(x, y, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil. $$

$$ g(x, y, \mathrm{Floor}) = \lfloor q \rfloor. $$

$$ 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 & 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 \Z$.

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 core::cmp::Ordering::*;
use malachite_base::num::arithmetic::traits::{DivRound, Pow};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_nz::integer::Integer;

assert_eq!(
    (&Integer::from(-10)).div_round(Integer::from(4), Down),
    (Integer::from(-2), Greater)
);
assert_eq!(
    (&-Integer::from(10u32).pow(12)).div_round(Integer::from(3), Floor),
    (Integer::from(-333333333334i64), Less)
);
assert_eq!(
    Integer::from(-10).div_round(Integer::from(4), Up),
    (Integer::from(-3), Less)
);
assert_eq!(
    (&-Integer::from(10u32).pow(12)).div_round(Integer::from(3), Ceiling),
    (Integer::from(-333333333333i64), Greater)
);
assert_eq!(
    (&Integer::from(-10)).div_round(Integer::from(5), Exact),
    (Integer::from(-2), Equal)
);
assert_eq!(
    (&Integer::from(-10)).div_round(Integer::from(3), Nearest),
    (Integer::from(-3), Greater)
);
assert_eq!(
    (&Integer::from(-20)).div_round(Integer::from(3), Nearest),
    (Integer::from(-7), Less)
);
assert_eq!(
    (&Integer::from(-10)).div_round(Integer::from(4), Nearest),
    (Integer::from(-2), Greater)
);
assert_eq!(
    (&Integer::from(-14)).div_round(Integer::from(4), Nearest),
    (Integer::from(-4), Less)
);

assert_eq!(
    (&Integer::from(-10)).div_round(Integer::from(-4), Down),
    (Integer::from(2), Less)
);
assert_eq!(
    (&-Integer::from(10u32).pow(12)).div_round(Integer::from(-3), Floor),
    (Integer::from(333333333333i64), Less)
);
assert_eq!(
    (&Integer::from(-10)).div_round(Integer::from(-4), Up),
    (Integer::from(3), Greater)
);
assert_eq!(
    (&-Integer::from(10u32).pow(12)).div_round(Integer::from(-3), Ceiling),
    (Integer::from(333333333334i64), Greater)
);
assert_eq!(
    (&Integer::from(-10)).div_round(Integer::from(-5), Exact),
    (Integer::from(2), Equal)
);
assert_eq!(
    (&Integer::from(-10)).div_round(Integer::from(-3), Nearest),
    (Integer::from(3), Less)
);
assert_eq!(
    (&Integer::from(-20)).div_round(Integer::from(-3), Nearest),
    (Integer::from(7), Greater)
);
assert_eq!(
    (&Integer::from(-10)).div_round(Integer::from(-4), Nearest),
    (Integer::from(2), Less)
);
assert_eq!(
    (&Integer::from(-14)).div_round(Integer::from(-4), Nearest),
    (Integer::from(4), Greater)
);
§

type Output = Integer

§

impl DivRound for Integer

§

fn div_round(self, other: Integer, rm: RoundingMode) -> (Integer, Ordering)

Divides an Integer by another Integer, 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}) = \operatorname{sgn}(q) \lfloor |q| \rfloor. $$

$$ g(x, y, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil. $$

$$ g(x, y, \mathrm{Floor}) = \lfloor q \rfloor. $$

$$ 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 & 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 \Z$.

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 core::cmp::Ordering::*;
use malachite_base::num::arithmetic::traits::{DivRound, Pow};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_nz::integer::Integer;

assert_eq!(
    Integer::from(-10).div_round(Integer::from(4), Down),
    (Integer::from(-2), Greater)
);
assert_eq!(
    (-Integer::from(10u32).pow(12)).div_round(Integer::from(3), Floor),
    (Integer::from(-333333333334i64), Less)
);
assert_eq!(
    Integer::from(-10).div_round(Integer::from(4), Up),
    (Integer::from(-3), Less)
);
assert_eq!(
    (-Integer::from(10u32).pow(12)).div_round(Integer::from(3), Ceiling),
    (Integer::from(-333333333333i64), Greater)
);
assert_eq!(
    Integer::from(-10).div_round(Integer::from(5), Exact),
    (Integer::from(-2), Equal)
);
assert_eq!(
    Integer::from(-10).div_round(Integer::from(3), Nearest),
    (Integer::from(-3), Greater)
);
assert_eq!(
    Integer::from(-20).div_round(Integer::from(3), Nearest),
    (Integer::from(-7), Less)
);
assert_eq!(
    Integer::from(-10).div_round(Integer::from(4), Nearest),
    (Integer::from(-2), Greater)
);
assert_eq!(
    Integer::from(-14).div_round(Integer::from(4), Nearest),
    (Integer::from(-4), Less)
);

assert_eq!(
    Integer::from(-10).div_round(Integer::from(-4), Down),
    (Integer::from(2), Less)
);
assert_eq!(
    (-Integer::from(10u32).pow(12)).div_round(Integer::from(-3), Floor),
    (Integer::from(333333333333i64), Less)
);
assert_eq!(
    Integer::from(-10).div_round(Integer::from(-4), Up),
    (Integer::from(3), Greater)
);
assert_eq!(
    (-Integer::from(10u32).pow(12)).div_round(Integer::from(-3), Ceiling),
    (Integer::from(333333333334i64), Greater)
);
assert_eq!(
    Integer::from(-10).div_round(Integer::from(-5), Exact),
    (Integer::from(2), Equal)
);
assert_eq!(
    Integer::from(-10).div_round(Integer::from(-3), Nearest),
    (Integer::from(3), Less)
);
assert_eq!(
    Integer::from(-20).div_round(Integer::from(-3), Nearest),
    (Integer::from(7), Greater)
);
assert_eq!(
    Integer::from(-10).div_round(Integer::from(-4), Nearest),
    (Integer::from(2), Less)
);
assert_eq!(
    Integer::from(-14).div_round(Integer::from(-4), Nearest),
    (Integer::from(4), Greater)
);
§

type Output = Integer

§

impl DivRoundAssign<&Integer> for Integer

§

fn div_round_assign(&mut self, other: &Integer, rm: RoundingMode) -> Ordering

Divides an Integer by another Integer in place, taking the Integer 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 core::cmp::Ordering::*;
use malachite_base::num::arithmetic::traits::{DivRoundAssign, Pow};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_nz::integer::Integer;

let mut n = Integer::from(-10);
assert_eq!(n.div_round_assign(&Integer::from(4), Down), Greater);
assert_eq!(n, -2);

let mut n = -Integer::from(10u32).pow(12);
assert_eq!(n.div_round_assign(&Integer::from(3), Floor), Less);
assert_eq!(n, -333333333334i64);

let mut n = Integer::from(-10);
assert_eq!(n.div_round_assign(&Integer::from(4), Up), Less);
assert_eq!(n, -3);

let mut n = -Integer::from(10u32).pow(12);
assert_eq!(n.div_round_assign(&Integer::from(3), Ceiling), Greater);
assert_eq!(n, -333333333333i64);

let mut n = Integer::from(-10);
assert_eq!(n.div_round_assign(&Integer::from(5), Exact), Equal);
assert_eq!(n, -2);

let mut n = Integer::from(-10);
assert_eq!(n.div_round_assign(&Integer::from(3), Nearest), Greater);
assert_eq!(n, -3);

let mut n = Integer::from(-20);
assert_eq!(n.div_round_assign(&Integer::from(3), Nearest), Less);
assert_eq!(n, -7);

let mut n = Integer::from(-10);
assert_eq!(n.div_round_assign(&Integer::from(4), Nearest), Greater);
assert_eq!(n, -2);

let mut n = Integer::from(-14);
assert_eq!(n.div_round_assign(&Integer::from(4), Nearest), Less);
assert_eq!(n, -4);

let mut n = Integer::from(-10);
assert_eq!(n.div_round_assign(&Integer::from(-4), Down), Less);
assert_eq!(n, 2);

let mut n = -Integer::from(10u32).pow(12);
assert_eq!(n.div_round_assign(&Integer::from(-3), Floor), Less);
assert_eq!(n, 333333333333i64);

let mut n = Integer::from(-10);
assert_eq!(n.div_round_assign(&Integer::from(-4), Up), Greater);
assert_eq!(n, 3);

let mut n = -Integer::from(10u32).pow(12);
assert_eq!(n.div_round_assign(&Integer::from(-3), Ceiling), Greater);
assert_eq!(n, 333333333334i64);

let mut n = Integer::from(-10);
assert_eq!(n.div_round_assign(&Integer::from(-5), Exact), Equal);
assert_eq!(n, 2);

let mut n = Integer::from(-10);
assert_eq!(n.div_round_assign(&Integer::from(-3), Nearest), Less);
assert_eq!(n, 3);

let mut n = Integer::from(-20);
assert_eq!(n.div_round_assign(&Integer::from(-3), Nearest), Greater);
assert_eq!(n, 7);

let mut n = Integer::from(-10);
assert_eq!(n.div_round_assign(&Integer::from(-4), Nearest), Less);
assert_eq!(n, 2);

let mut n = Integer::from(-14);
assert_eq!(n.div_round_assign(&Integer::from(-4), Nearest), Greater);
assert_eq!(n, 4);
§

impl DivRoundAssign for Integer

§

fn div_round_assign(&mut self, other: Integer, rm: RoundingMode) -> Ordering

Divides an Integer by another Integer in place, taking the Integer 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 core::cmp::Ordering::*;
use malachite_base::num::arithmetic::traits::{DivRoundAssign, Pow};
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_nz::integer::Integer;

let mut n = Integer::from(-10);
assert_eq!(n.div_round_assign(Integer::from(4), Down), Greater);
assert_eq!(n, -2);

let mut n = -Integer::from(10u32).pow(12);
assert_eq!(n.div_round_assign(Integer::from(3), Floor), Less);
assert_eq!(n, -333333333334i64);

let mut n = Integer::from(-10);
assert_eq!(n.div_round_assign(Integer::from(4), Up), Less);
assert_eq!(n, -3);

let mut n = -Integer::from(10u32).pow(12);
assert_eq!(n.div_round_assign(Integer::from(3), Ceiling), Greater);
assert_eq!(n, -333333333333i64);

let mut n = Integer::from(-10);
assert_eq!(n.div_round_assign(Integer::from(5), Exact), Equal);
assert_eq!(n, -2);

let mut n = Integer::from(-10);
assert_eq!(n.div_round_assign(Integer::from(3), Nearest), Greater);
assert_eq!(n, -3);

let mut n = Integer::from(-20);
assert_eq!(n.div_round_assign(Integer::from(3), Nearest), Less);
assert_eq!(n, -7);

let mut n = Integer::from(-10);
assert_eq!(n.div_round_assign(Integer::from(4), Nearest), Greater);
assert_eq!(n, -2);

let mut n = Integer::from(-14);
assert_eq!(n.div_round_assign(Integer::from(4), Nearest), Less);
assert_eq!(n, -4);

let mut n = Integer::from(-10);
assert_eq!(n.div_round_assign(Integer::from(-4), Down), Less);
assert_eq!(n, 2);

let mut n = -Integer::from(10u32).pow(12);
assert_eq!(n.div_round_assign(Integer::from(-3), Floor), Less);
assert_eq!(n, 333333333333i64);

let mut n = Integer::from(-10);
assert_eq!(n.div_round_assign(Integer::from(-4), Up), Greater);
assert_eq!(n, 3);

let mut n = -Integer::from(10u32).pow(12);
assert_eq!(n.div_round_assign(Integer::from(-3), Ceiling), Greater);
assert_eq!(n, 333333333334i64);

let mut n = Integer::from(-10);
assert_eq!(n.div_round_assign(Integer::from(-5), Exact), Equal);
assert_eq!(n, 2);

let mut n = Integer::from(-10);
assert_eq!(n.div_round_assign(Integer::from(-3), Nearest), Less);
assert_eq!(n, 3);

let mut n = Integer::from(-20);
assert_eq!(n.div_round_assign(Integer::from(-3), Nearest), Greater);
assert_eq!(n, 7);

let mut n = Integer::from(-10);
assert_eq!(n.div_round_assign(Integer::from(-4), Nearest), Less);
assert_eq!(n, 2);

let mut n = Integer::from(-14);
assert_eq!(n.div_round_assign(Integer::from(-4), Nearest), Greater);
assert_eq!(n, 4);
§

impl DivisibleBy<&Integer> for &Integer

§

fn divisible_by(self, other: &Integer) -> bool

Returns whether an Integer is divisible by another Integer; in other words, whether the first is a multiple of the second. Both Integers are taken by reference.

This means that zero is divisible by any Integer, including zero; but a nonzero Integer 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 core::str::FromStr;
use malachite_base::num::arithmetic::traits::DivisibleBy;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::integer::Integer;

assert_eq!((&Integer::ZERO).divisible_by(&Integer::ZERO), true);
assert_eq!(
    (&Integer::from(-100)).divisible_by(&Integer::from(-3)),
    false
);
assert_eq!((&Integer::from(102)).divisible_by(&Integer::from(-3)), true);
assert_eq!(
    (&Integer::from_str("-1000000000000000000000000").unwrap())
        .divisible_by(&Integer::from_str("1000000000000").unwrap()),
    true
);
§

impl DivisibleBy<&Integer> for Integer

§

fn divisible_by(self, other: &Integer) -> bool

Returns whether an Integer is divisible by another Integer; in other words, whether the first is a multiple of the second. The first Integer is taken by value and the second by reference.

This means that zero is divisible by any Integer, including zero; but a nonzero Integer 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 core::str::FromStr;
use malachite_base::num::arithmetic::traits::DivisibleBy;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::integer::Integer;

assert_eq!(Integer::ZERO.divisible_by(&Integer::ZERO), true);
assert_eq!(Integer::from(-100).divisible_by(&Integer::from(-3)), false);
assert_eq!(Integer::from(102).divisible_by(&Integer::from(-3)), true);
assert_eq!(
    Integer::from_str("-1000000000000000000000000")
        .unwrap()
        .divisible_by(&Integer::from_str("1000000000000").unwrap()),
    true
);
§

impl DivisibleBy<Integer> for &Integer

§

fn divisible_by(self, other: Integer) -> bool

Returns whether an Integer is divisible by another Integer; in other words, whether the first is a multiple of the second. The first Integer is taken by reference and the second by value.

This means that zero is divisible by any Integer, including zero; but a nonzero Integer 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 core::str::FromStr;
use malachite_base::num::arithmetic::traits::DivisibleBy;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::integer::Integer;

assert_eq!((&Integer::ZERO).divisible_by(Integer::ZERO), true);
assert_eq!(
    (&Integer::from(-100)).divisible_by(Integer::from(-3)),
    false
);
assert_eq!((&Integer::from(102)).divisible_by(Integer::from(-3)), true);
assert_eq!(
    (&Integer::from_str("-1000000000000000000000000").unwrap())
        .divisible_by(Integer::from_str("1000000000000").unwrap()),
    true
);
§

impl DivisibleBy for Integer

§

fn divisible_by(self, other: Integer) -> bool

Returns whether an Integer is divisible by another Integer; in other words, whether the first is a multiple of the second. Both Integers are taken by value.

This means that zero is divisible by any Integer, including zero; but a nonzero Integer 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 core::str::FromStr;
use malachite_base::num::arithmetic::traits::DivisibleBy;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::integer::Integer;

assert_eq!(Integer::ZERO.divisible_by(Integer::ZERO), true);
assert_eq!(Integer::from(-100).divisible_by(Integer::from(-3)), false);
assert_eq!(Integer::from(102).divisible_by(Integer::from(-3)), true);
assert_eq!(
    Integer::from_str("-1000000000000000000000000")
        .unwrap()
        .divisible_by(Integer::from_str("1000000000000").unwrap()),
    true
);
§

impl DivisibleByPowerOf2 for &Integer

§

fn divisible_by_power_of_2(self, pow: u64) -> bool

Returns whether an Integer 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::integer::Integer;

assert_eq!(Integer::ZERO.divisible_by_power_of_2(100), true);
assert_eq!(Integer::from(-100).divisible_by_power_of_2(2), true);
assert_eq!(Integer::from(100u32).divisible_by_power_of_2(3), false);
assert_eq!(
    (-Integer::from(10u32).pow(12)).divisible_by_power_of_2(12),
    true
);
assert_eq!(
    (-Integer::from(10u32).pow(12)).divisible_by_power_of_2(13),
    false
);
§

impl EqAbs<Integer> for Natural

§

fn eq_abs(&self, other: &Integer) -> bool

Determines whether the absolute values of an Integer and a Natural are equal.

§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::EqAbs;
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;

assert_eq!(Natural::from(122u32).eq_abs(&Integer::from(-123)), false);
assert_eq!(Natural::from(124u32).eq_abs(&Integer::from(-123)), false);
assert_eq!(Natural::from(123u32).eq_abs(&Integer::from(123)), true);
assert_eq!(Natural::from(123u32).eq_abs(&Integer::from(-123)), true);
§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
§

impl EqAbs<Integer> for u32

§

fn eq_abs(&self, other: &Integer) -> bool

Determines whether the absolute values of a primitive unsigned integer and an Integer are equal.

§Worst-case complexity

Constant time and additional memory.

See here.

§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
§

impl EqAbs<Natural> for Integer

§

fn eq_abs(&self, other: &Natural) -> bool

Determines whether the absolute values of an Integer and a Natural are equal.

§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::EqAbs;
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;

assert_eq!(Integer::from(-123).eq_abs(&Natural::from(122u32)), false);
assert_eq!(Integer::from(-123).eq_abs(&Natural::from(124u32)), false);
assert_eq!(Integer::from(123).eq_abs(&Natural::from(123u32)), true);
assert_eq!(Integer::from(-123).eq_abs(&Natural::from(123u32)), true);
§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
§

impl EqAbs<Rational> for Integer

§

fn eq_abs(&self, other: &Rational) -> bool

Determines whether the absolute values of a [Rational] and an Integer are equal.

§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::EqAbs;
use malachite_nz::integer::Integer;
use malachite_q::Rational;

assert_eq!(Integer::from(122).eq_abs(&Rational::from(-123)), false);
assert_eq!(Integer::from(124).eq_abs(&Rational::from(-123)), false);
assert_eq!(
    Integer::from(124).eq_abs(&Rational::from_signeds(22, 7)),
    false
);
assert_eq!(
    Integer::from(124).eq_abs(&Rational::from_signeds(-22, 7)),
    false
);
assert_eq!(Integer::from(123).eq_abs(&Rational::from(123)), true);
assert_eq!(Integer::from(123).eq_abs(&Rational::from(-123)), true);
assert_eq!(
    Integer::from(123).eq_abs(&Rational::from_signeds(22, 7)),
    false
);
assert_eq!(
    Integer::from(123).eq_abs(&Rational::from_signeds(-22, 7)),
    false
);
assert_eq!(Integer::from(-122).eq_abs(&Rational::from(-123)), false);
assert_eq!(Integer::from(-124).eq_abs(&Rational::from(-123)), false);
assert_eq!(
    Integer::from(-124).eq_abs(&Rational::from_signeds(22, 7)),
    false
);
assert_eq!(
    Integer::from(-124).eq_abs(&Rational::from_signeds(-22, 7)),
    false
);
assert_eq!(Integer::from(-123).eq_abs(&Rational::from(123)), true);
assert_eq!(Integer::from(-123).eq_abs(&Rational::from(-123)), true);
assert_eq!(
    Integer::from(-123).eq_abs(&Rational::from_signeds(22, 7)),
    false
);
assert_eq!(
    Integer::from(-123).eq_abs(&Rational::from_signeds(-22, 7)),
    false
);
§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
§

impl EqAbs<f32> for Integer

§

fn eq_abs(&self, other: &f32) -> bool

Determines whether the absolute values of an Integer and a primitive float are equal.

§Worst-case complexity

Constant time and additional memory.

See here.

§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
§

impl EqAbs<f64> for Integer

§

fn eq_abs(&self, other: &f64) -> bool

Determines whether the absolute values of an Integer and a primitive float are equal.

§Worst-case complexity

Constant time and additional memory.

See here.

§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
§

impl EqAbs<i128> for Integer

§

fn eq_abs(&self, other: &i128) -> bool

Determines whether the absolute values of an Integer and a primitive signed integer are equal.

§Worst-case complexity

Constant time and additional memory.

See here.

§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
§

impl EqAbs<i16> for Integer

§

fn eq_abs(&self, other: &i16) -> bool

Determines whether the absolute values of an Integer and a primitive signed integer are equal.

§Worst-case complexity

Constant time and additional memory.

See here.

§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
§

impl EqAbs<i32> for Integer

§

fn eq_abs(&self, other: &i32) -> bool

Determines whether the absolute values of an Integer and a primitive signed integer are equal.

§Worst-case complexity

Constant time and additional memory.

See here.

§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
§

impl EqAbs<i64> for Integer

§

fn eq_abs(&self, other: &i64) -> bool

Determines whether the absolute values of an Integer and a primitive signed integer are equal.

§Worst-case complexity

Constant time and additional memory.

See here.

§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
§

impl EqAbs<i8> for Integer

§

fn eq_abs(&self, other: &i8) -> bool

Determines whether the absolute values of an Integer and a primitive signed integer are equal.

§Worst-case complexity

Constant time and additional memory.

See here.

§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
§

impl EqAbs<isize> for Integer

§

fn eq_abs(&self, other: &isize) -> bool

Determines whether the absolute values of an Integer and a primitive signed integer are equal.

§Worst-case complexity

Constant time and additional memory.

See here.

§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
§

impl EqAbs<u128> for Integer

§

fn eq_abs(&self, other: &u128) -> bool

Determines whether the absolute values of an Integer and a primitive unsigned integer are equal.

§Worst-case complexity

Constant time and additional memory.

See here.

§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
§

impl EqAbs<u16> for Integer

§

fn eq_abs(&self, other: &u16) -> bool

Determines whether the absolute values of an Integer and a primitive unsigned integer are equal.

§Worst-case complexity

Constant time and additional memory.

See here.

§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
§

impl EqAbs<u32> for Integer

§

fn eq_abs(&self, other: &u32) -> bool

Determines whether the absolute values of an Integer and a primitive unsigned integer are equal.

§Worst-case complexity

Constant time and additional memory.

See here.

§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
§

impl EqAbs<u64> for Integer

§

fn eq_abs(&self, other: &u64) -> bool

Determines whether the absolute values of an Integer and a primitive unsigned integer are equal.

§Worst-case complexity

Constant time and additional memory.

See here.

§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
§

impl EqAbs<u8> for Integer

§

fn eq_abs(&self, other: &u8) -> bool

Determines whether the absolute values of an Integer and a primitive unsigned integer are equal.

§Worst-case complexity

Constant time and additional memory.

See here.

§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
§

impl EqAbs<usize> for Integer

§

fn eq_abs(&self, other: &usize) -> bool

Determines whether the absolute values of an Integer and a primitive unsigned integer are equal.

§Worst-case complexity

Constant time and additional memory.

See here.

§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
§

impl EqAbs for Integer

§

fn eq_abs(&self, other: &Integer) -> bool

Determines whether the absolute values of two Integers are equal.

§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::EqAbs;
use malachite_nz::integer::Integer;

assert_eq!(Integer::from(-123).eq_abs(&Integer::from(-122)), false);
assert_eq!(Integer::from(-123).eq_abs(&Integer::from(-124)), false);
assert_eq!(Integer::from(123).eq_abs(&Integer::from(123)), true);
assert_eq!(Integer::from(123).eq_abs(&Integer::from(-123)), true);
assert_eq!(Integer::from(-123).eq_abs(&Integer::from(123)), true);
assert_eq!(Integer::from(-123).eq_abs(&Integer::from(-123)), true);
§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
§

impl EqMod<&Integer, &Natural> for &Integer

§

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 Integers is a multiple of the Natural. All three numbers are taken by reference.

Two Integers 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 core::str::FromStr;
use malachite_base::num::arithmetic::traits::EqMod;
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;

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
);
§

impl EqMod<&Integer, &Natural> for Integer

§

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 Integers is a multiple of the Natural. The first number is taken by value and the second and third by reference.

Two Integers 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 core::str::FromStr;
use malachite_base::num::arithmetic::traits::EqMod;
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;

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
);
§

impl EqMod<&Integer, Natural> for &Integer

§

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 Integers is a multiple of the Natural. The first two numbers are taken by reference and the third by value.

Two Integers 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 core::str::FromStr;
use malachite_base::num::arithmetic::traits::EqMod;
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;

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
);
§

impl EqMod<&Integer, Natural> for Integer

§

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 Integers is a multiple of the Natural. The first and third numbers are taken by value and the second by reference.

Two Integers 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 core::str::FromStr;
use malachite_base::num::arithmetic::traits::EqMod;
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;

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
);
§

impl EqMod<Integer, &Natural> for &Integer

§

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 Integers is a multiple of the Natural. The first and third numbers are taken by reference and the third by value.

Two Integers 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 core::str::FromStr;
use malachite_base::num::arithmetic::traits::EqMod;
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;

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
);
§

impl EqMod<Integer, &Natural> for Integer

§

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 Integers is a multiple of the Natural. The first two numbers are taken by value and the third by reference.

Two Integers 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 core::str::FromStr;
use malachite_base::num::arithmetic::traits::EqMod;
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;

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
);
§

impl EqMod<Integer, Natural> for &Integer

§

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 Integers is a multiple of the Natural. The first number is taken by reference and the second and third by value.

Two Integers 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 core::str::FromStr;
use malachite_base::num::arithmetic::traits::EqMod;
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;

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
);
§

impl EqMod<Integer, Natural> for Integer

§

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 Integers is a multiple of the Natural. All three numbers are taken by value.

Two Integers 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 core::str::FromStr;
use malachite_base::num::arithmetic::traits::EqMod;
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;

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
);
§

impl EqModPowerOf2<&Integer> for &Integer

§

fn eq_mod_power_of_2(self, other: &Integer, pow: u64) -> bool

Returns whether one Integer is equal to another modulo $2^k$; that is, whether their $k$ least-significant bits (in two’s complement) 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::integer::Integer;

assert_eq!(
    Integer::ZERO.eq_mod_power_of_2(&Integer::from(-256), 8),
    true
);
assert_eq!(
    Integer::from(-0b1101).eq_mod_power_of_2(&Integer::from(0b11011), 3),
    true
);
assert_eq!(
    Integer::from(-0b1101).eq_mod_power_of_2(&Integer::from(0b11011), 4),
    false
);
§

impl ExtendedGcd<&Integer> for &Integer

§

fn extended_gcd(self, other: &Integer) -> (Natural, Integer, Integer)

Computes the GCD (greatest common divisor) of two Integers $a$ and $b$, and also the coefficients $x$ and $y$ in Bézout’s identity $ax+by=\gcd(a,b)$. Both Integers 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(a, ak) = (-a, -1, 0)$ if $a < 0$ and $k \neq 1$.
  • $f(bk, b) = (b, 0, 1)$ if $b > 0$.
  • $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::integer::Integer;

assert_eq!(
    (&Integer::from(3))
        .extended_gcd(&Integer::from(5))
        .to_debug_string(),
    "(1, 2, -1)"
);
assert_eq!(
    (&Integer::from(240))
        .extended_gcd(&Integer::from(46))
        .to_debug_string(),
    "(2, -9, 47)"
);
assert_eq!(
    (&Integer::from(-111))
        .extended_gcd(&Integer::from(300))
        .to_debug_string(),
    "(3, 27, 10)"
);
§

type Gcd = Natural

§

type Cofactor = Integer

§

impl ExtendedGcd<&Integer> for Integer

§

fn extended_gcd(self, other: &Integer) -> (Natural, Integer, Integer)

Computes the GCD (greatest common divisor) of two Integers $a$ and $b$, and also the coefficients $x$ and $y$ in Bézout’s identity $ax+by=\gcd(a,b)$. The first Integer 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(a, ak) = (-a, -1, 0)$ if $a < 0$ and $k \neq 1$.
  • $f(bk, b) = (b, 0, 1)$ if $b > 0$.
  • $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::integer::Integer;

assert_eq!(
    Integer::from(3)
        .extended_gcd(&Integer::from(5))
        .to_debug_string(),
    "(1, 2, -1)"
);
assert_eq!(
    Integer::from(240)
        .extended_gcd(&Integer::from(46))
        .to_debug_string(),
    "(2, -9, 47)"
);
assert_eq!(
    Integer::from(-111)
        .extended_gcd(&Integer::from(300))
        .to_debug_string(),
    "(3, 27, 10)"
);
§

type Gcd = Natural

§

type Cofactor = Integer

§

impl ExtendedGcd<Integer> for &Integer

§

fn extended_gcd(self, other: Integer) -> (Natural, Integer, Integer)

Computes the GCD (greatest common divisor) of two Integers $a$ and $b$, and also the coefficients $x$ and $y$ in Bézout’s identity $ax+by=\gcd(a,b)$. The first Integer 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(a, ak) = (-a, -1, 0)$ if $a < 0$ and $k \neq 1$.
  • $f(bk, b) = (b, 0, 1)$ if $b > 0$.
  • $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::integer::Integer;

assert_eq!(
    (&Integer::from(3))
        .extended_gcd(Integer::from(5))
        .to_debug_string(),
    "(1, 2, -1)"
);
assert_eq!(
    (&Integer::from(240))
        .extended_gcd(Integer::from(46))
        .to_debug_string(),
    "(2, -9, 47)"
);
assert_eq!(
    (&Integer::from(-111))
        .extended_gcd(Integer::from(300))
        .to_debug_string(),
    "(3, 27, 10)"
);
§

type Gcd = Natural

§

type Cofactor = Integer

§

impl ExtendedGcd for Integer

§

fn extended_gcd(self, other: Integer) -> (Natural, Integer, Integer)

Computes the GCD (greatest common divisor) of two Integers $a$ and $b$, and also the coefficients $x$ and $y$ in Bézout’s identity $ax+by=\gcd(a,b)$. Both Integers 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(a, ak) = (-a, -1, 0)$ if $a < 0$ and $k \neq 1$.
  • $f(bk, b) = (b, 0, 1)$ if $b > 0$.
  • $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::integer::Integer;

assert_eq!(
    Integer::from(3)
        .extended_gcd(Integer::from(5))
        .to_debug_string(),
    "(1, 2, -1)"
);
assert_eq!(
    Integer::from(240)
        .extended_gcd(Integer::from(46))
        .to_debug_string(),
    "(2, -9, 47)"
);
assert_eq!(
    Integer::from(-111)
        .extended_gcd(Integer::from(300))
        .to_debug_string(),
    "(3, 27, 10)"
);
§

type Gcd = Natural

§

type Cofactor = Integer

§

impl FloorRoot<u64> for &Integer

§

fn floor_root(self, exp: u64) -> Integer

Returns the floor of the $n$th root of an Integer, taking the Integer 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, or if exp is even and self is negative.

§Examples
use malachite_base::num::arithmetic::traits::FloorRoot;
use malachite_nz::integer::Integer;

assert_eq!((&Integer::from(999)).floor_root(3), 9);
assert_eq!((&Integer::from(1000)).floor_root(3), 10);
assert_eq!((&Integer::from(1001)).floor_root(3), 10);
assert_eq!((&Integer::from(100000000000i64)).floor_root(5), 158);
assert_eq!((&Integer::from(-100000000000i64)).floor_root(5), -159);
§

type Output = Integer

§

impl FloorRoot<u64> for Integer

§

fn floor_root(self, exp: u64) -> Integer

Returns the floor of the $n$th root of an Integer, taking the Integer 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, or if exp is even and self is negative.

§Examples
use malachite_base::num::arithmetic::traits::FloorRoot;
use malachite_nz::integer::Integer;

assert_eq!(Integer::from(999).floor_root(3), 9);
assert_eq!(Integer::from(1000).floor_root(3), 10);
assert_eq!(Integer::from(1001).floor_root(3), 10);
assert_eq!(Integer::from(100000000000i64).floor_root(5), 158);
assert_eq!(Integer::from(-100000000000i64).floor_root(5), -159);
§

type Output = Integer

§

impl FloorRootAssign<u64> for Integer

§

fn floor_root_assign(&mut self, exp: u64)

Replaces an Integer 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, or if exp is even and self is negative.

§Examples
use malachite_base::num::arithmetic::traits::FloorRootAssign;
use malachite_nz::integer::Integer;

let mut x = Integer::from(999);
x.floor_root_assign(3);
assert_eq!(x, 9);

let mut x = Integer::from(1000);
x.floor_root_assign(3);
assert_eq!(x, 10);

let mut x = Integer::from(1001);
x.floor_root_assign(3);
assert_eq!(x, 10);

let mut x = Integer::from(100000000000i64);
x.floor_root_assign(5);
assert_eq!(x, 158);

let mut x = Integer::from(-100000000000i64);
x.floor_root_assign(5);
assert_eq!(x, -159);
§

impl FloorSqrt for &Integer

§

fn floor_sqrt(self) -> Integer

Returns the floor of the square root of an Integer, taking it by reference.

$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().

§Panics

Panics if self is negative.

§Examples
use malachite_base::num::arithmetic::traits::FloorSqrt;
use malachite_nz::integer::Integer;

assert_eq!((&Integer::from(99)).floor_sqrt(), 9);
assert_eq!((&Integer::from(100)).floor_sqrt(), 10);
assert_eq!((&Integer::from(101)).floor_sqrt(), 10);
assert_eq!((&Integer::from(1000000000)).floor_sqrt(), 31622);
assert_eq!((&Integer::from(10000000000u64)).floor_sqrt(), 100000);
§

type Output = Integer

§

impl FloorSqrt for Integer

§

fn floor_sqrt(self) -> Integer

Returns the floor of the square root of an Integer, 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().

§Panics

Panics if self is negative.

§Examples
use malachite_base::num::arithmetic::traits::FloorSqrt;
use malachite_nz::integer::Integer;

assert_eq!(Integer::from(99).floor_sqrt(), 9);
assert_eq!(Integer::from(100).floor_sqrt(), 10);
assert_eq!(Integer::from(101).floor_sqrt(), 10);
assert_eq!(Integer::from(1000000000).floor_sqrt(), 31622);
assert_eq!(Integer::from(10000000000u64).floor_sqrt(), 100000);
§

type Output = Integer

§

impl FloorSqrtAssign for Integer

§

fn floor_sqrt_assign(&mut self)

Replaces an Integer 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().

§Panics

Panics if self is negative.

§Examples
use malachite_base::num::arithmetic::traits::FloorSqrtAssign;
use malachite_nz::integer::Integer;

let mut x = Integer::from(99);
x.floor_sqrt_assign();
assert_eq!(x, 9);

let mut x = Integer::from(100);
x.floor_sqrt_assign();
assert_eq!(x, 10);

let mut x = Integer::from(101);
x.floor_sqrt_assign();
assert_eq!(x, 10);

let mut x = Integer::from(1000000000);
x.floor_sqrt_assign();
assert_eq!(x, 31622);

let mut x = Integer::from(10000000000u64);
x.floor_sqrt_assign();
assert_eq!(x, 100000);
§

impl<'a> From<&'a Natural> for 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
);
§

impl From<Natural> for 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
);
§

impl From<bool> for Integer

§

fn from(b: bool) -> Integer

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::integer::Integer;

assert_eq!(Integer::from(false), 0);
assert_eq!(Integer::from(true), 1);
§

impl From<i128> for Integer

§

fn from(i: i128) -> Integer

Converts a signed primitive integer to an Integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

impl From<i16> for Integer

§

fn from(i: i16) -> Integer

Converts a signed primitive integer to an Integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

impl From<i32> for Integer

§

fn from(i: i32) -> Integer

Converts a signed primitive integer to an Integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

impl From<i64> for Integer

§

fn from(i: i64) -> Integer

Converts a signed primitive integer to an Integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

impl From<i8> for Integer

§

fn from(i: i8) -> Integer

Converts a signed primitive integer to an Integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

impl From<isize> for Integer

§

fn from(i: isize) -> Integer

Converts a signed primitive integer to an Integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

impl From<u128> for Integer

§

fn from(u: u128) -> Integer

Converts an unsigned primitive integer to an Integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

impl From<u16> for Integer

§

fn from(u: u16) -> Integer

Converts an unsigned primitive integer to an Integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

impl From<u32> for Integer

§

fn from(u: u32) -> Integer

Converts an unsigned primitive integer to an Integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

impl From<u64> for Integer

§

fn from(u: u64) -> Integer

Converts an unsigned primitive integer to an Integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

impl From<u8> for Integer

§

fn from(u: u8) -> Integer

Converts an unsigned primitive integer to an Integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

impl From<usize> for Integer

§

fn from(u: usize) -> Integer

Converts an unsigned primitive integer to an Integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

impl FromSciString for Integer

§

fn from_sci_string_with_options( s: &str, options: FromSciStringOptions, ) -> Option<Integer>

Converts a string, possibly in scientfic notation, to an Integer.

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::integer::Integer;

assert_eq!(Integer::from_sci_string("123").unwrap(), 123);
assert_eq!(Integer::from_sci_string("123.5").unwrap(), 124);
assert_eq!(Integer::from_sci_string("-123.5").unwrap(), -124);
assert_eq!(Integer::from_sci_string("1.23e10").unwrap(), 12300000000i64);

let mut options = FromSciStringOptions::default();
assert_eq!(
    Integer::from_sci_string_with_options("123.5", options).unwrap(),
    124
);

options.set_rounding_mode(Floor);
assert_eq!(
    Integer::from_sci_string_with_options("123.5", options).unwrap(),
    123
);

options = FromSciStringOptions::default();
options.set_base(16);
assert_eq!(
    Integer::from_sci_string_with_options("ff", options).unwrap(),
    255
);
§

fn from_sci_string(s: &str) -> Option<Self>

Converts a &str, possibly in scientific notation, to a number, using the default [FromSciStringOptions].
§

impl FromStr for Integer

§

fn from_str(s: &str) -> Result<Integer, ()>

Converts an string to an Integer.

If the string does not represent a valid Integer, an Err is returned. To be valid, the string must be nonempty and only contain the chars '0' through '9', with an optional leading '-'. Leading zeros are allowed, as is the string "-0". The string "-" is not.

§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 core::str::FromStr;
use malachite_nz::integer::Integer;

assert_eq!(Integer::from_str("123456").unwrap(), 123456);
assert_eq!(Integer::from_str("00123456").unwrap(), 123456);
assert_eq!(Integer::from_str("0").unwrap(), 0);
assert_eq!(Integer::from_str("-123456").unwrap(), -123456);
assert_eq!(Integer::from_str("-00123456").unwrap(), -123456);
assert_eq!(Integer::from_str("-0").unwrap(), 0);

assert!(Integer::from_str("").is_err());
assert!(Integer::from_str("a").is_err());
§

type Err = ()

The associated error which can be returned from parsing.
§

impl FromStringBase for Integer

§

fn from_string_base(base: u8, s: &str) -> Option<Integer>

Converts an string, in a specified base, to an Integer.

If the string does not represent a valid Integer, an Err is returned. To be valid, the string must be nonempty and only contain the chars '0' through '9', 'a' through 'z', and 'A' through 'Z', with an optional single leading '-' or '+'; and only characters that represent digits smaller than the base are allowed. Leading zeros are allowed, as is the string "-0". The string "-" is not.

§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::FromStringBase;
use malachite_nz::integer::Integer;

assert_eq!(Integer::from_string_base(10, "123456").unwrap(), 123456);
assert_eq!(Integer::from_string_base(10, "00123456").unwrap(), 123456);
assert_eq!(Integer::from_string_base(16, "0").unwrap(), 0);
assert_eq!(
    Integer::from_string_base(16, "deadbeef").unwrap(),
    3735928559i64
);
assert_eq!(
    Integer::from_string_base(16, "deAdBeEf").unwrap(),
    3735928559i64
);
assert_eq!(Integer::from_string_base(10, "-123456").unwrap(), -123456);
assert_eq!(Integer::from_string_base(10, "-00123456").unwrap(), -123456);
assert_eq!(Integer::from_string_base(16, "-0").unwrap(), 0);
assert_eq!(
    Integer::from_string_base(16, "-deadbeef").unwrap(),
    -3735928559i64
);
assert_eq!(
    Integer::from_string_base(16, "-deAdBeEf").unwrap(),
    -3735928559i64
);

assert!(Integer::from_string_base(10, "").is_none());
assert!(Integer::from_string_base(10, "a").is_none());
assert!(Integer::from_string_base(2, "2").is_none());
assert!(Integer::from_string_base(2, "-2").is_none());
§

impl Hash for Integer

§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
§

impl IsInteger for &Integer

§

fn is_integer(self) -> bool

Determines whether an Integer 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::{NegativeOne, One, Zero};
use malachite_base::num::conversion::traits::IsInteger;
use malachite_nz::integer::Integer;

assert_eq!(Integer::ZERO.is_integer(), true);
assert_eq!(Integer::ONE.is_integer(), true);
assert_eq!(Integer::from(100).is_integer(), true);
assert_eq!(Integer::NEGATIVE_ONE.is_integer(), true);
assert_eq!(Integer::from(-100).is_integer(), true);
§

impl JacobiSymbol<&Integer> for &Integer

§

fn jacobi_symbol(self, other: &Integer) -> i8

Computes the Jacobi symbol of two Integers, 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 self is negative or if other is even.

§Examples
use malachite_base::num::arithmetic::traits::JacobiSymbol;
use malachite_nz::integer::Integer;

assert_eq!((&Integer::from(10)).jacobi_symbol(&Integer::from(5)), 0);
assert_eq!((&Integer::from(7)).jacobi_symbol(&Integer::from(5)), -1);
assert_eq!((&Integer::from(11)).jacobi_symbol(&Integer::from(5)), 1);
assert_eq!((&Integer::from(11)).jacobi_symbol(&Integer::from(9)), 1);
assert_eq!((&Integer::from(-7)).jacobi_symbol(&Integer::from(5)), -1);
assert_eq!((&Integer::from(-11)).jacobi_symbol(&Integer::from(5)), 1);
assert_eq!((&Integer::from(-11)).jacobi_symbol(&Integer::from(9)), 1);
§

impl JacobiSymbol<&Integer> for Integer

§

fn jacobi_symbol(self, other: &Integer) -> i8

Computes the Jacobi symbol of two Integers, 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 self is negative or if other is even.

§Examples
use malachite_base::num::arithmetic::traits::JacobiSymbol;
use malachite_nz::integer::Integer;

assert_eq!(Integer::from(10).jacobi_symbol(&Integer::from(5)), 0);
assert_eq!(Integer::from(7).jacobi_symbol(&Integer::from(5)), -1);
assert_eq!(Integer::from(11).jacobi_symbol(&Integer::from(5)), 1);
assert_eq!(Integer::from(11).jacobi_symbol(&Integer::from(9)), 1);
assert_eq!(Integer::from(-7).jacobi_symbol(&Integer::from(5)), -1);
assert_eq!(Integer::from(-11).jacobi_symbol(&Integer::from(5)), 1);
assert_eq!(Integer::from(-11).jacobi_symbol(&Integer::from(9)), 1);
§

impl JacobiSymbol<Integer> for &Integer

§

fn jacobi_symbol(self, other: Integer) -> i8

Computes the Jacobi symbol of two Integers, 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 self is negative or if other is even.

§Examples
use malachite_base::num::arithmetic::traits::JacobiSymbol;
use malachite_nz::integer::Integer;

assert_eq!((&Integer::from(10)).jacobi_symbol(Integer::from(5)), 0);
assert_eq!((&Integer::from(7)).jacobi_symbol(Integer::from(5)), -1);
assert_eq!((&Integer::from(11)).jacobi_symbol(Integer::from(5)), 1);
assert_eq!((&Integer::from(11)).jacobi_symbol(Integer::from(9)), 1);
assert_eq!((&Integer::from(-7)).jacobi_symbol(Integer::from(5)), -1);
assert_eq!((&Integer::from(-11)).jacobi_symbol(Integer::from(5)), 1);
assert_eq!((&Integer::from(-11)).jacobi_symbol(Integer::from(9)), 1);
§

impl JacobiSymbol for Integer

§

fn jacobi_symbol(self, other: Integer) -> i8

Computes the Jacobi symbol of two Integers, 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 self is negative or if other is even.

§Examples
use malachite_base::num::arithmetic::traits::JacobiSymbol;
use malachite_nz::integer::Integer;

assert_eq!(Integer::from(10).jacobi_symbol(Integer::from(5)), 0);
assert_eq!(Integer::from(7).jacobi_symbol(Integer::from(5)), -1);
assert_eq!(Integer::from(11).jacobi_symbol(Integer::from(5)), 1);
assert_eq!(Integer::from(11).jacobi_symbol(Integer::from(9)), 1);
assert_eq!(Integer::from(-7).jacobi_symbol(Integer::from(5)), -1);
assert_eq!(Integer::from(-11).jacobi_symbol(Integer::from(5)), 1);
assert_eq!(Integer::from(-11).jacobi_symbol(Integer::from(9)), 1);
§

impl KroneckerSymbol<&Integer> for &Integer

§

fn kronecker_symbol(self, other: &Integer) -> i8

Computes the Kronecker symbol of two Integers, 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::integer::Integer;

assert_eq!((&Integer::from(10)).kronecker_symbol(&Integer::from(5)), 0);
assert_eq!((&Integer::from(7)).kronecker_symbol(&Integer::from(5)), -1);
assert_eq!((&Integer::from(11)).kronecker_symbol(&Integer::from(5)), 1);
assert_eq!((&Integer::from(11)).kronecker_symbol(&Integer::from(9)), 1);
assert_eq!((&Integer::from(11)).kronecker_symbol(&Integer::from(8)), -1);
assert_eq!((&Integer::from(-7)).kronecker_symbol(&Integer::from(5)), -1);
assert_eq!((&Integer::from(-11)).kronecker_symbol(&Integer::from(5)), 1);
assert_eq!((&Integer::from(-11)).kronecker_symbol(&Integer::from(9)), 1);
assert_eq!(
    (&Integer::from(-11)).kronecker_symbol(&Integer::from(8)),
    -1
);
assert_eq!(
    (&Integer::from(-11)).kronecker_symbol(&Integer::from(-8)),
    1
);
§

impl KroneckerSymbol<&Integer> for Integer

§

fn kronecker_symbol(self, other: &Integer) -> i8

Computes the Kronecker symbol of two Integers, 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::integer::Integer;

assert_eq!(Integer::from(10).kronecker_symbol(&Integer::from(5)), 0);
assert_eq!(Integer::from(7).kronecker_symbol(&Integer::from(5)), -1);
assert_eq!(Integer::from(11).kronecker_symbol(&Integer::from(5)), 1);
assert_eq!(Integer::from(11).kronecker_symbol(&Integer::from(9)), 1);
assert_eq!(Integer::from(11).kronecker_symbol(&Integer::from(8)), -1);
assert_eq!(Integer::from(-7).kronecker_symbol(&Integer::from(5)), -1);
assert_eq!(Integer::from(-11).kronecker_symbol(&Integer::from(5)), 1);
assert_eq!(Integer::from(-11).kronecker_symbol(&Integer::from(9)), 1);
assert_eq!(Integer::from(-11).kronecker_symbol(&Integer::from(8)), -1);
assert_eq!(Integer::from(-11).kronecker_symbol(&Integer::from(-8)), 1);
§

impl KroneckerSymbol<Integer> for &Integer

§

fn kronecker_symbol(self, other: Integer) -> i8

Computes the Kronecker symbol of two Integers, taking the first by reference and the second 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::integer::Integer;

assert_eq!((&Integer::from(10)).kronecker_symbol(Integer::from(5)), 0);
assert_eq!((&Integer::from(7)).kronecker_symbol(Integer::from(5)), -1);
assert_eq!((&Integer::from(11)).kronecker_symbol(Integer::from(5)), 1);
assert_eq!((&Integer::from(11)).kronecker_symbol(Integer::from(9)), 1);
assert_eq!((&Integer::from(11)).kronecker_symbol(Integer::from(8)), -1);
assert_eq!((&Integer::from(-7)).kronecker_symbol(Integer::from(5)), -1);
assert_eq!((&Integer::from(-11)).kronecker_symbol(Integer::from(5)), 1);
assert_eq!((&Integer::from(-11)).kronecker_symbol(Integer::from(9)), 1);
assert_eq!((&Integer::from(-11)).kronecker_symbol(Integer::from(8)), -1);
assert_eq!((&Integer::from(-11)).kronecker_symbol(Integer::from(-8)), 1);
§

impl KroneckerSymbol for Integer

§

fn kronecker_symbol(self, other: Integer) -> i8

Computes the Kronecker symbol of two Integers, 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::integer::Integer;

assert_eq!(Integer::from(10).kronecker_symbol(Integer::from(5)), 0);
assert_eq!(Integer::from(7).kronecker_symbol(Integer::from(5)), -1);
assert_eq!(Integer::from(11).kronecker_symbol(Integer::from(5)), 1);
assert_eq!(Integer::from(11).kronecker_symbol(Integer::from(9)), 1);
assert_eq!(Integer::from(11).kronecker_symbol(Integer::from(8)), -1);
assert_eq!(Integer::from(-7).kronecker_symbol(Integer::from(5)), -1);
assert_eq!(Integer::from(-11).kronecker_symbol(Integer::from(5)), 1);
assert_eq!(Integer::from(-11).kronecker_symbol(Integer::from(9)), 1);
assert_eq!(Integer::from(-11).kronecker_symbol(Integer::from(8)), -1);
assert_eq!(Integer::from(-11).kronecker_symbol(Integer::from(-8)), 1);
§

impl LegendreSymbol<&Integer> for &Integer

§

fn legendre_symbol(self, other: &Integer) -> i8

Computes the Legendre symbol of two Integers, 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 self is negative or if other is even.

§Examples
use malachite_base::num::arithmetic::traits::LegendreSymbol;
use malachite_nz::integer::Integer;

assert_eq!((&Integer::from(10)).legendre_symbol(&Integer::from(5)), 0);
assert_eq!((&Integer::from(7)).legendre_symbol(&Integer::from(5)), -1);
assert_eq!((&Integer::from(11)).legendre_symbol(&Integer::from(5)), 1);
assert_eq!((&Integer::from(-7)).legendre_symbol(&Integer::from(5)), -1);
assert_eq!((&Integer::from(-11)).legendre_symbol(&Integer::from(5)), 1);
§

impl LegendreSymbol<&Integer> for Integer

§

fn legendre_symbol(self, other: &Integer) -> i8

Computes the Legendre symbol of two Integers, 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 self is negative or if other is even.

§Examples
use malachite_base::num::arithmetic::traits::LegendreSymbol;
use malachite_nz::integer::Integer;

assert_eq!(Integer::from(10).legendre_symbol(&Integer::from(5)), 0);
assert_eq!(Integer::from(7).legendre_symbol(&Integer::from(5)), -1);
assert_eq!(Integer::from(11).legendre_symbol(&Integer::from(5)), 1);
assert_eq!(Integer::from(-7).legendre_symbol(&Integer::from(5)), -1);
assert_eq!(Integer::from(-11).legendre_symbol(&Integer::from(5)), 1);
§

impl LegendreSymbol<Integer> for &Integer

§

fn legendre_symbol(self, other: Integer) -> i8

Computes the Legendre symbol of two Integers, taking 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 self is negative or if other is even.

§Examples
use malachite_base::num::arithmetic::traits::LegendreSymbol;
use malachite_nz::integer::Integer;

assert_eq!((&Integer::from(10)).legendre_symbol(Integer::from(5)), 0);
assert_eq!((&Integer::from(7)).legendre_symbol(Integer::from(5)), -1);
assert_eq!((&Integer::from(11)).legendre_symbol(Integer::from(5)), 1);
assert_eq!((&Integer::from(-7)).legendre_symbol(Integer::from(5)), -1);
assert_eq!((&Integer::from(-11)).legendre_symbol(Integer::from(5)), 1);
§

impl LegendreSymbol for Integer

§

fn legendre_symbol(self, other: Integer) -> i8

Computes the Legendre symbol of two Integers, 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 self is negative or if other is even.

§Examples
use malachite_base::num::arithmetic::traits::LegendreSymbol;
use malachite_nz::integer::Integer;

assert_eq!(Integer::from(10).legendre_symbol(Integer::from(5)), 0);
assert_eq!(Integer::from(7).legendre_symbol(Integer::from(5)), -1);
assert_eq!(Integer::from(11).legendre_symbol(Integer::from(5)), 1);
assert_eq!(Integer::from(-7).legendre_symbol(Integer::from(5)), -1);
assert_eq!(Integer::from(-11).legendre_symbol(Integer::from(5)), 1);
§

impl LowMask for Integer

§

fn low_mask(bits: u64) -> Integer

Returns an Integer 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::integer::Integer;

assert_eq!(Integer::low_mask(0), 0);
assert_eq!(Integer::low_mask(3), 7);
assert_eq!(
    Integer::low_mask(100).to_string(),
    "1267650600228229401496703205375"
);
§

impl LowerHex for Integer

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Converts an Integer 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 core::str::FromStr;
use malachite_base::num::basic::traits::Zero;
use malachite_base::strings::ToLowerHexString;
use malachite_nz::integer::Integer;

assert_eq!(Integer::ZERO.to_lower_hex_string(), "0");
assert_eq!(Integer::from(123).to_lower_hex_string(), "7b");
assert_eq!(
    Integer::from_str("1000000000000")
        .unwrap()
        .to_lower_hex_string(),
    "e8d4a51000"
);
assert_eq!(format!("{:07x}", Integer::from(123)), "000007b");
assert_eq!(Integer::from(-123).to_lower_hex_string(), "-7b");
assert_eq!(
    Integer::from_str("-1000000000000")
        .unwrap()
        .to_lower_hex_string(),
    "-e8d4a51000"
);
assert_eq!(format!("{:07x}", Integer::from(-123)), "-00007b");

assert_eq!(format!("{:#x}", Integer::ZERO), "0x0");
assert_eq!(format!("{:#x}", Integer::from(123)), "0x7b");
assert_eq!(
    format!("{:#x}", Integer::from_str("1000000000000").unwrap()),
    "0xe8d4a51000"
);
assert_eq!(format!("{:#07x}", Integer::from(123)), "0x0007b");
assert_eq!(format!("{:#x}", Integer::from(-123)), "-0x7b");
assert_eq!(
    format!("{:#x}", Integer::from_str("-1000000000000").unwrap()),
    "-0xe8d4a51000"
);
assert_eq!(format!("{:#07x}", Integer::from(-123)), "-0x007b");
§

impl Mod<&Integer> for &Integer

§

fn mod_op(self, other: &Integer) -> Integer

Divides an Integer by another Integer, taking both by reference and returning just the remainder. The remainder has the same sign as the second Integer.

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::integer::Integer;

// 2 * 10 + 3 = 23
assert_eq!((&Integer::from(23)).mod_op(&Integer::from(10)), 3);

// -3 * -10 + -7 = 23
assert_eq!((&Integer::from(23)).mod_op(&Integer::from(-10)), -7);

// -3 * 10 + 7 = -23
assert_eq!((&Integer::from(-23)).mod_op(&Integer::from(10)), 7);

// 2 * -10 + -3 = -23
assert_eq!((&Integer::from(-23)).mod_op(&Integer::from(-10)), -3);
§

type Output = Integer

§

impl Mod<&Integer> for Integer

§

fn mod_op(self, other: &Integer) -> Integer

Divides an Integer by another Integer, taking the first by value and the second by reference and returning just the remainder. The remainder has the same sign as the second Integer.

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::integer::Integer;

// 2 * 10 + 3 = 23
assert_eq!(Integer::from(23).mod_op(&Integer::from(10)), 3);

// -3 * -10 + -7 = 23
assert_eq!(Integer::from(23).mod_op(&Integer::from(-10)), -7);

// -3 * 10 + 7 = -23
assert_eq!(Integer::from(-23).mod_op(&Integer::from(10)), 7);

// 2 * -10 + -3 = -23
assert_eq!(Integer::from(-23).mod_op(&Integer::from(-10)), -3);
§

type Output = Integer

§

impl Mod<Integer> for &Integer

§

fn mod_op(self, other: Integer) -> Integer

Divides an Integer by another Integer, taking the first by reference and the second by value and returning just the remainder. The remainder has the same sign as the second Integer.

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::integer::Integer;

// 2 * 10 + 3 = 23
assert_eq!((&Integer::from(23)).mod_op(Integer::from(10)), 3);

// -3 * -10 + -7 = 23
assert_eq!((&Integer::from(23)).mod_op(Integer::from(-10)), -7);

// -3 * 10 + 7 = -23
assert_eq!((&Integer::from(-23)).mod_op(Integer::from(10)), 7);

// 2 * -10 + -3 = -23
assert_eq!((&Integer::from(-23)).mod_op(Integer::from(-10)), -3);
§

type Output = Integer

§

impl Mod for Integer

§

fn mod_op(self, other: Integer) -> Integer

Divides an Integer by another Integer, taking both by value and returning just the remainder. The remainder has the same sign as the second Integer.

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::integer::Integer;

// 2 * 10 + 3 = 23
assert_eq!(Integer::from(23).mod_op(Integer::from(10)), 3);

// -3 * -10 + -7 = 23
assert_eq!(Integer::from(23).mod_op(Integer::from(-10)), -7);

// -3 * 10 + 7 = -23
assert_eq!(Integer::from(-23).mod_op(Integer::from(10)), 7);

// 2 * -10 + -3 = -23
assert_eq!(Integer::from(-23).mod_op(Integer::from(-10)), -3);
§

type Output = Integer

§

impl ModAssign<&Integer> for Integer

§

fn mod_assign(&mut self, other: &Integer)

Divides an Integer by another Integer, taking the second Integer by reference and replacing the first by the remainder. The remainder has the same sign as the second Integer.

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::integer::Integer;

// 2 * 10 + 3 = 23
let mut x = Integer::from(23);
x.mod_assign(&Integer::from(10));
assert_eq!(x, 3);

// -3 * -10 + -7 = 23
let mut x = Integer::from(23);
x.mod_assign(&Integer::from(-10));
assert_eq!(x, -7);

// -3 * 10 + 7 = -23
let mut x = Integer::from(-23);
x.mod_assign(&Integer::from(10));
assert_eq!(x, 7);

// 2 * -10 + -3 = -23
let mut x = Integer::from(-23);
x.mod_assign(&Integer::from(-10));
assert_eq!(x, -3);
§

impl ModAssign for Integer

§

fn mod_assign(&mut self, other: Integer)

Divides an Integer by another Integer, taking the second Integer by value and replacing the first by the remainder. The remainder has the same sign as the second Integer.

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::integer::Integer;

// 2 * 10 + 3 = 23
let mut x = Integer::from(23);
x.mod_assign(Integer::from(10));
assert_eq!(x, 3);

// -3 * -10 + -7 = 23
let mut x = Integer::from(23);
x.mod_assign(Integer::from(-10));
assert_eq!(x, -7);

// -3 * 10 + 7 = -23
let mut x = Integer::from(-23);
x.mod_assign(Integer::from(10));
assert_eq!(x, 7);

// 2 * -10 + -3 = -23
let mut x = Integer::from(-23);
x.mod_assign(Integer::from(-10));
assert_eq!(x, -3);
§

impl ModPowerOf2 for &Integer

§

fn mod_power_of_2(self, pow: u64) -> Natural

Divides an Integer by $2^k$, taking it by reference and returning just the remainder. The remainder is non-negative.

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. $$

Unlike rem_power_of_2, this function always returns a non-negative number.

§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::integer::Integer;

// 1 * 2^8 + 4 = 260
assert_eq!((&Integer::from(260)).mod_power_of_2(8), 4);
// -101 * 2^4 + 5 = -1611
assert_eq!((&Integer::from(-1611)).mod_power_of_2(4), 5);
§

type Output = Natural

§

impl ModPowerOf2 for Integer

§

fn mod_power_of_2(self, pow: u64) -> Natural

Divides an Integer by $2^k$, taking it by value and returning just the remainder. The remainder is non-negative.

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. $$

Unlike rem_power_of_2, this function always returns a non-negative number.

§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::integer::Integer;

// 1 * 2^8 + 4 = 260
assert_eq!(Integer::from(260).mod_power_of_2(8), 4);

// -101 * 2^4 + 5 = -1611
assert_eq!(Integer::from(-1611).mod_power_of_2(4), 5);
§

type Output = Natural

§

impl ModPowerOf2Assign for Integer

§

fn mod_power_of_2_assign(&mut self, pow: u64)

Divides an Integer by $2^k$, replacing the Integer by the remainder. The remainder is non-negative.

If the quotient were computed, he 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. $$

Unlike rem_power_of_2_assign, this function always assigns a non-negative number.

§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::ModPowerOf2Assign;
use malachite_nz::integer::Integer;

// 1 * 2^8 + 4 = 260
let mut x = Integer::from(260);
x.mod_power_of_2_assign(8);
assert_eq!(x, 4);

// -101 * 2^4 + 5 = -1611
let mut x = Integer::from(-1611);
x.mod_power_of_2_assign(4);
assert_eq!(x, 5);
§

impl Mul<&Integer> for &Integer

§

fn mul(self, other: &Integer) -> Integer

Multiplies two Integers, 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::integer::Integer;

assert_eq!(&Integer::ONE * &Integer::from(123), 123);
assert_eq!(&Integer::from(123) * &Integer::ZERO, 0);
assert_eq!(&Integer::from(123) * &Integer::from(-456), -56088);
assert_eq!(
    (&Integer::from(-123456789000i64) * &Integer::from(-987654321000i64)).to_string(),
    "121932631112635269000000"
);
§

type Output = Integer

The resulting type after applying the * operator.
§

impl Mul<&Integer> for Integer

§

fn mul(self, other: &Integer) -> Integer

Multiplies two Integers, 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::integer::Integer;

assert_eq!(Integer::ONE * &Integer::from(123), 123);
assert_eq!(Integer::from(123) * &Integer::ZERO, 0);
assert_eq!(Integer::from(123) * &Integer::from(-456), -56088);
assert_eq!(
    (Integer::from(-123456789000i64) * &Integer::from(-987654321000i64)).to_string(),
    "121932631112635269000000"
);
§

type Output = Integer

The resulting type after applying the * operator.
§

impl Mul<Integer> for &Integer

§

fn mul(self, other: Integer) -> Integer

Multiplies two Integers, 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::integer::Integer;

assert_eq!(&Integer::ONE * Integer::from(123), 123);
assert_eq!(&Integer::from(123) * Integer::ZERO, 0);
assert_eq!(&Integer::from(123) * Integer::from(-456), -56088);
assert_eq!(
    (&Integer::from(-123456789000i64) * Integer::from(-987654321000i64)).to_string(),
    "121932631112635269000000"
);
§

type Output = Integer

The resulting type after applying the * operator.
§

impl Mul for Integer

§

fn mul(self, other: Integer) -> Integer

Multiplies two Integers, 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::integer::Integer;

assert_eq!(Integer::ONE * Integer::from(123), 123);
assert_eq!(Integer::from(123) * Integer::ZERO, 0);
assert_eq!(Integer::from(123) * Integer::from(-456), -56088);
assert_eq!(
    (Integer::from(-123456789000i64) * Integer::from(-987654321000i64)).to_string(),
    "121932631112635269000000"
);
§

type Output = Integer

The resulting type after applying the * operator.
§

impl MulAssign<&Integer> for Integer

§

fn mul_assign(&mut self, other: &Integer)

Multiplies an Integer by an Integer in place, taking the Integer 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::NegativeOne;
use malachite_nz::integer::Integer;

let mut x = Integer::NEGATIVE_ONE;
x *= &Integer::from(1000);
x *= &Integer::from(2000);
x *= &Integer::from(3000);
x *= &Integer::from(4000);
assert_eq!(x, -24000000000000i64);
§

impl MulAssign for Integer

§

fn mul_assign(&mut self, other: Integer)

Multiplies an Integer by an Integer in place, taking the Integer 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::NegativeOne;
use malachite_nz::integer::Integer;

let mut x = Integer::NEGATIVE_ONE;
x *= Integer::from(1000);
x *= Integer::from(2000);
x *= Integer::from(3000);
x *= Integer::from(4000);
assert_eq!(x, -24000000000000i64);
§

impl Named for Integer

§

const NAME: &'static str = "Integer"

The name of this type, as given by the stringify macro.

See the documentation for [impl_named] for more details.

§

impl Neg for &Integer

§

fn neg(self) -> Integer

Negates an Integer, taking it by reference.

$$ 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::integer::Integer;

assert_eq!(-&Integer::ZERO, 0);
assert_eq!(-&Integer::from(123), -123);
assert_eq!(-&Integer::from(-123), 123);
§

type Output = Integer

The resulting type after applying the - operator.
§

impl Neg for Integer

§

fn neg(self) -> Integer

Negates an Integer, taking it by value.

$$ f(x) = -x. $$

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_nz::integer::Integer;

assert_eq!(-Integer::ZERO, 0);
assert_eq!(-Integer::from(123), -123);
assert_eq!(-Integer::from(-123), 123);
§

type Output = Integer

The resulting type after applying the - operator.
§

impl NegAssign for Integer

§

fn neg_assign(&mut self)

Negates an Integer in place.

$$ x \gets -x. $$

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::num::arithmetic::traits::NegAssign;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::integer::Integer;

let mut x = Integer::ZERO;
x.neg_assign();
assert_eq!(x, 0);

let mut x = Integer::from(123);
x.neg_assign();
assert_eq!(x, -123);

let mut x = Integer::from(-123);
x.neg_assign();
assert_eq!(x, 123);
§

impl NegativeOne for Integer

The constant -1.

§

impl Not for &Integer

§

fn not(self) -> Integer

Returns the bitwise negation of an Integer, taking it by reference.

$$ 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::integer::Integer;

assert_eq!(!&Integer::ZERO, -1);
assert_eq!(!&Integer::from(123), -124);
assert_eq!(!&Integer::from(-123), 122);
§

type Output = Integer

The resulting type after applying the ! operator.
§

impl Not for Integer

§

fn not(self) -> Integer

Returns the bitwise negation of an Integer, taking it by value.

$$ 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::integer::Integer;

assert_eq!(!Integer::ZERO, -1);
assert_eq!(!Integer::from(123), -124);
assert_eq!(!Integer::from(-123), 122);
§

type Output = Integer

The resulting type after applying the ! operator.
§

impl NotAssign for Integer

§

fn not_assign(&mut self)

Replaces an Integer with its bitwise negation.

$$ n \gets -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_base::num::logic::traits::NotAssign;
use malachite_nz::integer::Integer;

let mut x = Integer::ZERO;
x.not_assign();
assert_eq!(x, -1);

let mut x = Integer::from(123);
x.not_assign();
assert_eq!(x, -124);

let mut x = Integer::from(-123);
x.not_assign();
assert_eq!(x, 122);
§

impl Octal for Integer

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Converts an Integer 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 core::str::FromStr;
use malachite_base::num::basic::traits::Zero;
use malachite_base::strings::ToOctalString;
use malachite_nz::integer::Integer;

assert_eq!(Integer::ZERO.to_octal_string(), "0");
assert_eq!(Integer::from(123).to_octal_string(), "173");
assert_eq!(
    Integer::from_str("1000000000000")
        .unwrap()
        .to_octal_string(),
    "16432451210000"
);
assert_eq!(format!("{:07o}", Integer::from(123)), "0000173");
assert_eq!(Integer::from(-123).to_octal_string(), "-173");
assert_eq!(
    Integer::from_str("-1000000000000")
        .unwrap()
        .to_octal_string(),
    "-16432451210000"
);
assert_eq!(format!("{:07o}", Integer::from(-123)), "-000173");

assert_eq!(format!("{:#o}", Integer::ZERO), "0o0");
assert_eq!(format!("{:#o}", Integer::from(123)), "0o173");
assert_eq!(
    format!("{:#o}", Integer::from_str("1000000000000").unwrap()),
    "0o16432451210000"
);
assert_eq!(format!("{:#07o}", Integer::from(123)), "0o00173");
assert_eq!(format!("{:#o}", Integer::from(-123)), "-0o173");
assert_eq!(
    format!("{:#o}", Integer::from_str("-1000000000000").unwrap()),
    "-0o16432451210000"
);
assert_eq!(format!("{:#07o}", Integer::from(-123)), "-0o0173");
§

impl One for Integer

The constant 1.

§

const ONE: Integer

§

impl Ord for Integer

§

fn cmp(&self, other: &Integer) -> Ordering

Compares two Integers.

§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::integer::Integer;

assert!(Integer::from(-123) < Integer::from(-122));
assert!(Integer::from(-123) <= Integer::from(-122));
assert!(Integer::from(-123) > Integer::from(-124));
assert!(Integer::from(-123) >= Integer::from(-124));
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
§

impl OrdAbs for Integer

§

fn cmp_abs(&self, other: &Integer) -> Ordering

Compares the absolute values of two Integers.

§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;

assert!(Integer::from(-123).lt_abs(&Integer::from(-124)));
assert!(Integer::from(-123).le_abs(&Integer::from(-124)));
assert!(Integer::from(-124).gt_abs(&Integer::from(-123)));
assert!(Integer::from(-124).ge_abs(&Integer::from(-123)));
§

impl<'a> OverflowingFrom<&'a Integer> for u32

§

fn overflowing_from(value: &Integer) -> (u32, bool)

Converts an Integer to an unsigned primitive integer, wrapping modulo $2^W$, where $W$ is the width of the primitive integer.

The returned boolean value indicates whether wrapping occurred.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

impl Parity for &Integer

§

fn even(self) -> bool

Tests whether an Integer 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::integer::Integer;

assert_eq!(Integer::ZERO.even(), true);
assert_eq!(Integer::from(123).even(), false);
assert_eq!(Integer::from(-0x80).even(), true);
assert_eq!(Integer::from(10u32).pow(12).even(), true);
assert_eq!((-Integer::from(10u32).pow(12) - Integer::ONE).even(), false);
§

fn odd(self) -> bool

Tests whether an Integer 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::integer::Integer;

assert_eq!(Integer::ZERO.odd(), false);
assert_eq!(Integer::from(123).odd(), true);
assert_eq!(Integer::from(-0x80).odd(), false);
assert_eq!(Integer::from(10u32).pow(12).odd(), false);
assert_eq!((-Integer::from(10u32).pow(12) - Integer::ONE).odd(), true);
§

impl PartialEq<Integer> for Natural

§

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));
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl PartialEq<Integer> for u32

§

fn eq(&self, other: &Integer) -> bool

Determines whether an unsigned primitive integer is equal to an Integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl PartialEq<Natural> for Integer

§

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));
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl PartialEq<Rational> for Integer

§

fn eq(&self, other: &Rational) -> bool

Determines whether an Integer is equal to a [Rational].

§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::integer::Integer;
use malachite_q::Rational;

assert!(Integer::from(-123) == Rational::from(-123));
assert!(Integer::from(5) != Rational::from_signeds(22, 7));
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl PartialEq<f32> for Integer

§

fn eq(&self, other: &f32) -> bool

Determines whether an Integer is equal to a primitive float.

§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.

1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl PartialEq<f64> for Integer

§

fn eq(&self, other: &f64) -> bool

Determines whether an Integer is equal to a primitive float.

§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.

1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl PartialEq<i128> for Integer

§

fn eq(&self, other: &i128) -> bool

Determines whether an Integer is equal to a signed primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl PartialEq<i16> for Integer

§

fn eq(&self, other: &i16) -> bool

Determines whether an Integer is equal to a signed primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl PartialEq<i32> for Integer

§

fn eq(&self, other: &i32) -> bool

Determines whether an Integer is equal to a signed primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl PartialEq<i64> for Integer

§

fn eq(&self, other: &i64) -> bool

Determines whether an Integer is equal to a signed primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl PartialEq<i8> for Integer

§

fn eq(&self, other: &i8) -> bool

Determines whether an Integer is equal to a signed primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl PartialEq<isize> for Integer

§

fn eq(&self, other: &isize) -> bool

Determines whether an Integer is equal to a signed primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl PartialEq<u128> for Integer

§

fn eq(&self, other: &u128) -> bool

Determines whether an Integer is equal to an unsigned primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl PartialEq<u16> for Integer

§

fn eq(&self, other: &u16) -> bool

Determines whether an Integer is equal to an unsigned primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl PartialEq<u32> for Integer

§

fn eq(&self, other: &u32) -> bool

Determines whether an Integer is equal to an unsigned primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl PartialEq<u64> for Integer

§

fn eq(&self, other: &u64) -> bool

Determines whether an Integer is equal to an unsigned primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl PartialEq<u8> for Integer

§

fn eq(&self, other: &u8) -> bool

Determines whether an Integer is equal to an unsigned primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl PartialEq<usize> for Integer

§

fn eq(&self, other: &usize) -> bool

Determines whether an Integer is equal to an unsigned primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl PartialEq for Integer

§

fn eq(&self, other: &Integer) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl PartialOrd<Integer> for Natural

§

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 lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl PartialOrd<Integer> for u32

§

fn partial_cmp(&self, other: &Integer) -> Option<Ordering>

Compares an unsigned primitive integer to an Integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl PartialOrd<Natural> for Integer

§

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 lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl PartialOrd<Rational> for Integer

§

fn partial_cmp(&self, other: &Rational) -> Option<Ordering>

Compares an Integer to a [Rational].

§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_nz::integer::Integer;
use malachite_q::Rational;

assert!(Integer::from(3) < Rational::from_signeds(22, 7));
assert!(Integer::from(4) > Rational::from_signeds(22, 7));
assert!(Integer::from(-3) > Rational::from_signeds(-22, 7));
assert!(Integer::from(-4) < Rational::from_signeds(-22, 7));
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl PartialOrd<f32> for Integer

§

fn partial_cmp(&self, other: &f32) -> Option<Ordering>

Compares an Integer to a primitive float.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where n = self.significant_bits().

§Examples

See here.

1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl PartialOrd<f64> for Integer

§

fn partial_cmp(&self, other: &f64) -> Option<Ordering>

Compares an Integer to a primitive float.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where n = self.significant_bits().

§Examples

See here.

1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl PartialOrd<i128> for Integer

§

fn partial_cmp(&self, other: &i128) -> Option<Ordering>

Compares an Integer to a signed primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl PartialOrd<i16> for Integer

§

fn partial_cmp(&self, other: &i16) -> Option<Ordering>

Compares an Integer to a signed primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl PartialOrd<i32> for Integer

§

fn partial_cmp(&self, other: &i32) -> Option<Ordering>

Compares an Integer to a signed primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl PartialOrd<i64> for Integer

§

fn partial_cmp(&self, other: &i64) -> Option<Ordering>

Compares an Integer to a signed primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl PartialOrd<i8> for Integer

§

fn partial_cmp(&self, other: &i8) -> Option<Ordering>

Compares an Integer to a signed primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl PartialOrd<isize> for Integer

§

fn partial_cmp(&self, other: &isize) -> Option<Ordering>

Compares an Integer to a signed primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl PartialOrd<u128> for Integer

§

fn partial_cmp(&self, other: &u128) -> Option<Ordering>

Compares an Integer to an unsigned primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl PartialOrd<u16> for Integer

§

fn partial_cmp(&self, other: &u16) -> Option<Ordering>

Compares an Integer to an unsigned primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl PartialOrd<u32> for Integer

§

fn partial_cmp(&self, other: &u32) -> Option<Ordering>

Compares an Integer to an unsigned primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl PartialOrd<u64> for Integer

§

fn partial_cmp(&self, other: &u64) -> Option<Ordering>

Compares an Integer to an unsigned primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl PartialOrd<u8> for Integer

§

fn partial_cmp(&self, other: &u8) -> Option<Ordering>

Compares an Integer to an unsigned primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl PartialOrd<usize> for Integer

§

fn partial_cmp(&self, other: &usize) -> Option<Ordering>

Compares an Integer to an unsigned primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl PartialOrd for Integer

§

fn partial_cmp(&self, other: &Integer) -> Option<Ordering>

Compares two Integers.

See the documentation for the Ord implementation.

1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl PartialOrdAbs<Integer> for Natural

§

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)));
§

fn lt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than the absolute value of another. Read more
§

fn le_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
§

fn gt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
§

fn ge_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
§

impl PartialOrdAbs<Integer> for u32

§

fn partial_cmp_abs(&self, other: &Integer) -> Option<Ordering>

Compares the absolute values of an unsigned primitive integer and an Integer.

§Worst-case complexity

Constant time and additional memory.

See here.

§

fn lt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than the absolute value of another. Read more
§

fn le_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
§

fn gt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
§

fn ge_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
§

impl PartialOrdAbs<Natural> for Integer

§

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)));
§

fn lt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than the absolute value of another. Read more
§

fn le_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
§

fn gt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
§

fn ge_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
§

impl PartialOrdAbs<Rational> for Integer

§

fn partial_cmp_abs(&self, other: &Rational) -> Option<Ordering>

Compares the absolute values of an Integer and a [Rational].

§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::comparison::traits::PartialOrdAbs;
use malachite_nz::integer::Integer;
use malachite_q::Rational;
use std::cmp::Ordering::*;

assert_eq!(
    Integer::from(3).partial_cmp_abs(&Rational::from_signeds(22, 7)),
    Some(Less)
);
assert_eq!(
    Integer::from(-3).partial_cmp_abs(&Rational::from_signeds(-22, 7)),
    Some(Less)
);
§

fn lt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than the absolute value of another. Read more
§

fn le_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
§

fn gt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
§

fn ge_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
§

impl PartialOrdAbs<f32> for Integer

§

fn partial_cmp_abs(&self, other: &f32) -> Option<Ordering>

Compares the absolute values of an Integer and a primitive float.

§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.

§

fn lt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than the absolute value of another. Read more
§

fn le_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
§

fn gt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
§

fn ge_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
§

impl PartialOrdAbs<f64> for Integer

§

fn partial_cmp_abs(&self, other: &f64) -> Option<Ordering>

Compares the absolute values of an Integer and a primitive float.

§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.

§

fn lt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than the absolute value of another. Read more
§

fn le_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
§

fn gt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
§

fn ge_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
§

impl PartialOrdAbs<i128> for Integer

§

fn partial_cmp_abs(&self, other: &i128) -> Option<Ordering>

Compares the absolute values of an Integer and a signed primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

fn lt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than the absolute value of another. Read more
§

fn le_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
§

fn gt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
§

fn ge_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
§

impl PartialOrdAbs<i16> for Integer

§

fn partial_cmp_abs(&self, other: &i16) -> Option<Ordering>

Compares the absolute values of an Integer and a signed primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

fn lt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than the absolute value of another. Read more
§

fn le_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
§

fn gt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
§

fn ge_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
§

impl PartialOrdAbs<i32> for Integer

§

fn partial_cmp_abs(&self, other: &i32) -> Option<Ordering>

Compares the absolute values of an Integer and a signed primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

fn lt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than the absolute value of another. Read more
§

fn le_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
§

fn gt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
§

fn ge_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
§

impl PartialOrdAbs<i64> for Integer

§

fn partial_cmp_abs(&self, other: &i64) -> Option<Ordering>

Compares the absolute values of an Integer and a signed primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

fn lt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than the absolute value of another. Read more
§

fn le_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
§

fn gt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
§

fn ge_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
§

impl PartialOrdAbs<i8> for Integer

§

fn partial_cmp_abs(&self, other: &i8) -> Option<Ordering>

Compares the absolute values of an Integer and a signed primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

fn lt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than the absolute value of another. Read more
§

fn le_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
§

fn gt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
§

fn ge_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
§

impl PartialOrdAbs<isize> for Integer

§

fn partial_cmp_abs(&self, other: &isize) -> Option<Ordering>

Compares the absolute values of an Integer and a signed primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

fn lt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than the absolute value of another. Read more
§

fn le_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
§

fn gt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
§

fn ge_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
§

impl PartialOrdAbs<u128> for Integer

§

fn partial_cmp_abs(&self, other: &u128) -> Option<Ordering>

Compares the absolute values of an Integer and an unsigned primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

fn lt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than the absolute value of another. Read more
§

fn le_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
§

fn gt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
§

fn ge_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
§

impl PartialOrdAbs<u16> for Integer

§

fn partial_cmp_abs(&self, other: &u16) -> Option<Ordering>

Compares the absolute values of an Integer and an unsigned primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

fn lt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than the absolute value of another. Read more
§

fn le_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
§

fn gt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
§

fn ge_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
§

impl PartialOrdAbs<u32> for Integer

§

fn partial_cmp_abs(&self, other: &u32) -> Option<Ordering>

Compares the absolute values of an Integer and an unsigned primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

fn lt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than the absolute value of another. Read more
§

fn le_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
§

fn gt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
§

fn ge_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
§

impl PartialOrdAbs<u64> for Integer

§

fn partial_cmp_abs(&self, other: &u64) -> Option<Ordering>

Compares the absolute values of an Integer and an unsigned primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

fn lt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than the absolute value of another. Read more
§

fn le_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
§

fn gt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
§

fn ge_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
§

impl PartialOrdAbs<u8> for Integer

§

fn partial_cmp_abs(&self, other: &u8) -> Option<Ordering>

Compares the absolute values of an Integer and an unsigned primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

fn lt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than the absolute value of another. Read more
§

fn le_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
§

fn gt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
§

fn ge_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
§

impl PartialOrdAbs<usize> for Integer

§

fn partial_cmp_abs(&self, other: &usize) -> Option<Ordering>

Compares the absolute values of an Integer and an unsigned primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

fn lt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than the absolute value of another. Read more
§

fn le_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
§

fn gt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
§

fn ge_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
§

impl PartialOrdAbs for Integer

§

fn partial_cmp_abs(&self, other: &Integer) -> Option<Ordering>

Compares the absolute values of two Integers.

See the documentation for the [OrdAbs] implementation.

§

fn lt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than the absolute value of another. Read more
§

fn le_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is less than or equal to the absolute value of another. Read more
§

fn gt_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than the absolute value of another. Read more
§

fn ge_abs(&self, other: &Rhs) -> bool

Determines whether the absolute value of one number is greater than or equal to the absolute value of another. Read more
§

impl Pow<u64> for &Integer

§

fn pow(self, exp: u64) -> Integer

Raises an Integer to a power, taking the Integer 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 core::str::FromStr;
use malachite_base::num::arithmetic::traits::Pow;
use malachite_nz::integer::Integer;

assert_eq!(
    (&Integer::from(-3)).pow(100).to_string(),
    "515377520732011331036461129765621272702107522001"
);
assert_eq!(
    (&Integer::from_str("-12345678987654321").unwrap())
        .pow(3)
        .to_string(),
    "-1881676411868862234942354805142998028003108518161"
);
§

type Output = Integer

§

impl Pow<u64> for Integer

§

fn pow(self, exp: u64) -> Integer

Raises an Integer to a power, taking the Integer 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 core::str::FromStr;
use malachite_base::num::arithmetic::traits::Pow;
use malachite_nz::integer::Integer;

assert_eq!(
    Integer::from(-3).pow(100).to_string(),
    "515377520732011331036461129765621272702107522001"
);
assert_eq!(
    Integer::from_str("-12345678987654321")
        .unwrap()
        .pow(3)
        .to_string(),
    "-1881676411868862234942354805142998028003108518161"
);
§

type Output = Integer

§

impl PowAssign<u64> for Integer

§

fn pow_assign(&mut self, exp: u64)

Raises an Integer 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 core::str::FromStr;
use malachite_base::num::arithmetic::traits::PowAssign;
use malachite_nz::integer::Integer;

let mut x = Integer::from(-3);
x.pow_assign(100);
assert_eq!(
    x.to_string(),
    "515377520732011331036461129765621272702107522001"
);

let mut x = Integer::from_str("-12345678987654321").unwrap();
x.pow_assign(3);
assert_eq!(
    x.to_string(),
    "-1881676411868862234942354805142998028003108518161"
);
§

impl PowerOf2<u64> for Integer

§

fn power_of_2(pow: u64) -> Integer

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::integer::Integer;

assert_eq!(Integer::power_of_2(0), 1);
assert_eq!(Integer::power_of_2(3), 8);
assert_eq!(
    Integer::power_of_2(100).to_string(),
    "1267650600228229401496703205376"
);
§

impl<'a> Product<&'a Integer> for Integer

§

fn product<I>(xs: I) -> Integer
where I: Iterator<Item = &'a Integer>,

Multiplies together all the Integers in an iterator of Integer 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 Integer::sum(xs.map(Integer::significant_bits)).

§Examples
use core::iter::Product;
use malachite_base::vecs::vec_from_str;
use malachite_nz::integer::Integer;

assert_eq!(
    Integer::product(vec_from_str::<Integer>("[2, -3, 5, 7]").unwrap().iter()),
    -210
);
§

impl Product for Integer

§

fn product<I>(xs: I) -> Integer
where I: Iterator<Item = Integer>,

Multiplies together all the Integers 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 Integer::sum(xs.map(Integer::significant_bits)).

§Examples
use core::iter::Product;
use malachite_base::vecs::vec_from_str;
use malachite_nz::integer::Integer;

assert_eq!(
    Integer::product(
        vec_from_str::<Integer>("[2, -3, 5, 7]")
            .unwrap()
            .into_iter()
    ),
    -210
);
§

impl Rem<&Integer> for &Integer

§

fn rem(self, other: &Integer) -> Integer

Divides an Integer by another Integer, taking both by reference and returning just the remainder. The remainder has the same sign as the first Integer.

If the quotient were computed, the quotient and remainder would satisfy $x = qy + r$ and $0 \leq |r| < |y|$.

$$ f(x, y) = x - y \operatorname{sgn}(xy) \left \lfloor \left | \frac{x}{y} \right | \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::integer::Integer;

// 2 * 10 + 3 = 23
assert_eq!(&Integer::from(23) % &Integer::from(10), 3);

// -3 * -10 + -7 = 23
assert_eq!(&Integer::from(23) % &Integer::from(-10), 3);

// -3 * 10 + 7 = -23
assert_eq!(&Integer::from(-23) % &Integer::from(10), -3);

// 2 * -10 + -3 = -23
assert_eq!(&Integer::from(-23) % &Integer::from(-10), -3);
§

type Output = Integer

The resulting type after applying the % operator.
§

impl Rem<&Integer> for Integer

§

fn rem(self, other: &Integer) -> Integer

Divides an Integer by another Integer, taking the first by value and the second by reference and returning just the remainder. The remainder has the same sign as the first Integer.

If the quotient were computed, the quotient and remainder would satisfy $x = qy + r$ and $0 \leq |r| < |y|$.

$$ f(x, y) = x - y \operatorname{sgn}(xy) \left \lfloor \left | \frac{x}{y} \right | \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::integer::Integer;

// 2 * 10 + 3 = 23
assert_eq!(Integer::from(23) % &Integer::from(10), 3);

// -3 * -10 + -7 = 23
assert_eq!(Integer::from(23) % &Integer::from(-10), 3);

// -3 * 10 + 7 = -23
assert_eq!(Integer::from(-23) % &Integer::from(10), -3);

// 2 * -10 + -3 = -23
assert_eq!(Integer::from(-23) % &Integer::from(-10), -3);
§

type Output = Integer

The resulting type after applying the % operator.
§

impl Rem<Integer> for &Integer

§

fn rem(self, other: Integer) -> Integer

Divides an Integer by another Integer, taking the first by reference and the second by value and returning just the remainder. The remainder has the same sign as the first Integer.

If the quotient were computed, the quotient and remainder would satisfy $x = qy + r$ and $0 \leq |r| < |y|$.

$$ f(x, y) = x - y \operatorname{sgn}(xy) \left \lfloor \left | \frac{x}{y} \right | \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::integer::Integer;

// 2 * 10 + 3 = 23
assert_eq!(&Integer::from(23) % Integer::from(10), 3);

// -3 * -10 + -7 = 23
assert_eq!(&Integer::from(23) % Integer::from(-10), 3);

// -3 * 10 + 7 = -23
assert_eq!(&Integer::from(-23) % Integer::from(10), -3);

// 2 * -10 + -3 = -23
assert_eq!(&Integer::from(-23) % Integer::from(-10), -3);
§

type Output = Integer

The resulting type after applying the % operator.
§

impl Rem for Integer

§

fn rem(self, other: Integer) -> Integer

Divides an Integer by another Integer, taking both by value and returning just the remainder. The remainder has the same sign as the first Integer.

If the quotient were computed, the quotient and remainder would satisfy $x = qy + r$ and $0 \leq |r| < |y|$.

$$ f(x, y) = x - y \operatorname{sgn}(xy) \left \lfloor \left | \frac{x}{y} \right | \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::integer::Integer;

// 2 * 10 + 3 = 23
assert_eq!(Integer::from(23) % Integer::from(10), 3);

// -3 * -10 + -7 = 23
assert_eq!(Integer::from(23) % Integer::from(-10), 3);

// -3 * 10 + 7 = -23
assert_eq!(Integer::from(-23) % Integer::from(10), -3);

// 2 * -10 + -3 = -23
assert_eq!(Integer::from(-23) % Integer::from(-10), -3);
§

type Output = Integer

The resulting type after applying the % operator.
§

impl RemAssign<&Integer> for Integer

§

fn rem_assign(&mut self, other: &Integer)

Divides an Integer by another Integer, taking the second Integer by reference and replacing the first by the remainder. The remainder has the same sign as the first Integer.

If the quotient were computed, he quotient and remainder would satisfy $x = qy + r$ and $0 \leq |r| < |y|$.

$$ x \gets x - y \operatorname{sgn}(xy) \left \lfloor \left | \frac{x}{y} \right | \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::integer::Integer;

// 2 * 10 + 3 = 23
let mut x = Integer::from(23);
x %= &Integer::from(10);
assert_eq!(x, 3);

// -3 * -10 + -7 = 23
let mut x = Integer::from(23);
x %= &Integer::from(-10);
assert_eq!(x, 3);

// -3 * 10 + 7 = -23
let mut x = Integer::from(-23);
x %= &Integer::from(10);
assert_eq!(x, -3);

// 2 * -10 + -3 = -23
let mut x = Integer::from(-23);
x %= &Integer::from(-10);
assert_eq!(x, -3);
§

impl RemAssign for Integer

§

fn rem_assign(&mut self, other: Integer)

Divides an Integer by another Integer, taking the second Integer by value and replacing the first by the remainder. The remainder has the same sign as the first Integer.

If the quotient were computed, he quotient and remainder would satisfy $x = qy + r$ and $0 \leq |r| < |y|$.

$$ x \gets x - y \operatorname{sgn}(xy) \left \lfloor \left | \frac{x}{y} \right | \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::integer::Integer;

// 2 * 10 + 3 = 23
let mut x = Integer::from(23);
x %= Integer::from(10);
assert_eq!(x, 3);

// -3 * -10 + -7 = 23
let mut x = Integer::from(23);
x %= Integer::from(-10);
assert_eq!(x, 3);

// -3 * 10 + 7 = -23
let mut x = Integer::from(-23);
x %= Integer::from(10);
assert_eq!(x, -3);

// 2 * -10 + -3 = -23
let mut x = Integer::from(-23);
x %= Integer::from(-10);
assert_eq!(x, -3);
§

impl RemPowerOf2 for &Integer

§

fn rem_power_of_2(self, pow: u64) -> Integer

Divides an Integer by $2^k$, taking it by reference and returning just the remainder. The remainder has the same sign as the first number.

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\operatorname{sgn}(x)\left \lfloor \frac{|x|}{2^k} \right \rfloor. $$

Unlike mod_power_of_2, this function always returns zero or a number with the same sign as self.

§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::integer::Integer;

// 1 * 2^8 + 4 = 260
assert_eq!((&Integer::from(260)).rem_power_of_2(8), 4);
// -100 * 2^4 + -11 = -1611
assert_eq!((&Integer::from(-1611)).rem_power_of_2(4), -11);
§

type Output = Integer

§

impl RemPowerOf2 for Integer

§

fn rem_power_of_2(self, pow: u64) -> Integer

Divides an Integer by $2^k$, taking it by value and returning just the remainder. The remainder has the same sign as the first number.

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\operatorname{sgn}(x)\left \lfloor \frac{|x|}{2^k} \right \rfloor. $$

Unlike mod_power_of_2, this function always returns zero or a number with the same sign as self.

§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::integer::Integer;

// 1 * 2^8 + 4 = 260
assert_eq!(Integer::from(260).rem_power_of_2(8), 4);

// -100 * 2^4 + -11 = -1611
assert_eq!(Integer::from(-1611).rem_power_of_2(4), -11);
§

type Output = Integer

§

impl RemPowerOf2Assign for Integer

§

fn rem_power_of_2_assign(&mut self, pow: u64)

Divides an Integer by $2^k$, replacing the Integer by the remainder. The remainder has the same sign as the Integer.

If the quotient were computed, he quotient and remainder would satisfy $x = q2^k + r$ and $0 \leq r < 2^k$.

$$ x \gets x - 2^k\operatorname{sgn}(x)\left \lfloor \frac{|x|}{2^k} \right \rfloor. $$

Unlike mod_power_of_2_assign, this function does never changes the sign of self, except possibly to set self to 0.

§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::RemPowerOf2Assign;
use malachite_nz::integer::Integer;

// 1 * 2^8 + 4 = 260
let mut x = Integer::from(260);
x.rem_power_of_2_assign(8);
assert_eq!(x, 4);

// -100 * 2^4 + -11 = -1611
let mut x = Integer::from(-1611);
x.rem_power_of_2_assign(4);
assert_eq!(x, -11);
§

impl RoundToMultiple<&Integer> for &Integer

§

fn round_to_multiple( self, other: &Integer, rm: RoundingMode, ) -> (Integer, Ordering)

Rounds an Integer to a multiple of another Integer, according to a specified rounding mode. Both Integers 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}) = \operatorname{sgn}(q) |y| \lfloor |q| \rfloor.$

$f(x, y, \mathrm{Up}) = \operatorname{sgn}(q) |y| \lceil |q| \rceil.$

$f(x, y, \mathrm{Floor}) = |y| \lfloor q \rfloor.$

$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}) = q$, but panics if $q \notin \Z$.

The following two expressions are equivalent:

  • x.round_to_multiple(other, 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 is Exact, but self is not a multiple of other.
  • If self is nonzero, other is zero, and rm 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::integer::Integer;

assert_eq!(
    (&Integer::from(-5))
        .round_to_multiple(&Integer::ZERO, Down)
        .to_debug_string(),
    "(0, Greater)"
);

assert_eq!(
    (&Integer::from(-10))
        .round_to_multiple(&Integer::from(4), Down)
        .to_debug_string(),
    "(-8, Greater)"
);
assert_eq!(
    (&Integer::from(-10))
        .round_to_multiple(&Integer::from(4), Up)
        .to_debug_string(),
    "(-12, Less)"
);
assert_eq!(
    (&Integer::from(-10))
        .round_to_multiple(&Integer::from(5), Exact)
        .to_debug_string(),
    "(-10, Equal)"
);
assert_eq!(
    (&Integer::from(-10))
        .round_to_multiple(&Integer::from(3), Nearest)
        .to_debug_string(),
    "(-9, Greater)"
);
assert_eq!(
    (&Integer::from(-20))
        .round_to_multiple(&Integer::from(3), Nearest)
        .to_debug_string(),
    "(-21, Less)"
);
assert_eq!(
    (&Integer::from(-10))
        .round_to_multiple(&Integer::from(4), Nearest)
        .to_debug_string(),
    "(-8, Greater)"
);
assert_eq!(
    (&Integer::from(-14))
        .round_to_multiple(&Integer::from(4), Nearest)
        .to_debug_string(),
    "(-16, Less)"
);

assert_eq!(
    (&Integer::from(-10))
        .round_to_multiple(&Integer::from(-4), Down)
        .to_debug_string(),
    "(-8, Greater)"
);
assert_eq!(
    (&Integer::from(-10))
        .round_to_multiple(&Integer::from(-4), Up)
        .to_debug_string(),
    "(-12, Less)"
);
assert_eq!(
    (&Integer::from(-10))
        .round_to_multiple(&Integer::from(-5), Exact)
        .to_debug_string(),
    "(-10, Equal)"
);
assert_eq!(
    (&Integer::from(-10))
        .round_to_multiple(&Integer::from(-3), Nearest)
        .to_debug_string(),
    "(-9, Greater)"
);
assert_eq!(
    (&Integer::from(-20))
        .round_to_multiple(&Integer::from(-3), Nearest)
        .to_debug_string(),
    "(-21, Less)"
);
assert_eq!(
    (&Integer::from(-10))
        .round_to_multiple(&Integer::from(-4), Nearest)
        .to_debug_string(),
    "(-8, Greater)"
);
assert_eq!(
    (&Integer::from(-14))
        .round_to_multiple(&Integer::from(-4), Nearest)
        .to_debug_string(),
    "(-16, Less)"
);
§

type Output = Integer

§

impl RoundToMultiple<&Integer> for Integer

§

fn round_to_multiple( self, other: &Integer, rm: RoundingMode, ) -> (Integer, Ordering)

Rounds an Integer to a multiple of another Integer, according to a specified rounding mode. The first Integer 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}) = \operatorname{sgn}(q) |y| \lfloor |q| \rfloor.$

$f(x, y, \mathrm{Up}) = \operatorname{sgn}(q) |y| \lceil |q| \rceil.$

$f(x, y, \mathrm{Floor}) = |y| \lfloor q \rfloor.$

$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}) = q$, but panics if $q \notin \Z$.

The following two expressions are equivalent:

  • x.round_to_multiple(other, 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 is Exact, but self is not a multiple of other.
  • If self is nonzero, other is zero, and rm 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::integer::Integer;

assert_eq!(
    Integer::from(-5)
        .round_to_multiple(&Integer::ZERO, Down)
        .to_debug_string(),
    "(0, Greater)"
);

assert_eq!(
    Integer::from(-10)
        .round_to_multiple(&Integer::from(4), Down)
        .to_debug_string(),
    "(-8, Greater)"
);
assert_eq!(
    Integer::from(-10)
        .round_to_multiple(&Integer::from(4), Up)
        .to_debug_string(),
    "(-12, Less)"
);
assert_eq!(
    Integer::from(-10)
        .round_to_multiple(&Integer::from(5), Exact)
        .to_debug_string(),
    "(-10, Equal)"
);
assert_eq!(
    Integer::from(-10)
        .round_to_multiple(&Integer::from(3), Nearest)
        .to_debug_string(),
    "(-9, Greater)"
);
assert_eq!(
    Integer::from(-20)
        .round_to_multiple(&Integer::from(3), Nearest)
        .to_debug_string(),
    "(-21, Less)"
);
assert_eq!(
    Integer::from(-10)
        .round_to_multiple(&Integer::from(4), Nearest)
        .to_debug_string(),
    "(-8, Greater)"
);
assert_eq!(
    Integer::from(-14)
        .round_to_multiple(&Integer::from(4), Nearest)
        .to_debug_string(),
    "(-16, Less)"
);

assert_eq!(
    Integer::from(-10)
        .round_to_multiple(&Integer::from(-4), Down)
        .to_debug_string(),
    "(-8, Greater)"
);
assert_eq!(
    Integer::from(-10)
        .round_to_multiple(&Integer::from(-4), Up)
        .to_debug_string(),
    "(-12, Less)"
);
assert_eq!(
    Integer::from(-10)
        .round_to_multiple(&Integer::from(-5), Exact)
        .to_debug_string(),
    "(-10, Equal)"
);
assert_eq!(
    Integer::from(-10)
        .round_to_multiple(&Integer::from(-3), Nearest)
        .to_debug_string(),
    "(-9, Greater)"
);
assert_eq!(
    Integer::from(-20)
        .round_to_multiple(&Integer::from(-3), Nearest)
        .to_debug_string(),
    "(-21, Less)"
);
assert_eq!(
    Integer::from(-10)
        .round_to_multiple(&Integer::from(-4), Nearest)
        .to_debug_string(),
    "(-8, Greater)"
);
assert_eq!(
    Integer::from(-14)
        .round_to_multiple(&Integer::from(-4), Nearest)
        .to_debug_string(),
    "(-16, Less)"
);
§

type Output = Integer

§

impl RoundToMultiple<Integer> for &Integer

§

fn round_to_multiple( self, other: Integer, rm: RoundingMode, ) -> (Integer, Ordering)

Rounds an Integer to a multiple of another Integer, according to a specified rounding mode. The first Integer 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}) = \operatorname{sgn}(q) |y| \lfloor |q| \rfloor.$

$f(x, y, \mathrm{Up}) = \operatorname{sgn}(q) |y| \lceil |q| \rceil.$

$f(x, y, \mathrm{Floor}) = |y| \lfloor q \rfloor.$

$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}) = q$, but panics if $q \notin \Z$.

The following two expressions are equivalent:

  • x.round_to_multiple(other, 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 is Exact, but self is not a multiple of other.
  • If self is nonzero, other is zero, and rm 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::integer::Integer;

assert_eq!(
    (&Integer::from(-5))
        .round_to_multiple(Integer::ZERO, Down)
        .to_debug_string(),
    "(0, Greater)"
);

assert_eq!(
    (&Integer::from(-10))
        .round_to_multiple(Integer::from(4), Down)
        .to_debug_string(),
    "(-8, Greater)"
);
assert_eq!(
    (&Integer::from(-10))
        .round_to_multiple(Integer::from(4), Up)
        .to_debug_string(),
    "(-12, Less)"
);
assert_eq!(
    (&Integer::from(-10))
        .round_to_multiple(Integer::from(5), Exact)
        .to_debug_string(),
    "(-10, Equal)"
);
assert_eq!(
    (&Integer::from(-10))
        .round_to_multiple(Integer::from(3), Nearest)
        .to_debug_string(),
    "(-9, Greater)"
);
assert_eq!(
    (&Integer::from(-20))
        .round_to_multiple(Integer::from(3), Nearest)
        .to_debug_string(),
    "(-21, Less)"
);
assert_eq!(
    (&Integer::from(-10))
        .round_to_multiple(Integer::from(4), Nearest)
        .to_debug_string(),
    "(-8, Greater)"
);
assert_eq!(
    (&Integer::from(-14))
        .round_to_multiple(Integer::from(4), Nearest)
        .to_debug_string(),
    "(-16, Less)"
);

assert_eq!(
    (&Integer::from(-10))
        .round_to_multiple(Integer::from(-4), Down)
        .to_debug_string(),
    "(-8, Greater)"
);
assert_eq!(
    (&Integer::from(-10))
        .round_to_multiple(Integer::from(-4), Up)
        .to_debug_string(),
    "(-12, Less)"
);
assert_eq!(
    (&Integer::from(-10))
        .round_to_multiple(Integer::from(-5), Exact)
        .to_debug_string(),
    "(-10, Equal)"
);
assert_eq!(
    (&Integer::from(-10))
        .round_to_multiple(Integer::from(-3), Nearest)
        .to_debug_string(),
    "(-9, Greater)"
);
assert_eq!(
    (&Integer::from(-20))
        .round_to_multiple(Integer::from(-3), Nearest)
        .to_debug_string(),
    "(-21, Less)"
);
assert_eq!(
    (&Integer::from(-10))
        .round_to_multiple(Integer::from(-4), Nearest)
        .to_debug_string(),
    "(-8, Greater)"
);
assert_eq!(
    (&Integer::from(-14))
        .round_to_multiple(Integer::from(-4), Nearest)
        .to_debug_string(),
    "(-16, Less)"
);
§

type Output = Integer

§

impl RoundToMultiple for Integer

§

fn round_to_multiple( self, other: Integer, rm: RoundingMode, ) -> (Integer, Ordering)

Rounds an Integer to a multiple of another Integer, according to a specified rounding mode. Both Integers 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}) = \operatorname{sgn}(q) |y| \lfloor |q| \rfloor.$

$f(x, y, \mathrm{Up}) = \operatorname{sgn}(q) |y| \lceil |q| \rceil.$

$f(x, y, \mathrm{Floor}) = |y| \lfloor q \rfloor.$

$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}) = q$, but panics if $q \notin \Z$.

The following two expressions are equivalent:

  • x.round_to_multiple(other, 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 is Exact, but self is not a multiple of other.
  • If self is nonzero, other is zero, and rm 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::integer::Integer;

assert_eq!(
    Integer::from(-5)
        .round_to_multiple(Integer::ZERO, Down)
        .to_debug_string(),
    "(0, Greater)"
);

assert_eq!(
    Integer::from(-10)
        .round_to_multiple(Integer::from(4), Down)
        .to_debug_string(),
    "(-8, Greater)"
);
assert_eq!(
    Integer::from(-10)
        .round_to_multiple(Integer::from(4), Up)
        .to_debug_string(),
    "(-12, Less)"
);
assert_eq!(
    Integer::from(-10)
        .round_to_multiple(Integer::from(5), Exact)
        .to_debug_string(),
    "(-10, Equal)"
);
assert_eq!(
    Integer::from(-10)
        .round_to_multiple(Integer::from(3), Nearest)
        .to_debug_string(),
    "(-9, Greater)"
);
assert_eq!(
    Integer::from(-20)
        .round_to_multiple(Integer::from(3), Nearest)
        .to_debug_string(),
    "(-21, Less)"
);
assert_eq!(
    Integer::from(-10)
        .round_to_multiple(Integer::from(4), Nearest)
        .to_debug_string(),
    "(-8, Greater)"
);
assert_eq!(
    Integer::from(-14)
        .round_to_multiple(Integer::from(4), Nearest)
        .to_debug_string(),
    "(-16, Less)"
);

assert_eq!(
    Integer::from(-10)
        .round_to_multiple(Integer::from(-4), Down)
        .to_debug_string(),
    "(-8, Greater)"
);
assert_eq!(
    Integer::from(-10)
        .round_to_multiple(Integer::from(-4), Up)
        .to_debug_string(),
    "(-12, Less)"
);
assert_eq!(
    Integer::from(-10)
        .round_to_multiple(Integer::from(-5), Exact)
        .to_debug_string(),
    "(-10, Equal)"
);
assert_eq!(
    Integer::from(-10)
        .round_to_multiple(Integer::from(-3), Nearest)
        .to_debug_string(),
    "(-9, Greater)"
);
assert_eq!(
    Integer::from(-20)
        .round_to_multiple(Integer::from(-3), Nearest)
        .to_debug_string(),
    "(-21, Less)"
);
assert_eq!(
    Integer::from(-10)
        .round_to_multiple(Integer::from(-4), Nearest)
        .to_debug_string(),
    "(-8, Greater)"
);
assert_eq!(
    Integer::from(-14)
        .round_to_multiple(Integer::from(-4), Nearest)
        .to_debug_string(),
    "(-16, Less)"
);
§

type Output = Integer

§

impl RoundToMultipleAssign<&Integer> for Integer

§

fn round_to_multiple_assign( &mut self, other: &Integer, rm: RoundingMode, ) -> Ordering

Rounds an Integer to a multiple of another Integer in place, according to a specified rounding mode. The Integer on the right-hand side is taken by reference. 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, 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 is Exact, but self is not a multiple of other.
  • If self is nonzero, other is zero, and rm is trying to round away from zero.
§Examples
use core::cmp::Ordering::*;
use malachite_base::num::arithmetic::traits::RoundToMultipleAssign;
use malachite_base::num::basic::traits::Zero;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_nz::integer::Integer;

let mut x = Integer::from(-5);
assert_eq!(x.round_to_multiple_assign(&Integer::ZERO, Down), Greater);
assert_eq!(x, 0);

let mut x = Integer::from(-10);
assert_eq!(x.round_to_multiple_assign(&Integer::from(4), Down), Greater);
assert_eq!(x, -8);

let mut x = Integer::from(-10);
assert_eq!(x.round_to_multiple_assign(&Integer::from(4), Up), Less);
assert_eq!(x, -12);

let mut x = Integer::from(-10);
assert_eq!(x.round_to_multiple_assign(&Integer::from(5), Exact), Equal);
assert_eq!(x, -10);

let mut x = Integer::from(-10);
assert_eq!(
    x.round_to_multiple_assign(&Integer::from(3), Nearest),
    Greater
);
assert_eq!(x, -9);

let mut x = Integer::from(-20);
assert_eq!(x.round_to_multiple_assign(&Integer::from(3), Nearest), Less);
assert_eq!(x, -21);

let mut x = Integer::from(-10);
assert_eq!(
    x.round_to_multiple_assign(&Integer::from(4), Nearest),
    Greater
);
assert_eq!(x, -8);

let mut x = Integer::from(-14);
assert_eq!(x.round_to_multiple_assign(&Integer::from(4), Nearest), Less);
assert_eq!(x, -16);

let mut x = Integer::from(-10);
assert_eq!(
    x.round_to_multiple_assign(&Integer::from(-4), Down),
    Greater
);
assert_eq!(x, -8);

let mut x = Integer::from(-10);
assert_eq!(x.round_to_multiple_assign(&Integer::from(-4), Up), Less);
assert_eq!(x, -12);

let mut x = Integer::from(-10);
assert_eq!(x.round_to_multiple_assign(&Integer::from(-5), Exact), Equal);
assert_eq!(x, -10);

let mut x = Integer::from(-10);
assert_eq!(
    x.round_to_multiple_assign(&Integer::from(-3), Nearest),
    Greater
);
assert_eq!(x, -9);

let mut x = Integer::from(-20);
assert_eq!(
    x.round_to_multiple_assign(&Integer::from(-3), Nearest),
    Less
);
assert_eq!(x, -21);

let mut x = Integer::from(-10);
assert_eq!(
    x.round_to_multiple_assign(&Integer::from(-4), Nearest),
    Greater
);
assert_eq!(x, -8);

let mut x = Integer::from(-14);
assert_eq!(
    x.round_to_multiple_assign(&Integer::from(-4), Nearest),
    Less
);
assert_eq!(x, -16);
§

impl RoundToMultipleAssign for Integer

§

fn round_to_multiple_assign( &mut self, other: Integer, rm: RoundingMode, ) -> Ordering

Rounds an Integer to a multiple of another Integer in place, according to a specified rounding mode. The Integer 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, 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 is Exact, but self is not a multiple of other.
  • If self is nonzero, other is zero, and rm is trying to round away from zero.
§Examples
use core::cmp::Ordering::*;
use malachite_base::num::arithmetic::traits::RoundToMultipleAssign;
use malachite_base::num::basic::traits::Zero;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_nz::integer::Integer;

let mut x = Integer::from(-5);
assert_eq!(x.round_to_multiple_assign(Integer::ZERO, Down), Greater);
assert_eq!(x, 0);

let mut x = Integer::from(-10);
assert_eq!(x.round_to_multiple_assign(Integer::from(4), Down), Greater);
assert_eq!(x, -8);

let mut x = Integer::from(-10);
assert_eq!(x.round_to_multiple_assign(Integer::from(4), Up), Less);
assert_eq!(x, -12);

let mut x = Integer::from(-10);
assert_eq!(x.round_to_multiple_assign(Integer::from(5), Exact), Equal);
assert_eq!(x, -10);

let mut x = Integer::from(-10);
assert_eq!(
    x.round_to_multiple_assign(Integer::from(3), Nearest),
    Greater
);
assert_eq!(x, -9);

let mut x = Integer::from(-20);
assert_eq!(x.round_to_multiple_assign(Integer::from(3), Nearest), Less);
assert_eq!(x, -21);

let mut x = Integer::from(-10);
assert_eq!(
    x.round_to_multiple_assign(Integer::from(4), Nearest),
    Greater
);
assert_eq!(x, -8);

let mut x = Integer::from(-14);
assert_eq!(x.round_to_multiple_assign(Integer::from(4), Nearest), Less);
assert_eq!(x, -16);

let mut x = Integer::from(-10);
assert_eq!(x.round_to_multiple_assign(Integer::from(-4), Down), Greater);
assert_eq!(x, -8);

let mut x = Integer::from(-10);
assert_eq!(x.round_to_multiple_assign(Integer::from(-4), Up), Less);
assert_eq!(x, -12);

let mut x = Integer::from(-10);
assert_eq!(x.round_to_multiple_assign(Integer::from(-5), Exact), Equal);
assert_eq!(x, -10);

let mut x = Integer::from(-10);
assert_eq!(
    x.round_to_multiple_assign(Integer::from(-3), Nearest),
    Greater
);
assert_eq!(x, -9);

let mut x = Integer::from(-20);
assert_eq!(x.round_to_multiple_assign(Integer::from(-3), Nearest), Less);
assert_eq!(x, -21);

let mut x = Integer::from(-10);
assert_eq!(
    x.round_to_multiple_assign(Integer::from(-4), Nearest),
    Greater
);
assert_eq!(x, -8);

let mut x = Integer::from(-14);
assert_eq!(x.round_to_multiple_assign(Integer::from(-4), Nearest), Less);
assert_eq!(x, -16);
§

impl RoundToMultipleOfPowerOf2<u64> for &Integer

§

fn round_to_multiple_of_power_of_2( self, pow: u64, rm: RoundingMode, ) -> (Integer, Ordering)

Rounds an Integer to a multiple of $2^k$ according to a specified rounding mode. The Integer 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}) = 2^k \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$f(x, k, \mathrm{Up}) = 2^k \operatorname{sgn}(q) \lceil |q| \rceil.$

$f(x, k, \mathrm{Floor}) = 2^k \lfloor q \rfloor.$

$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, 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::integer::Integer;

assert_eq!(
    (&Integer::from(10))
        .round_to_multiple_of_power_of_2(2, Floor)
        .to_debug_string(),
    "(8, Less)"
);
assert_eq!(
    (&Integer::from(-10))
        .round_to_multiple_of_power_of_2(2, Ceiling)
        .to_debug_string(),
    "(-8, Greater)"
);
assert_eq!(
    (&Integer::from(10))
        .round_to_multiple_of_power_of_2(2, Down)
        .to_debug_string(),
    "(8, Less)"
);
assert_eq!(
    (&Integer::from(-10))
        .round_to_multiple_of_power_of_2(2, Up)
        .to_debug_string(),
    "(-12, Less)"
);
assert_eq!(
    (&Integer::from(10))
        .round_to_multiple_of_power_of_2(2, Nearest)
        .to_debug_string(),
    "(8, Less)"
);
assert_eq!(
    (&Integer::from(-12))
        .round_to_multiple_of_power_of_2(2, Exact)
        .to_debug_string(),
    "(-12, Equal)"
);
§

type Output = Integer

§

impl RoundToMultipleOfPowerOf2<u64> for Integer

§

fn round_to_multiple_of_power_of_2( self, pow: u64, rm: RoundingMode, ) -> (Integer, Ordering)

Rounds an Integer to a multiple of $2^k$ according to a specified rounding mode. The Integer 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}) = 2^k \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$f(x, k, \mathrm{Up}) = 2^k \operatorname{sgn}(q) \lceil |q| \rceil.$

$f(x, k, \mathrm{Floor}) = 2^k \lfloor q \rfloor.$

$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, 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::integer::Integer;

assert_eq!(
    Integer::from(10)
        .round_to_multiple_of_power_of_2(2, Floor)
        .to_debug_string(),
    "(8, Less)"
);
assert_eq!(
    Integer::from(-10)
        .round_to_multiple_of_power_of_2(2, Ceiling)
        .to_debug_string(),
    "(-8, Greater)"
);
assert_eq!(
    Integer::from(10)
        .round_to_multiple_of_power_of_2(2, Down)
        .to_debug_string(),
    "(8, Less)"
);
assert_eq!(
    Integer::from(-10)
        .round_to_multiple_of_power_of_2(2, Up)
        .to_debug_string(),
    "(-12, Less)"
);
assert_eq!(
    Integer::from(10)
        .round_to_multiple_of_power_of_2(2, Nearest)
        .to_debug_string(),
    "(8, Less)"
);
assert_eq!(
    Integer::from(-12)
        .round_to_multiple_of_power_of_2(2, Exact)
        .to_debug_string(),
    "(-12, Equal)"
);
§

type Output = Integer

§

impl RoundToMultipleOfPowerOf2Assign<u64> for Integer

§

fn round_to_multiple_of_power_of_2_assign( &mut self, pow: u64, rm: RoundingMode, ) -> Ordering

Rounds an Integer 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, 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 core::cmp::Ordering::*;
use malachite_base::num::arithmetic::traits::RoundToMultipleOfPowerOf2Assign;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_nz::integer::Integer;

let mut n = Integer::from(10);
assert_eq!(n.round_to_multiple_of_power_of_2_assign(2, Floor), Less);
assert_eq!(n, 8);

let mut n = Integer::from(-10);
assert_eq!(
    n.round_to_multiple_of_power_of_2_assign(2, Ceiling),
    Greater
);
assert_eq!(n, -8);

let mut n = Integer::from(10);
assert_eq!(n.round_to_multiple_of_power_of_2_assign(2, Down), Less);
assert_eq!(n, 8);

let mut n = Integer::from(-10);
assert_eq!(n.round_to_multiple_of_power_of_2_assign(2, Up), Less);
assert_eq!(n, -12);

let mut n = Integer::from(10);
assert_eq!(n.round_to_multiple_of_power_of_2_assign(2, Nearest), Less);
assert_eq!(n, 8);

let mut n = Integer::from(-12);
assert_eq!(n.round_to_multiple_of_power_of_2_assign(2, Exact), Equal);
assert_eq!(n, -12);
§

impl RoundingFrom<&Rational> for Integer

§

fn rounding_from(x: &Rational, rm: RoundingMode) -> (Integer, Ordering)

Converts a [Rational] to an Integer, using a specified [RoundingMode] and taking the [Rational] by reference. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original 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 x.significant_bits().

§Panics

Panics if the [Rational] is not an integer and rm is Exact.

§Examples
use malachite_base::num::conversion::traits::RoundingFrom;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_base::strings::ToDebugString;
use malachite_nz::integer::Integer;
use malachite_q::Rational;

assert_eq!(
    Integer::rounding_from(&Rational::from(123), Exact).to_debug_string(),
    "(123, Equal)"
);
assert_eq!(
    Integer::rounding_from(&Rational::from(-123), Exact).to_debug_string(),
    "(-123, Equal)"
);

assert_eq!(
    Integer::rounding_from(&Rational::from_signeds(22, 7), Floor).to_debug_string(),
    "(3, Less)"
);
assert_eq!(
    Integer::rounding_from(&Rational::from_signeds(22, 7), Down).to_debug_string(),
    "(3, Less)"
);
assert_eq!(
    Integer::rounding_from(&Rational::from_signeds(22, 7), Ceiling).to_debug_string(),
    "(4, Greater)"
);
assert_eq!(
    Integer::rounding_from(&Rational::from_signeds(22, 7), Up).to_debug_string(),
    "(4, Greater)"
);
assert_eq!(
    Integer::rounding_from(&Rational::from_signeds(22, 7), Nearest).to_debug_string(),
    "(3, Less)"
);

assert_eq!(
    Integer::rounding_from(Rational::from_signeds(-22, 7), Floor).to_debug_string(),
    "(-4, Less)"
);
assert_eq!(
    Integer::rounding_from(Rational::from_signeds(-22, 7), Down).to_debug_string(),
    "(-3, Greater)"
);
assert_eq!(
    Integer::rounding_from(Rational::from_signeds(-22, 7), Ceiling).to_debug_string(),
    "(-3, Greater)"
);
assert_eq!(
    Integer::rounding_from(Rational::from_signeds(-22, 7), Up).to_debug_string(),
    "(-4, Less)"
);
assert_eq!(
    Integer::rounding_from(Rational::from_signeds(-22, 7), Nearest).to_debug_string(),
    "(-3, Greater)"
);
§

impl RoundingFrom<Rational> for Integer

§

fn rounding_from(x: Rational, rm: RoundingMode) -> (Integer, Ordering)

Converts a [Rational] to an Integer, using a specified [RoundingMode] and taking the [Rational] by value. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the original 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 x.significant_bits().

§Panics

Panics if the [Rational] is not an integer and rm is Exact.

§Examples
use malachite_base::num::conversion::traits::RoundingFrom;
use malachite_base::rounding_modes::RoundingMode::*;
use malachite_base::strings::ToDebugString;
use malachite_nz::integer::Integer;
use malachite_q::Rational;

assert_eq!(
    Integer::rounding_from(Rational::from(123), Exact).to_debug_string(),
    "(123, Equal)"
);
assert_eq!(
    Integer::rounding_from(Rational::from(-123), Exact).to_debug_string(),
    "(-123, Equal)"
);

assert_eq!(
    Integer::rounding_from(Rational::from_signeds(22, 7), Floor).to_debug_string(),
    "(3, Less)"
);
assert_eq!(
    Integer::rounding_from(Rational::from_signeds(22, 7), Down).to_debug_string(),
    "(3, Less)"
);
assert_eq!(
    Integer::rounding_from(Rational::from_signeds(22, 7), Ceiling).to_debug_string(),
    "(4, Greater)"
);
assert_eq!(
    Integer::rounding_from(Rational::from_signeds(22, 7), Up).to_debug_string(),
    "(4, Greater)"
);
assert_eq!(
    Integer::rounding_from(Rational::from_signeds(22, 7), Nearest).to_debug_string(),
    "(3, Less)"
);

assert_eq!(
    Integer::rounding_from(Rational::from_signeds(-22, 7), Floor).to_debug_string(),
    "(-4, Less)"
);
assert_eq!(
    Integer::rounding_from(Rational::from_signeds(-22, 7), Down).to_debug_string(),
    "(-3, Greater)"
);
assert_eq!(
    Integer::rounding_from(Rational::from_signeds(-22, 7), Ceiling).to_debug_string(),
    "(-3, Greater)"
);
assert_eq!(
    Integer::rounding_from(Rational::from_signeds(-22, 7), Up).to_debug_string(),
    "(-4, Less)"
);
assert_eq!(
    Integer::rounding_from(Rational::from_signeds(-22, 7), Nearest).to_debug_string(),
    "(-3, Greater)"
);
§

impl RoundingFrom<f32> for Integer

§

fn rounding_from(value: f32, rm: RoundingMode) -> (Integer, Ordering)

Converts a primitive float to an Integer, 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.

§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 or if the rounding mode is Exact and value is not an integer.

§Examples

See here.

§

impl RoundingFrom<f64> for Integer

§

fn rounding_from(value: f64, rm: RoundingMode) -> (Integer, Ordering)

Converts a primitive float to an Integer, 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.

§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 or if the rounding mode is Exact and value is not an integer.

§Examples

See here.

§

impl<'a> SaturatingFrom<&'a Integer> for 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);
§

impl<'a> SaturatingFrom<&'a Integer> for u32

§

fn saturating_from(value: &Integer) -> u32

Converts an Integer to an unsigned primitive integer.

If the Integer cannot be represented by the output type, then either zero or the maximum representable value is returned, whichever is closer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

impl SaturatingFrom<Integer> for 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);
§

impl<'a> Shl<i128> for &Integer

§

fn shl(self, bits: i128) -> Integer

Left-shifts an Integer (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.

§

type Output = Integer

The resulting type after applying the << operator.
§

impl Shl<i128> for Integer

§

fn shl(self, bits: i128) -> Integer

Left-shifts an Integer (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.

§

type Output = Integer

The resulting type after applying the << operator.
§

impl<'a> Shl<i16> for &Integer

§

fn shl(self, bits: i16) -> Integer

Left-shifts an Integer (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.

§

type Output = Integer

The resulting type after applying the << operator.
§

impl Shl<i16> for Integer

§

fn shl(self, bits: i16) -> Integer

Left-shifts an Integer (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.

§

type Output = Integer

The resulting type after applying the << operator.
§

impl<'a> Shl<i32> for &Integer

§

fn shl(self, bits: i32) -> Integer

Left-shifts an Integer (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.

§

type Output = Integer

The resulting type after applying the << operator.
§

impl Shl<i32> for Integer

§

fn shl(self, bits: i32) -> Integer

Left-shifts an Integer (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.

§

type Output = Integer

The resulting type after applying the << operator.
§

impl<'a> Shl<i64> for &Integer

§

fn shl(self, bits: i64) -> Integer

Left-shifts an Integer (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.

§

type Output = Integer

The resulting type after applying the << operator.
§

impl Shl<i64> for Integer

§

fn shl(self, bits: i64) -> Integer

Left-shifts an Integer (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.

§

type Output = Integer

The resulting type after applying the << operator.
§

impl<'a> Shl<i8> for &Integer

§

fn shl(self, bits: i8) -> Integer

Left-shifts an Integer (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.

§

type Output = Integer

The resulting type after applying the << operator.
§

impl Shl<i8> for Integer

§

fn shl(self, bits: i8) -> Integer

Left-shifts an Integer (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.

§

type Output = Integer

The resulting type after applying the << operator.
§

impl<'a> Shl<isize> for &Integer

§

fn shl(self, bits: isize) -> Integer

Left-shifts an Integer (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.

§

type Output = Integer

The resulting type after applying the << operator.
§

impl Shl<isize> for Integer

§

fn shl(self, bits: isize) -> Integer

Left-shifts an Integer (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.

§

type Output = Integer

The resulting type after applying the << operator.
§

impl<'a> Shl<u128> for &Integer

§

fn shl(self, bits: u128) -> Integer

Left-shifts an Integer (multiplies it by a power of 2), taking it by reference.

$$ f(x, k) = x2^k. $$

§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 bits.

§Examples

See here.

§

type Output = Integer

The resulting type after applying the << operator.
§

impl Shl<u128> for Integer

§

fn shl(self, bits: u128) -> Integer

Left-shifts an Integer (multiplies it by a power of 2), taking it by value.

$$ f(x, k) = x2^k. $$

§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 bits.

§Examples

See here.

§

type Output = Integer

The resulting type after applying the << operator.
§

impl<'a> Shl<u16> for &Integer

§

fn shl(self, bits: u16) -> Integer

Left-shifts an Integer (multiplies it by a power of 2), taking it by reference.

$$ f(x, k) = x2^k. $$

§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 bits.

§Examples

See here.

§

type Output = Integer

The resulting type after applying the << operator.
§

impl Shl<u16> for Integer

§

fn shl(self, bits: u16) -> Integer

Left-shifts an Integer (multiplies it by a power of 2), taking it by value.

$$ f(x, k) = x2^k. $$

§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 bits.

§Examples

See here.

§

type Output = Integer

The resulting type after applying the << operator.
§

impl<'a> Shl<u32> for &Integer

§

fn shl(self, bits: u32) -> Integer

Left-shifts an Integer (multiplies it by a power of 2), taking it by reference.

$$ f(x, k) = x2^k. $$

§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 bits.

§Examples

See here.

§

type Output = Integer

The resulting type after applying the << operator.
§

impl Shl<u32> for Integer

§

fn shl(self, bits: u32) -> Integer

Left-shifts an Integer (multiplies it by a power of 2), taking it by value.

$$ f(x, k) = x2^k. $$

§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 bits.

§Examples

See here.

§

type Output = Integer

The resulting type after applying the << operator.
§

impl<'a> Shl<u64> for &Integer

§

fn shl(self, bits: u64) -> Integer

Left-shifts an Integer (multiplies it by a power of 2), taking it by reference.

$$ f(x, k) = x2^k. $$

§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 bits.

§Examples

See here.

§

type Output = Integer

The resulting type after applying the << operator.
§

impl Shl<u64> for Integer

§

fn shl(self, bits: u64) -> Integer

Left-shifts an Integer (multiplies it by a power of 2), taking it by value.

$$ f(x, k) = x2^k. $$

§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 bits.

§Examples

See here.

§

type Output = Integer

The resulting type after applying the << operator.
§

impl<'a> Shl<u8> for &Integer

§

fn shl(self, bits: u8) -> Integer

Left-shifts an Integer (multiplies it by a power of 2), taking it by reference.

$$ f(x, k) = x2^k. $$

§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 bits.

§Examples

See here.

§

type Output = Integer

The resulting type after applying the << operator.
§

impl Shl<u8> for Integer

§

fn shl(self, bits: u8) -> Integer

Left-shifts an Integer (multiplies it by a power of 2), taking it by value.

$$ f(x, k) = x2^k. $$

§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 bits.

§Examples

See here.

§

type Output = Integer

The resulting type after applying the << operator.
§

impl<'a> Shl<usize> for &Integer

§

fn shl(self, bits: usize) -> Integer

Left-shifts an Integer (multiplies it by a power of 2), taking it by reference.

$$ f(x, k) = x2^k. $$

§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 bits.

§Examples

See here.

§

type Output = Integer

The resulting type after applying the << operator.
§

impl Shl<usize> for Integer

§

fn shl(self, bits: usize) -> Integer

Left-shifts an Integer (multiplies it by a power of 2), taking it by value.

$$ f(x, k) = x2^k. $$

§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 bits.

§Examples

See here.

§

type Output = Integer

The resulting type after applying the << operator.
§

impl ShlAssign<i128> for Integer

§

fn shl_assign(&mut self, bits: i128)

Left-shifts an Integer (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).

§Examples

See here.

§

impl ShlAssign<i16> for Integer

§

fn shl_assign(&mut self, bits: i16)

Left-shifts an Integer (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).

§Examples

See here.

§

impl ShlAssign<i32> for Integer

§

fn shl_assign(&mut self, bits: i32)

Left-shifts an Integer (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).

§Examples

See here.

§

impl ShlAssign<i64> for Integer

§

fn shl_assign(&mut self, bits: i64)

Left-shifts an Integer (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).

§Examples

See here.

§

impl ShlAssign<i8> for Integer

§

fn shl_assign(&mut self, bits: i8)

Left-shifts an Integer (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).

§Examples

See here.

§

impl ShlAssign<isize> for Integer

§

fn shl_assign(&mut self, bits: isize)

Left-shifts an Integer (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).

§Examples

See here.

§

impl ShlAssign<u128> for Integer

§

fn shl_assign(&mut self, bits: u128)

Left-shifts an Integer (multiplies it by a power of 2), in place.

$$ x \gets x2^k. $$

§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 bits.

§Examples

See here.

§

impl ShlAssign<u16> for Integer

§

fn shl_assign(&mut self, bits: u16)

Left-shifts an Integer (multiplies it by a power of 2), in place.

$$ x \gets x2^k. $$

§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 bits.

§Examples

See here.

§

impl ShlAssign<u32> for Integer

§

fn shl_assign(&mut self, bits: u32)

Left-shifts an Integer (multiplies it by a power of 2), in place.

$$ x \gets x2^k. $$

§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 bits.

§Examples

See here.

§

impl ShlAssign<u64> for Integer

§

fn shl_assign(&mut self, bits: u64)

Left-shifts an Integer (multiplies it by a power of 2), in place.

$$ x \gets x2^k. $$

§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 bits.

§Examples

See here.

§

impl ShlAssign<u8> for Integer

§

fn shl_assign(&mut self, bits: u8)

Left-shifts an Integer (multiplies it by a power of 2), in place.

$$ x \gets x2^k. $$

§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 bits.

§Examples

See here.

§

impl ShlAssign<usize> for Integer

§

fn shl_assign(&mut self, bits: usize)

Left-shifts an Integer (multiplies it by a power of 2), in place.

$$ x \gets x2^k. $$

§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 bits.

§Examples

See here.

§

impl<'a> ShlRound<i128> for &Integer

§

fn shl_round(self, bits: i128, rm: RoundingMode) -> (Integer, Ordering)

Left-shifts an Integer (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 Floor is equivalent to using >>. To test whether 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 Exact but self is not divisible by $2^{-k}$.

§Examples

See here.

§

type Output = Integer

§

impl ShlRound<i128> for Integer

§

fn shl_round(self, bits: i128, rm: RoundingMode) -> (Integer, Ordering)

Left-shifts an Integer (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 Floor is equivalent to using >>. To test whether 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 Exact but self is not divisible by $2^{-k}$.

§Examples

See here.

§

type Output = Integer

§

impl<'a> ShlRound<i16> for &Integer

§

fn shl_round(self, bits: i16, rm: RoundingMode) -> (Integer, Ordering)

Left-shifts an Integer (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 Floor is equivalent to using >>. To test whether 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 Exact but self is not divisible by $2^{-k}$.

§Examples

See here.

§

type Output = Integer

§

impl ShlRound<i16> for Integer

§

fn shl_round(self, bits: i16, rm: RoundingMode) -> (Integer, Ordering)

Left-shifts an Integer (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 Floor is equivalent to using >>. To test whether 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 Exact but self is not divisible by $2^{-k}$.

§Examples

See here.

§

type Output = Integer

§

impl<'a> ShlRound<i32> for &Integer

§

fn shl_round(self, bits: i32, rm: RoundingMode) -> (Integer, Ordering)

Left-shifts an Integer (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 Floor is equivalent to using >>. To test whether 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 Exact but self is not divisible by $2^{-k}$.

§Examples

See here.

§

type Output = Integer

§

impl ShlRound<i32> for Integer

§

fn shl_round(self, bits: i32, rm: RoundingMode) -> (Integer, Ordering)

Left-shifts an Integer (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 Floor is equivalent to using >>. To test whether 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 Exact but self is not divisible by $2^{-k}$.

§Examples

See here.

§

type Output = Integer

§

impl<'a> ShlRound<i64> for &Integer

§

fn shl_round(self, bits: i64, rm: RoundingMode) -> (Integer, Ordering)

Left-shifts an Integer (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 Floor is equivalent to using >>. To test whether 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 Exact but self is not divisible by $2^{-k}$.

§Examples

See here.

§

type Output = Integer

§

impl ShlRound<i64> for Integer

§

fn shl_round(self, bits: i64, rm: RoundingMode) -> (Integer, Ordering)

Left-shifts an Integer (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 Floor is equivalent to using >>. To test whether 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 Exact but self is not divisible by $2^{-k}$.

§Examples

See here.

§

type Output = Integer

§

impl<'a> ShlRound<i8> for &Integer

§

fn shl_round(self, bits: i8, rm: RoundingMode) -> (Integer, Ordering)

Left-shifts an Integer (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 Floor is equivalent to using >>. To test whether 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 Exact but self is not divisible by $2^{-k}$.

§Examples

See here.

§

type Output = Integer

§

impl ShlRound<i8> for Integer

§

fn shl_round(self, bits: i8, rm: RoundingMode) -> (Integer, Ordering)

Left-shifts an Integer (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 Floor is equivalent to using >>. To test whether 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 Exact but self is not divisible by $2^{-k}$.

§Examples

See here.

§

type Output = Integer

§

impl<'a> ShlRound<isize> for &Integer

§

fn shl_round(self, bits: isize, rm: RoundingMode) -> (Integer, Ordering)

Left-shifts an Integer (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 Floor is equivalent to using >>. To test whether 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 Exact but self is not divisible by $2^{-k}$.

§Examples

See here.

§

type Output = Integer

§

impl ShlRound<isize> for Integer

§

fn shl_round(self, bits: isize, rm: RoundingMode) -> (Integer, Ordering)

Left-shifts an Integer (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 Floor is equivalent to using >>. To test whether 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 Exact but self is not divisible by $2^{-k}$.

§Examples

See here.

§

type Output = Integer

§

impl ShlRoundAssign<i128> for Integer

§

fn shl_round_assign(&mut self, bits: i128, rm: RoundingMode) -> Ordering

Left-shifts an Integer (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 Floor is equivalent to using >>. To test whether 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).

§Examples

See here.

§

impl ShlRoundAssign<i16> for Integer

§

fn shl_round_assign(&mut self, bits: i16, rm: RoundingMode) -> Ordering

Left-shifts an Integer (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 Floor is equivalent to using >>. To test whether 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).

§Examples

See here.

§

impl ShlRoundAssign<i32> for Integer

§

fn shl_round_assign(&mut self, bits: i32, rm: RoundingMode) -> Ordering

Left-shifts an Integer (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 Floor is equivalent to using >>. To test whether 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).

§Examples

See here.

§

impl ShlRoundAssign<i64> for Integer

§

fn shl_round_assign(&mut self, bits: i64, rm: RoundingMode) -> Ordering

Left-shifts an Integer (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 Floor is equivalent to using >>. To test whether 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).

§Examples

See here.

§

impl ShlRoundAssign<i8> for Integer

§

fn shl_round_assign(&mut self, bits: i8, rm: RoundingMode) -> Ordering

Left-shifts an Integer (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 Floor is equivalent to using >>. To test whether 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).

§Examples

See here.

§

impl ShlRoundAssign<isize> for Integer

§

fn shl_round_assign(&mut self, bits: isize, rm: RoundingMode) -> Ordering

Left-shifts an Integer (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 Floor is equivalent to using >>. To test whether 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).

§Examples

See here.

§

impl<'a> Shr<i128> for &Integer

§

fn shr(self, bits: i128) -> Integer

Right-shifts an Integer (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(1)$

where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits).

§Examples

See here.

§

type Output = Integer

The resulting type after applying the >> operator.
§

impl Shr<i128> for Integer

§

fn shr(self, bits: i128) -> Integer

Right-shifts an Integer (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.

§

type Output = Integer

The resulting type after applying the >> operator.
§

impl<'a> Shr<i16> for &Integer

§

fn shr(self, bits: i16) -> Integer

Right-shifts an Integer (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(1)$

where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits).

§Examples

See here.

§

type Output = Integer

The resulting type after applying the >> operator.
§

impl Shr<i16> for Integer

§

fn shr(self, bits: i16) -> Integer

Right-shifts an Integer (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.

§

type Output = Integer

The resulting type after applying the >> operator.
§

impl<'a> Shr<i32> for &Integer

§

fn shr(self, bits: i32) -> Integer

Right-shifts an Integer (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(1)$

where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits).

§Examples

See here.

§

type Output = Integer

The resulting type after applying the >> operator.
§

impl Shr<i32> for Integer

§

fn shr(self, bits: i32) -> Integer

Right-shifts an Integer (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.

§

type Output = Integer

The resulting type after applying the >> operator.
§

impl<'a> Shr<i64> for &Integer

§

fn shr(self, bits: i64) -> Integer

Right-shifts an Integer (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(1)$

where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits).

§Examples

See here.

§

type Output = Integer

The resulting type after applying the >> operator.
§

impl Shr<i64> for Integer

§

fn shr(self, bits: i64) -> Integer

Right-shifts an Integer (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.

§

type Output = Integer

The resulting type after applying the >> operator.
§

impl<'a> Shr<i8> for &Integer

§

fn shr(self, bits: i8) -> Integer

Right-shifts an Integer (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(1)$

where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits).

§Examples

See here.

§

type Output = Integer

The resulting type after applying the >> operator.
§

impl Shr<i8> for Integer

§

fn shr(self, bits: i8) -> Integer

Right-shifts an Integer (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.

§

type Output = Integer

The resulting type after applying the >> operator.
§

impl<'a> Shr<isize> for &Integer

§

fn shr(self, bits: isize) -> Integer

Right-shifts an Integer (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(1)$

where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits).

§Examples

See here.

§

type Output = Integer

The resulting type after applying the >> operator.
§

impl Shr<isize> for Integer

§

fn shr(self, bits: isize) -> Integer

Right-shifts an Integer (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.

§

type Output = Integer

The resulting type after applying the >> operator.
§

impl<'a> Shr<u128> for &Integer

§

fn shr(self, bits: u128) -> Integer

Right-shifts an Integer (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(1)$

where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits).

§Examples

See here.

§

type Output = Integer

The resulting type after applying the >> operator.
§

impl Shr<u128> for Integer

§

fn shr(self, bits: u128) -> Integer

Right-shifts an Integer (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.

§

type Output = Integer

The resulting type after applying the >> operator.
§

impl<'a> Shr<u16> for &Integer

§

fn shr(self, bits: u16) -> Integer

Right-shifts an Integer (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(1)$

where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits).

§Examples

See here.

§

type Output = Integer

The resulting type after applying the >> operator.
§

impl Shr<u16> for Integer

§

fn shr(self, bits: u16) -> Integer

Right-shifts an Integer (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.

§

type Output = Integer

The resulting type after applying the >> operator.
§

impl<'a> Shr<u32> for &Integer

§

fn shr(self, bits: u32) -> Integer

Right-shifts an Integer (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(1)$

where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits).

§Examples

See here.

§

type Output = Integer

The resulting type after applying the >> operator.
§

impl Shr<u32> for Integer

§

fn shr(self, bits: u32) -> Integer

Right-shifts an Integer (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.

§

type Output = Integer

The resulting type after applying the >> operator.
§

impl<'a> Shr<u64> for &Integer

§

fn shr(self, bits: u64) -> Integer

Right-shifts an Integer (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(1)$

where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits).

§Examples

See here.

§

type Output = Integer

The resulting type after applying the >> operator.
§

impl Shr<u64> for Integer

§

fn shr(self, bits: u64) -> Integer

Right-shifts an Integer (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.

§

type Output = Integer

The resulting type after applying the >> operator.
§

impl<'a> Shr<u8> for &Integer

§

fn shr(self, bits: u8) -> Integer

Right-shifts an Integer (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(1)$

where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits).

§Examples

See here.

§

type Output = Integer

The resulting type after applying the >> operator.
§

impl Shr<u8> for Integer

§

fn shr(self, bits: u8) -> Integer

Right-shifts an Integer (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.

§

type Output = Integer

The resulting type after applying the >> operator.
§

impl<'a> Shr<usize> for &Integer

§

fn shr(self, bits: usize) -> Integer

Right-shifts an Integer (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(1)$

where $T$ is time, $M$ is additional memory and $n$ is max(1, self.significant_bits() - bits).

§Examples

See here.

§

type Output = Integer

The resulting type after applying the >> operator.
§

impl Shr<usize> for Integer

§

fn shr(self, bits: usize) -> Integer

Right-shifts an Integer (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.

§

type Output = Integer

The resulting type after applying the >> operator.
§

impl ShrAssign<i128> for Integer

§

fn shr_assign(&mut self, bits: i128)

Right-shifts an Integer (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.

§

impl ShrAssign<i16> for Integer

§

fn shr_assign(&mut self, bits: i16)

Right-shifts an Integer (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.

§

impl ShrAssign<i32> for Integer

§

fn shr_assign(&mut self, bits: i32)

Right-shifts an Integer (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.

§

impl ShrAssign<i64> for Integer

§

fn shr_assign(&mut self, bits: i64)

Right-shifts an Integer (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.

§

impl ShrAssign<i8> for Integer

§

fn shr_assign(&mut self, bits: i8)

Right-shifts an Integer (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.

§

impl ShrAssign<isize> for Integer

§

fn shr_assign(&mut self, bits: isize)

Right-shifts an Integer (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.

§

impl ShrAssign<u128> for Integer

§

fn shr_assign(&mut self, bits: u128)

Right-shifts an Integer (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.

§

impl ShrAssign<u16> for Integer

§

fn shr_assign(&mut self, bits: u16)

Right-shifts an Integer (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.

§

impl ShrAssign<u32> for Integer

§

fn shr_assign(&mut self, bits: u32)

Right-shifts an Integer (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.

§

impl ShrAssign<u64> for Integer

§

fn shr_assign(&mut self, bits: u64)

Right-shifts an Integer (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.

§

impl ShrAssign<u8> for Integer

§

fn shr_assign(&mut self, bits: u8)

Right-shifts an Integer (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.

§

impl ShrAssign<usize> for Integer

§

fn shr_assign(&mut self, bits: usize)

Right-shifts an Integer (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.

§

impl<'a> ShrRound<i128> for &Integer

§

fn shr_round(self, bits: i128, rm: RoundingMode) -> (Integer, Ordering)

Shifts an Integer 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 Floor is equivalent to using >>. To test whether 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}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$f(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$f(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, k, \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 \Z$.

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 Exact but self is not divisible by $2^k$.

§Examples

See here.

§

type Output = Integer

§

impl ShrRound<i128> for Integer

§

fn shr_round(self, bits: i128, rm: RoundingMode) -> (Integer, Ordering)

Shifts an Integer 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 Floor is equivalent to using >>. To test whether 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}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$f(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$f(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, k, \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 \Z$.

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 Exact but self is not divisible by $2^k$.

§Examples

See here.

§

type Output = Integer

§

impl<'a> ShrRound<i16> for &Integer

§

fn shr_round(self, bits: i16, rm: RoundingMode) -> (Integer, Ordering)

Shifts an Integer 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 Floor is equivalent to using >>. To test whether 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}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$f(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$f(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, k, \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 \Z$.

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 Exact but self is not divisible by $2^k$.

§Examples

See here.

§

type Output = Integer

§

impl ShrRound<i16> for Integer

§

fn shr_round(self, bits: i16, rm: RoundingMode) -> (Integer, Ordering)

Shifts an Integer 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 Floor is equivalent to using >>. To test whether 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}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$f(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$f(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, k, \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 \Z$.

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 Exact but self is not divisible by $2^k$.

§Examples

See here.

§

type Output = Integer

§

impl<'a> ShrRound<i32> for &Integer

§

fn shr_round(self, bits: i32, rm: RoundingMode) -> (Integer, Ordering)

Shifts an Integer 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 Floor is equivalent to using >>. To test whether 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}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$f(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$f(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, k, \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 \Z$.

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 Exact but self is not divisible by $2^k$.

§Examples

See here.

§

type Output = Integer

§

impl ShrRound<i32> for Integer

§

fn shr_round(self, bits: i32, rm: RoundingMode) -> (Integer, Ordering)

Shifts an Integer 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 Floor is equivalent to using >>. To test whether 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}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$f(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$f(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, k, \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 \Z$.

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 Exact but self is not divisible by $2^k$.

§Examples

See here.

§

type Output = Integer

§

impl<'a> ShrRound<i64> for &Integer

§

fn shr_round(self, bits: i64, rm: RoundingMode) -> (Integer, Ordering)

Shifts an Integer 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 Floor is equivalent to using >>. To test whether 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}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$f(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$f(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, k, \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 \Z$.

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 Exact but self is not divisible by $2^k$.

§Examples

See here.

§

type Output = Integer

§

impl ShrRound<i64> for Integer

§

fn shr_round(self, bits: i64, rm: RoundingMode) -> (Integer, Ordering)

Shifts an Integer 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 Floor is equivalent to using >>. To test whether 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}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$f(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$f(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, k, \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 \Z$.

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 Exact but self is not divisible by $2^k$.

§Examples

See here.

§

type Output = Integer

§

impl<'a> ShrRound<i8> for &Integer

§

fn shr_round(self, bits: i8, rm: RoundingMode) -> (Integer, Ordering)

Shifts an Integer 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 Floor is equivalent to using >>. To test whether 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}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$f(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$f(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, k, \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 \Z$.

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 Exact but self is not divisible by $2^k$.

§Examples

See here.

§

type Output = Integer

§

impl ShrRound<i8> for Integer

§

fn shr_round(self, bits: i8, rm: RoundingMode) -> (Integer, Ordering)

Shifts an Integer 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 Floor is equivalent to using >>. To test whether 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}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$f(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$f(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, k, \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 \Z$.

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 Exact but self is not divisible by $2^k$.

§Examples

See here.

§

type Output = Integer

§

impl<'a> ShrRound<isize> for &Integer

§

fn shr_round(self, bits: isize, rm: RoundingMode) -> (Integer, Ordering)

Shifts an Integer 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 Floor is equivalent to using >>. To test whether 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}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$f(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$f(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, k, \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 \Z$.

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 Exact but self is not divisible by $2^k$.

§Examples

See here.

§

type Output = Integer

§

impl ShrRound<isize> for Integer

§

fn shr_round(self, bits: isize, rm: RoundingMode) -> (Integer, Ordering)

Shifts an Integer 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 Floor is equivalent to using >>. To test whether 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}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$f(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$f(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, k, \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 \Z$.

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 Exact but self is not divisible by $2^k$.

§Examples

See here.

§

type Output = Integer

§

impl<'a> ShrRound<u128> for &Integer

§

fn shr_round(self, bits: u128, rm: RoundingMode) -> (Integer, Ordering)

Shifts an Integer 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 Floor is equivalent to using >>. To test whether 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}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$f(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$f(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, k, \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 \Z$.

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 Exact but self is not divisible by $2^k$.

§Examples

See here.

§

type Output = Integer

§

impl ShrRound<u128> for Integer

§

fn shr_round(self, bits: u128, rm: RoundingMode) -> (Integer, Ordering)

Shifts an Integer 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 Floor is equivalent to using >>. To test whether 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}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$f(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$f(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, k, \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 \Z$.

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 Exact but self is not divisible by $2^k$.

§Examples

See here.

§

type Output = Integer

§

impl<'a> ShrRound<u16> for &Integer

§

fn shr_round(self, bits: u16, rm: RoundingMode) -> (Integer, Ordering)

Shifts an Integer 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 Floor is equivalent to using >>. To test whether 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}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$f(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$f(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, k, \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 \Z$.

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 Exact but self is not divisible by $2^k$.

§Examples

See here.

§

type Output = Integer

§

impl ShrRound<u16> for Integer

§

fn shr_round(self, bits: u16, rm: RoundingMode) -> (Integer, Ordering)

Shifts an Integer 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 Floor is equivalent to using >>. To test whether 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}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$f(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$f(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, k, \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 \Z$.

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 Exact but self is not divisible by $2^k$.

§Examples

See here.

§

type Output = Integer

§

impl<'a> ShrRound<u32> for &Integer

§

fn shr_round(self, bits: u32, rm: RoundingMode) -> (Integer, Ordering)

Shifts an Integer 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 Floor is equivalent to using >>. To test whether 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}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$f(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$f(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, k, \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 \Z$.

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 Exact but self is not divisible by $2^k$.

§Examples

See here.

§

type Output = Integer

§

impl ShrRound<u32> for Integer

§

fn shr_round(self, bits: u32, rm: RoundingMode) -> (Integer, Ordering)

Shifts an Integer 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 Floor is equivalent to using >>. To test whether 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}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$f(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$f(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, k, \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 \Z$.

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 Exact but self is not divisible by $2^k$.

§Examples

See here.

§

type Output = Integer

§

impl<'a> ShrRound<u64> for &Integer

§

fn shr_round(self, bits: u64, rm: RoundingMode) -> (Integer, Ordering)

Shifts an Integer 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 Floor is equivalent to using >>. To test whether 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}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$f(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$f(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, k, \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 \Z$.

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 Exact but self is not divisible by $2^k$.

§Examples

See here.

§

type Output = Integer

§

impl ShrRound<u64> for Integer

§

fn shr_round(self, bits: u64, rm: RoundingMode) -> (Integer, Ordering)

Shifts an Integer 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 Floor is equivalent to using >>. To test whether 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}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$f(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$f(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, k, \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 \Z$.

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 Exact but self is not divisible by $2^k$.

§Examples

See here.

§

type Output = Integer

§

impl<'a> ShrRound<u8> for &Integer

§

fn shr_round(self, bits: u8, rm: RoundingMode) -> (Integer, Ordering)

Shifts an Integer 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 Floor is equivalent to using >>. To test whether 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}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$f(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$f(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, k, \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 \Z$.

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 Exact but self is not divisible by $2^k$.

§Examples

See here.

§

type Output = Integer

§

impl ShrRound<u8> for Integer

§

fn shr_round(self, bits: u8, rm: RoundingMode) -> (Integer, Ordering)

Shifts an Integer 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 Floor is equivalent to using >>. To test whether 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}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$f(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$f(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, k, \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 \Z$.

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 Exact but self is not divisible by $2^k$.

§Examples

See here.

§

type Output = Integer

§

impl<'a> ShrRound<usize> for &Integer

§

fn shr_round(self, bits: usize, rm: RoundingMode) -> (Integer, Ordering)

Shifts an Integer 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 Floor is equivalent to using >>. To test whether 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}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$f(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$f(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, k, \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 \Z$.

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 Exact but self is not divisible by $2^k$.

§Examples

See here.

§

type Output = Integer

§

impl ShrRound<usize> for Integer

§

fn shr_round(self, bits: usize, rm: RoundingMode) -> (Integer, Ordering)

Shifts an Integer 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 Floor is equivalent to using >>. To test whether 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}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$f(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$f(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, k, \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 \Z$.

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 Exact but self is not divisible by $2^k$.

§Examples

See here.

§

type Output = Integer

§

impl ShrRoundAssign<i128> for Integer

§

fn shr_round_assign(&mut self, bits: i128, rm: RoundingMode) -> Ordering

Shifts an Integer 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 Floor is equivalent to using >>. To test whether 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 Exact but self is not divisible by $2^k$.

§Examples

See here.

§

impl ShrRoundAssign<i16> for Integer

§

fn shr_round_assign(&mut self, bits: i16, rm: RoundingMode) -> Ordering

Shifts an Integer 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 Floor is equivalent to using >>. To test whether 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 Exact but self is not divisible by $2^k$.

§Examples

See here.

§

impl ShrRoundAssign<i32> for Integer

§

fn shr_round_assign(&mut self, bits: i32, rm: RoundingMode) -> Ordering

Shifts an Integer 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 Floor is equivalent to using >>. To test whether 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 Exact but self is not divisible by $2^k$.

§Examples

See here.

§

impl ShrRoundAssign<i64> for Integer

§

fn shr_round_assign(&mut self, bits: i64, rm: RoundingMode) -> Ordering

Shifts an Integer 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 Floor is equivalent to using >>. To test whether 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 Exact but self is not divisible by $2^k$.

§Examples

See here.

§

impl ShrRoundAssign<i8> for Integer

§

fn shr_round_assign(&mut self, bits: i8, rm: RoundingMode) -> Ordering

Shifts an Integer 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 Floor is equivalent to using >>. To test whether 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 Exact but self is not divisible by $2^k$.

§Examples

See here.

§

impl ShrRoundAssign<isize> for Integer

§

fn shr_round_assign(&mut self, bits: isize, rm: RoundingMode) -> Ordering

Shifts an Integer 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 Floor is equivalent to using >>. To test whether 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 Exact but self is not divisible by $2^k$.

§Examples

See here.

§

impl ShrRoundAssign<u128> for Integer

§

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. Passing Floor is equivalent to using >>=. To test whether Exact can be passed, use self.divisible_by_power_of_2(bits). An Ordering is returned, indicating whether the assigned value is less than, equal to, or greater than the exact value.

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 Exact but self is not divisible by $2^k$.

§Examples

See here.

§

impl ShrRoundAssign<u16> for Integer

§

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. Passing Floor is equivalent to using >>=. To test whether Exact can be passed, use self.divisible_by_power_of_2(bits). An Ordering is returned, indicating whether the assigned value is less than, equal to, or greater than the exact value.

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 Exact but self is not divisible by $2^k$.

§Examples

See here.

§

impl ShrRoundAssign<u32> for Integer

§

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. Passing Floor is equivalent to using >>=. To test whether Exact can be passed, use self.divisible_by_power_of_2(bits). An Ordering is returned, indicating whether the assigned value is less than, equal to, or greater than the exact value.

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 Exact but self is not divisible by $2^k$.

§Examples

See here.

§

impl ShrRoundAssign<u64> for Integer

§

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. Passing Floor is equivalent to using >>=. To test whether Exact can be passed, use self.divisible_by_power_of_2(bits). An Ordering is returned, indicating whether the assigned value is less than, equal to, or greater than the exact value.

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 Exact but self is not divisible by $2^k$.

§Examples

See here.

§

impl ShrRoundAssign<u8> for Integer

§

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. Passing Floor is equivalent to using >>=. To test whether Exact can be passed, use self.divisible_by_power_of_2(bits). An Ordering is returned, indicating whether the assigned value is less than, equal to, or greater than the exact value.

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 Exact but self is not divisible by $2^k$.

§Examples

See here.

§

impl ShrRoundAssign<usize> for Integer

§

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. Passing Floor is equivalent to using >>=. To test whether Exact can be passed, use self.divisible_by_power_of_2(bits). An Ordering is returned, indicating whether the assigned value is less than, equal to, or greater than the exact value.

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 Exact but self is not divisible by $2^k$.

§Examples

See here.

§

impl Sign for Integer

§

fn sign(&self) -> Ordering

Compares an Integer to zero.

Returns Greater, Equal, or Less, depending on whether the Integer is positive, zero, or negative, respectively.

§Worst-case complexity

Constant time and additional memory.

§Examples
use core::cmp::Ordering::*;
use malachite_base::num::arithmetic::traits::Sign;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::integer::Integer;

assert_eq!(Integer::ZERO.sign(), Equal);
assert_eq!(Integer::from(123).sign(), Greater);
assert_eq!(Integer::from(-123).sign(), Less);
§

impl SignificantBits for &Integer

§

fn significant_bits(self) -> u64

Returns the number of significant bits of an Integer’s absolute value.

$$ f(n) = \begin{cases} 0 & \text{if} \quad n = 0, \\ \lfloor \log_2 |n| \rfloor + 1 & \text{otherwise}. \end{cases} $$

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_base::num::logic::traits::SignificantBits;
use malachite_nz::integer::Integer;

assert_eq!(Integer::ZERO.significant_bits(), 0);
assert_eq!(Integer::from(100).significant_bits(), 7);
assert_eq!(Integer::from(-100).significant_bits(), 7);
§

impl Square for &Integer

§

fn square(self) -> Integer

Squares an Integer, 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::integer::Integer;

assert_eq!((&Integer::ZERO).square(), 0);
assert_eq!((&Integer::from(123)).square(), 15129);
assert_eq!((&Integer::from(-123)).square(), 15129);
§

type Output = Integer

§

impl Square for Integer

§

fn square(self) -> Integer

Squares an Integer, 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::integer::Integer;

assert_eq!(Integer::ZERO.square(), 0);
assert_eq!(Integer::from(123).square(), 15129);
assert_eq!(Integer::from(-123).square(), 15129);
§

type Output = Integer

§

impl SquareAssign for Integer

§

fn square_assign(&mut self)

Squares an Integer 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::integer::Integer;

let mut x = Integer::ZERO;
x.square_assign();
assert_eq!(x, 0);

let mut x = Integer::from(123);
x.square_assign();
assert_eq!(x, 15129);

let mut x = Integer::from(-123);
x.square_assign();
assert_eq!(x, 15129);
§

impl Sub<&Integer> for &Integer

§

fn sub(self, other: &Integer) -> Integer

Subtracts an Integer by another Integer, 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::integer::Integer;

assert_eq!(&Integer::ZERO - &Integer::from(123), -123);
assert_eq!(&Integer::from(123) - &Integer::ZERO, 123);
assert_eq!(&Integer::from(456) - &Integer::from(-123), 579);
assert_eq!(
    &-Integer::from(10u32).pow(12) - &(-Integer::from(10u32).pow(12) * Integer::from(2u32)),
    1000000000000u64
);
§

type Output = Integer

The resulting type after applying the - operator.
§

impl Sub<&Integer> for Integer

§

fn sub(self, other: &Integer) -> Integer

Subtracts an Integer by another Integer, 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::integer::Integer;

assert_eq!(Integer::ZERO - &Integer::from(123), -123);
assert_eq!(Integer::from(123) - &Integer::ZERO, 123);
assert_eq!(Integer::from(456) - &Integer::from(-123), 579);
assert_eq!(
    -Integer::from(10u32).pow(12) - &(-Integer::from(10u32).pow(12) * Integer::from(2u32)),
    1000000000000u64
);
§

type Output = Integer

The resulting type after applying the - operator.
§

impl Sub<Integer> for &Integer

§

fn sub(self, other: Integer) -> Integer

Subtracts an Integer by another Integer, 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::integer::Integer;

assert_eq!(&Integer::ZERO - Integer::from(123), -123);
assert_eq!(&Integer::from(123) - Integer::ZERO, 123);
assert_eq!(&Integer::from(456) - Integer::from(-123), 579);
assert_eq!(
    &-Integer::from(10u32).pow(12) - -Integer::from(10u32).pow(12) * Integer::from(2u32),
    1000000000000u64
);
§

type Output = Integer

The resulting type after applying the - operator.
§

impl Sub for Integer

§

fn sub(self, other: Integer) -> Integer

Subtracts an Integer by another Integer, 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::integer::Integer;

assert_eq!(Integer::ZERO - Integer::from(123), -123);
assert_eq!(Integer::from(123) - Integer::ZERO, 123);
assert_eq!(Integer::from(456) - Integer::from(-123), 579);
assert_eq!(
    -Integer::from(10u32).pow(12) - -Integer::from(10u32).pow(12) * Integer::from(2u32),
    1000000000000u64
);
§

type Output = Integer

The resulting type after applying the - operator.
§

impl SubAssign<&Integer> for Integer

§

fn sub_assign(&mut self, other: &Integer)

Subtracts an Integer by another Integer in place, taking the Integer 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::integer::Integer;

let mut x = Integer::ZERO;
x -= &(-Integer::from(10u32).pow(12));
x -= &(Integer::from(10u32).pow(12) * Integer::from(2u32));
x -= &(-Integer::from(10u32).pow(12) * Integer::from(3u32));
x -= &(Integer::from(10u32).pow(12) * Integer::from(4u32));
assert_eq!(x, -2000000000000i64);
§

impl SubAssign for Integer

§

fn sub_assign(&mut self, other: Integer)

Subtracts an Integer by another Integer in place, taking the Integer 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)

§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::integer::Integer;

let mut x = Integer::ZERO;
x -= -Integer::from(10u32).pow(12);
x -= Integer::from(10u32).pow(12) * Integer::from(2u32);
x -= -Integer::from(10u32).pow(12) * Integer::from(3u32);
x -= Integer::from(10u32).pow(12) * Integer::from(4u32);
assert_eq!(x, -2000000000000i64);
§

impl<'a> SubMul<&'a Integer> for Integer

§

fn sub_mul(self, y: &'a Integer, z: Integer) -> Integer

Subtracts an Integer by the product of two other Integers, 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::{Pow, SubMul};
use malachite_nz::integer::Integer;

assert_eq!(
    Integer::from(10u32).sub_mul(&Integer::from(3u32), Integer::from(-4)),
    22
);
assert_eq!(
    (-Integer::from(10u32).pow(12))
        .sub_mul(&Integer::from(-0x10000), -Integer::from(10u32).pow(12)),
    -65537000000000000i64
);
§

type Output = Integer

§

impl SubMul<&Integer, &Integer> for &Integer

§

fn sub_mul(self, y: &Integer, z: &Integer) -> Integer

Subtracts an Integer by the product of two other Integers, 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::{Pow, SubMul};
use malachite_nz::integer::Integer;

assert_eq!(
    (&Integer::from(10u32)).sub_mul(&Integer::from(3u32), &Integer::from(-4)),
    22
);
assert_eq!(
    (&-Integer::from(10u32).pow(12))
        .sub_mul(&Integer::from(-0x10000), &-Integer::from(10u32).pow(12)),
    -65537000000000000i64
);
§

type Output = Integer

§

impl SubMul<&Integer, &Integer> for Integer

§

fn sub_mul(self, y: &Integer, z: &Integer) -> Integer

Subtracts an Integer by the product of two other Integers, 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::{Pow, SubMul};
use malachite_nz::integer::Integer;

assert_eq!(
    Integer::from(10u32).sub_mul(&Integer::from(3u32), &Integer::from(-4)),
    22
);
assert_eq!(
    (-Integer::from(10u32).pow(12))
        .sub_mul(&Integer::from(-0x10000), &-Integer::from(10u32).pow(12)),
    -65537000000000000i64
);
§

type Output = Integer

§

impl<'a> SubMul<Integer, &'a Integer> for Integer

§

fn sub_mul(self, y: Integer, z: &'a Integer) -> Integer

Subtracts an Integer by the product of two other Integers, 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::{Pow, SubMul};
use malachite_nz::integer::Integer;

assert_eq!(
    Integer::from(10u32).sub_mul(Integer::from(3u32), &Integer::from(-4)),
    22
);
assert_eq!(
    (-Integer::from(10u32).pow(12))
        .sub_mul(Integer::from(-0x10000), &-Integer::from(10u32).pow(12)),
    -65537000000000000i64
);
§

type Output = Integer

§

impl SubMul for Integer

§

fn sub_mul(self, y: Integer, z: Integer) -> Integer

Subtracts an Integer by the product of two other Integers, 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::{Pow, SubMul};
use malachite_nz::integer::Integer;

assert_eq!(
    Integer::from(10u32).sub_mul(Integer::from(3u32), Integer::from(-4)),
    22
);
assert_eq!(
    (-Integer::from(10u32).pow(12))
        .sub_mul(Integer::from(-0x10000), -Integer::from(10u32).pow(12)),
    -65537000000000000i64
);
§

type Output = Integer

§

impl<'a> SubMulAssign<&'a Integer> for Integer

§

fn sub_mul_assign(&mut self, y: &'a Integer, z: Integer)

Subtracts the product of two other Integers from an Integer in place, taking the first Integer 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::{Pow, SubMulAssign};
use malachite_nz::integer::Integer;

let mut x = Integer::from(10u32);
x.sub_mul_assign(&Integer::from(3u32), Integer::from(-4));
assert_eq!(x, 22);

let mut x = -Integer::from(10u32).pow(12);
x.sub_mul_assign(&Integer::from(-0x10000), -Integer::from(10u32).pow(12));
assert_eq!(x, -65537000000000000i64);
§

impl<'a, 'b> SubMulAssign<&'a Integer, &'b Integer> for Integer

§

fn sub_mul_assign(&mut self, y: &'a Integer, z: &'b Integer)

Subtracts the product of two other Integers from an Integer in place, taking both Integers 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::{Pow, SubMulAssign};
use malachite_nz::integer::Integer;

let mut x = Integer::from(10u32);
x.sub_mul_assign(&Integer::from(3u32), &Integer::from(-4));
assert_eq!(x, 22);

let mut x = -Integer::from(10u32).pow(12);
x.sub_mul_assign(&Integer::from(-0x10000), &(-Integer::from(10u32).pow(12)));
assert_eq!(x, -65537000000000000i64);
§

impl<'a> SubMulAssign<Integer, &'a Integer> for Integer

§

fn sub_mul_assign(&mut self, y: Integer, z: &'a Integer)

Subtracts the product of two other Integers from an Integer in place, taking the first Integer 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::{Pow, SubMulAssign};
use malachite_nz::integer::Integer;

let mut x = Integer::from(10u32);
x.sub_mul_assign(Integer::from(3u32), &Integer::from(-4));
assert_eq!(x, 22);

let mut x = -Integer::from(10u32).pow(12);
x.sub_mul_assign(Integer::from(-0x10000), &(-Integer::from(10u32).pow(12)));
assert_eq!(x, -65537000000000000i64);
§

impl SubMulAssign for Integer

§

fn sub_mul_assign(&mut self, y: Integer, z: Integer)

Subtracts the product of two other Integers from an Integer in place, taking both Integers 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::{Pow, SubMulAssign};
use malachite_nz::integer::Integer;

let mut x = Integer::from(10u32);
x.sub_mul_assign(Integer::from(3u32), Integer::from(-4));
assert_eq!(x, 22);

let mut x = -Integer::from(10u32).pow(12);
x.sub_mul_assign(Integer::from(-0x10000), -Integer::from(10u32).pow(12));
assert_eq!(x, -65537000000000000i64);
§

impl<'a> Sum<&'a Integer> for Integer

§

fn sum<I>(xs: I) -> Integer
where I: Iterator<Item = &'a Integer>,

Adds up all the Integers in an iterator of Integer 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 Integer::sum(xs.map(Integer::significant_bits)).

§Examples
use core::iter::Sum;
use malachite_base::vecs::vec_from_str;
use malachite_nz::integer::Integer;

assert_eq!(
    Integer::sum(vec_from_str::<Integer>("[2, -3, 5, 7]").unwrap().iter()),
    11
);
§

impl Sum for Integer

§

fn sum<I>(xs: I) -> Integer
where I: Iterator<Item = Integer>,

Adds up all the Integers 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 Integer::sum(xs.map(Integer::significant_bits)).

§Examples
use core::iter::Sum;
use malachite_base::vecs::vec_from_str;
use malachite_nz::integer::Integer;

assert_eq!(
    Integer::sum(
        vec_from_str::<Integer>("[2, -3, 5, 7]")
            .unwrap()
            .into_iter()
    ),
    11
);
§

impl ToSci for Integer

§

fn fmt_sci_valid(&self, options: ToSciOptions) -> bool

Determines whether an Integer 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::integer::Integer;

let mut options = ToSciOptions::default();
assert!(Integer::from(123).fmt_sci_valid(options));
assert!(Integer::from(u128::MAX).fmt_sci_valid(options));
// u128::MAX has more than 16 significant digits
options.set_rounding_mode(Exact);
assert!(!Integer::from(u128::MAX).fmt_sci_valid(options));
options.set_precision(50);
assert!(Integer::from(u128::MAX).fmt_sci_valid(options));
§

fn fmt_sci( &self, f: &mut Formatter<'_>, options: ToSciOptions, ) -> Result<(), Error>

Converts an Integer 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 an Integer.

§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::integer::Integer;

assert_eq!(
    Integer::from(u128::MAX).to_sci().to_string(),
    "3.402823669209385e38"
);
assert_eq!(
    Integer::from(i128::MIN).to_sci().to_string(),
    "-1.701411834604692e38"
);

let n = Integer::from(123456u32);
let mut options = ToSciOptions::default();
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(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");
§

fn to_sci_with_options(&self, options: ToSciOptions) -> SciWrapper<'_, Self>

Converts a number to a string, possibly in scientific notation.
§

fn to_sci(&self) -> SciWrapper<'_, Self>

Converts a number to a string, possibly in scientific notation, using the default [ToSciOptions].
§

impl ToStringBase for Integer

§

fn to_string_base(&self, base: u8) -> String

Converts an Integer to a String using a specified base.

Digits from 0 to 9 become chars from '0' to '9'. Digits from 10 to 35 become the lowercase chars '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::integer::Integer;

assert_eq!(Integer::from(1000).to_string_base(2), "1111101000");
assert_eq!(Integer::from(1000).to_string_base(10), "1000");
assert_eq!(Integer::from(1000).to_string_base(36), "rs");

assert_eq!(Integer::from(-1000).to_string_base(2), "-1111101000");
assert_eq!(Integer::from(-1000).to_string_base(10), "-1000");
assert_eq!(Integer::from(-1000).to_string_base(36), "-rs");
§

fn to_string_base_upper(&self, base: u8) -> String

Converts an Integer to a String using a specified base.

Digits from 0 to 9 become chars from '0' to '9'. Digits from 10 to 35 become the uppercase chars '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::integer::Integer;

assert_eq!(Integer::from(1000).to_string_base_upper(2), "1111101000");
assert_eq!(Integer::from(1000).to_string_base_upper(10), "1000");
assert_eq!(Integer::from(1000).to_string_base_upper(36), "RS");

assert_eq!(Integer::from(-1000).to_string_base_upper(2), "-1111101000");
assert_eq!(Integer::from(-1000).to_string_base_upper(10), "-1000");
assert_eq!(Integer::from(-1000).to_string_base_upper(36), "-RS");
§

impl<'a> TryFrom<&'a Integer> for Natural

§

fn try_from( value: &'a Integer, ) -> Result<Natural, <Natural as TryFrom<&'a Integer>>::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

The type returned in the event of a conversion error.
§

impl<'a> TryFrom<&'a Integer> for u32

§

fn try_from( value: &Integer, ) -> Result<u32, <u32 as TryFrom<&'a Integer>>::Error>

Converts an Integer to an unsigned primitive integer, returning an error if the Integer cannot be represented.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

type Error = UnsignedFromIntegerError

The type returned in the event of a conversion error.
§

impl TryFrom<&Rational> for Integer

§

fn try_from( x: &Rational, ) -> Result<Integer, <Integer as TryFrom<&Rational>>::Error>

Converts a [Rational] to an Integer, taking the [Rational] by reference. If the [Rational] is not an integer, 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 x.significant_bits().

§Examples
use malachite_nz::integer::Integer;
use malachite_q::conversion::integer_from_rational::IntegerFromRationalError;
use malachite_q::Rational;

assert_eq!(Integer::try_from(&Rational::from(123)).unwrap(), 123);
assert_eq!(Integer::try_from(&Rational::from(-123)).unwrap(), -123);
assert_eq!(
    Integer::try_from(&Rational::from_signeds(22, 7)),
    Err(IntegerFromRationalError)
);
§

type Error = IntegerFromRationalError

The type returned in the event of a conversion error.
§

impl TryFrom<Integer> for Natural

§

fn try_from( value: Integer, ) -> Result<Natural, <Natural as TryFrom<Integer>>::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

The type returned in the event of a conversion error.
§

impl TryFrom<Rational> for Integer

§

fn try_from( x: Rational, ) -> Result<Integer, <Integer as TryFrom<Rational>>::Error>

Converts a [Rational] to an Integer, taking the [Rational] by value. If the [Rational] is not an integer, an error is returned.

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_nz::integer::Integer;
use malachite_q::conversion::integer_from_rational::IntegerFromRationalError;
use malachite_q::Rational;

assert_eq!(Integer::try_from(Rational::from(123)).unwrap(), 123);
assert_eq!(Integer::try_from(Rational::from(-123)).unwrap(), -123);
assert_eq!(
    Integer::try_from(Rational::from_signeds(22, 7)),
    Err(IntegerFromRationalError)
);
§

type Error = IntegerFromRationalError

The type returned in the event of a conversion error.
§

impl TryFrom<SerdeInteger> for Integer

§

type Error = String

The type returned in the event of a conversion error.
§

fn try_from(s: SerdeInteger) -> Result<Integer, String>

Performs the conversion.
§

impl TryFrom<f32> for Integer

§

fn try_from(value: f32) -> Result<Integer, <Integer as TryFrom<f32>>::Error>

Converts a primitive float to an Integer.

If the input isn’t exactly equal to some Integer, 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.sci_exponent().

§Examples

See here.

§

type Error = SignedFromFloatError

The type returned in the event of a conversion error.
§

impl TryFrom<f64> for Integer

§

fn try_from(value: f64) -> Result<Integer, <Integer as TryFrom<f64>>::Error>

Converts a primitive float to an Integer.

If the input isn’t exactly equal to some Integer, 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.sci_exponent().

§Examples

See here.

§

type Error = SignedFromFloatError

The type returned in the event of a conversion error.
§

impl Two for Integer

The constant 2.

§

const TWO: Integer

§

impl UnsignedAbs for &Integer

§

fn unsigned_abs(self) -> Natural

Takes the absolute value of an Integer, taking the Integer by reference and converting the result to a Natural.

$$ 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::arithmetic::traits::UnsignedAbs;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::integer::Integer;

assert_eq!((&Integer::ZERO).unsigned_abs(), 0);
assert_eq!((&Integer::from(123)).unsigned_abs(), 123);
assert_eq!((&Integer::from(-123)).unsigned_abs(), 123);
§

type Output = Natural

§

impl UnsignedAbs for Integer

§

fn unsigned_abs(self) -> Natural

Takes the absolute value of an Integer, taking the Integer by value and converting the result to a Natural.

$$ f(x) = |x|. $$

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::num::arithmetic::traits::UnsignedAbs;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::integer::Integer;

assert_eq!(Integer::ZERO.unsigned_abs(), 0);
assert_eq!(Integer::from(123).unsigned_abs(), 123);
assert_eq!(Integer::from(-123).unsigned_abs(), 123);
§

type Output = Natural

§

impl UpperHex for Integer

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Converts an Integer 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 core::str::FromStr;
use malachite_base::num::basic::traits::Zero;
use malachite_base::strings::ToUpperHexString;
use malachite_nz::integer::Integer;

assert_eq!(Integer::ZERO.to_upper_hex_string(), "0");
assert_eq!(Integer::from(123).to_upper_hex_string(), "7B");
assert_eq!(
    Integer::from_str("1000000000000")
        .unwrap()
        .to_upper_hex_string(),
    "E8D4A51000"
);
assert_eq!(format!("{:07X}", Integer::from(123)), "000007B");
assert_eq!(Integer::from(-123).to_upper_hex_string(), "-7B");
assert_eq!(
    Integer::from_str("-1000000000000")
        .unwrap()
        .to_upper_hex_string(),
    "-E8D4A51000"
);
assert_eq!(format!("{:07X}", Integer::from(-123)), "-00007B");

assert_eq!(format!("{:#X}", Integer::ZERO), "0x0");
assert_eq!(format!("{:#X}", Integer::from(123)), "0x7B");
assert_eq!(
    format!("{:#X}", Integer::from_str("1000000000000").unwrap()),
    "0xE8D4A51000"
);
assert_eq!(format!("{:#07X}", Integer::from(123)), "0x0007B");
assert_eq!(format!("{:#X}", Integer::from(-123)), "-0x7B");
assert_eq!(
    format!("{:#X}", Integer::from_str("-1000000000000").unwrap()),
    "-0xE8D4A51000"
);
assert_eq!(format!("{:#07X}", Integer::from(-123)), "-0x007B");
§

impl<'a> WrappingFrom<&'a Integer> for u32

§

fn wrapping_from(value: &Integer) -> u32

Converts an Integer to an unsigned primitive integer, wrapping modulo $2^W$, where $W$ is the width of the primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

§

impl Zero for Integer

The constant 0.

§

impl Eq for Integer

§

impl StructuralPartialEq for Integer

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<T, U> ExactFrom<T> for U
where U: TryFrom<T>,

§

fn exact_from(value: T) -> U

§

impl<T, U> ExactInto<U> for T
where U: ExactFrom<T>,

§

fn exact_into(self) -> U

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T, U> OverflowingInto<U> for T
where U: OverflowingFrom<T>,

§

fn overflowing_into(self) -> (U, bool)

§

impl<T> Paint for T
where T: ?Sized,

§

fn fg(&self, value: Color) -> Painted<&T>

Returns a styled value derived from self with the foreground set to value.

This method should be used rarely. Instead, prefer to use color-specific builder methods like red() and green(), which have the same functionality but are pithier.

§Example

Set foreground color to white using fg():

use yansi::{Paint, Color};

painted.fg(Color::White);

Set foreground color to white using white().

use yansi::Paint;

painted.white();
§

fn primary(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Primary].

§Example
println!("{}", value.primary());
§

fn fixed(&self, color: u8) -> Painted<&T>

Returns self with the fg() set to [Color :: Fixed].

§Example
println!("{}", value.fixed(color));
§

fn rgb(&self, r: u8, g: u8, b: u8) -> Painted<&T>

Returns self with the fg() set to [Color :: Rgb].

§Example
println!("{}", value.rgb(r, g, b));
§

fn black(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Black].

§Example
println!("{}", value.black());
§

fn red(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Red].

§Example
println!("{}", value.red());
§

fn green(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Green].

§Example
println!("{}", value.green());
§

fn yellow(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Yellow].

§Example
println!("{}", value.yellow());
§

fn blue(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Blue].

§Example
println!("{}", value.blue());
§

fn magenta(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Magenta].

§Example
println!("{}", value.magenta());
§

fn cyan(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Cyan].

§Example
println!("{}", value.cyan());
§

fn white(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: White].

§Example
println!("{}", value.white());
§

fn bright_black(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightBlack].

§Example
println!("{}", value.bright_black());
§

fn bright_red(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightRed].

§Example
println!("{}", value.bright_red());
§

fn bright_green(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightGreen].

§Example
println!("{}", value.bright_green());
§

fn bright_yellow(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightYellow].

§Example
println!("{}", value.bright_yellow());
§

fn bright_blue(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightBlue].

§Example
println!("{}", value.bright_blue());
§

fn bright_magenta(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightMagenta].

§Example
println!("{}", value.bright_magenta());
§

fn bright_cyan(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightCyan].

§Example
println!("{}", value.bright_cyan());
§

fn bright_white(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightWhite].

§Example
println!("{}", value.bright_white());
§

fn bg(&self, value: Color) -> Painted<&T>

Returns a styled value derived from self with the background set to value.

This method should be used rarely. Instead, prefer to use color-specific builder methods like on_red() and on_green(), which have the same functionality but are pithier.

§Example

Set background color to red using fg():

use yansi::{Paint, Color};

painted.bg(Color::Red);

Set background color to red using on_red().

use yansi::Paint;

painted.on_red();
§

fn on_primary(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Primary].

§Example
println!("{}", value.on_primary());
§

fn on_fixed(&self, color: u8) -> Painted<&T>

Returns self with the bg() set to [Color :: Fixed].

§Example
println!("{}", value.on_fixed(color));
§

fn on_rgb(&self, r: u8, g: u8, b: u8) -> Painted<&T>

Returns self with the bg() set to [Color :: Rgb].

§Example
println!("{}", value.on_rgb(r, g, b));
§

fn on_black(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Black].

§Example
println!("{}", value.on_black());
§

fn on_red(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Red].

§Example
println!("{}", value.on_red());
§

fn on_green(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Green].

§Example
println!("{}", value.on_green());
§

fn on_yellow(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Yellow].

§Example
println!("{}", value.on_yellow());
§

fn on_blue(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Blue].

§Example
println!("{}", value.on_blue());
§

fn on_magenta(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Magenta].

§Example
println!("{}", value.on_magenta());
§

fn on_cyan(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Cyan].

§Example
println!("{}", value.on_cyan());
§

fn on_white(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: White].

§Example
println!("{}", value.on_white());
§

fn on_bright_black(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightBlack].

§Example
println!("{}", value.on_bright_black());
§

fn on_bright_red(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightRed].

§Example
println!("{}", value.on_bright_red());
§

fn on_bright_green(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightGreen].

§Example
println!("{}", value.on_bright_green());
§

fn on_bright_yellow(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightYellow].

§Example
println!("{}", value.on_bright_yellow());
§

fn on_bright_blue(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightBlue].

§Example
println!("{}", value.on_bright_blue());
§

fn on_bright_magenta(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightMagenta].

§Example
println!("{}", value.on_bright_magenta());
§

fn on_bright_cyan(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightCyan].

§Example
println!("{}", value.on_bright_cyan());
§

fn on_bright_white(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightWhite].

§Example
println!("{}", value.on_bright_white());
§

fn attr(&self, value: Attribute) -> Painted<&T>

Enables the styling [Attribute] value.

This method should be used rarely. Instead, prefer to use attribute-specific builder methods like bold() and underline(), which have the same functionality but are pithier.

§Example

Make text bold using attr():

use yansi::{Paint, Attribute};

painted.attr(Attribute::Bold);

Make text bold using using bold().

use yansi::Paint;

painted.bold();
§

fn bold(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Bold].

§Example
println!("{}", value.bold());
§

fn dim(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Dim].

§Example
println!("{}", value.dim());
§

fn italic(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Italic].

§Example
println!("{}", value.italic());
§

fn underline(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Underline].

§Example
println!("{}", value.underline());

Returns self with the attr() set to [Attribute :: Blink].

§Example
println!("{}", value.blink());

Returns self with the attr() set to [Attribute :: RapidBlink].

§Example
println!("{}", value.rapid_blink());
§

fn invert(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Invert].

§Example
println!("{}", value.invert());
§

fn conceal(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Conceal].

§Example
println!("{}", value.conceal());
§

fn strike(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Strike].

§Example
println!("{}", value.strike());
§

fn quirk(&self, value: Quirk) -> Painted<&T>

Enables the yansi [Quirk] value.

This method should be used rarely. Instead, prefer to use quirk-specific builder methods like mask() and wrap(), which have the same functionality but are pithier.

§Example

Enable wrapping using .quirk():

use yansi::{Paint, Quirk};

painted.quirk(Quirk::Wrap);

Enable wrapping using wrap().

use yansi::Paint;

painted.wrap();
§

fn mask(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Mask].

§Example
println!("{}", value.mask());
§

fn wrap(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Wrap].

§Example
println!("{}", value.wrap());
§

fn linger(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Linger].

§Example
println!("{}", value.linger());
§

fn clear(&self) -> Painted<&T>

👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear(). The clear() method will be removed in a future release.

Returns self with the quirk() set to [Quirk :: Clear].

§Example
println!("{}", value.clear());
§

fn resetting(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Resetting].

§Example
println!("{}", value.resetting());
§

fn bright(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Bright].

§Example
println!("{}", value.bright());
§

fn on_bright(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: OnBright].

§Example
println!("{}", value.on_bright());
§

fn whenever(&self, value: Condition) -> Painted<&T>

Conditionally enable styling based on whether the [Condition] value applies. Replaces any previous condition.

See the crate level docs for more details.

§Example

Enable styling painted only when both stdout and stderr are TTYs:

use yansi::{Paint, Condition};

painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);
§

fn new(self) -> Painted<Self>
where Self: Sized,

Create a new [Painted] with a default [Style]. Read more
§

fn paint<S>(&self, style: S) -> Painted<&Self>
where S: Into<Style>,

Apply a style wholesale to self. Any previous style is replaced. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
§

impl<T, U> RoundingInto<U> for T
where U: RoundingFrom<T>,

§

fn rounding_into(self, rm: RoundingMode) -> (U, Ordering)

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T, U> SaturatingInto<U> for T
where U: SaturatingFrom<T>,

§

fn saturating_into(self) -> U

§

impl<T> ToBinaryString for T
where T: Binary,

§

fn to_binary_string(&self) -> String

Returns the String produced by Ts Binary implementation.

§Examples
use malachite_base::strings::ToBinaryString;

assert_eq!(5u64.to_binary_string(), "101");
assert_eq!((-100i16).to_binary_string(), "1111111110011100");
§

impl<T> ToDebugString for T
where T: Debug,

§

fn to_debug_string(&self) -> String

Returns the String produced by Ts Debug implementation.

§Examples
use malachite_base::strings::ToDebugString;

assert_eq!([1, 2, 3].to_debug_string(), "[1, 2, 3]");
assert_eq!(
    [vec![2, 3], vec![], vec![4]].to_debug_string(),
    "[[2, 3], [], [4]]"
);
assert_eq!(Some(5).to_debug_string(), "Some(5)");
§

impl<T> ToLowerHexString for T
where T: LowerHex,

§

fn to_lower_hex_string(&self) -> String

Returns the String produced by Ts LowerHex implementation.

§Examples
use malachite_base::strings::ToLowerHexString;

assert_eq!(50u64.to_lower_hex_string(), "32");
assert_eq!((-100i16).to_lower_hex_string(), "ff9c");
§

impl<T> ToOctalString for T
where T: Octal,

§

fn to_octal_string(&self) -> String

Returns the String produced by Ts Octal implementation.

§Examples
use malachite_base::strings::ToOctalString;

assert_eq!(50u64.to_octal_string(), "62");
assert_eq!((-100i16).to_octal_string(), "177634");
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
§

impl<T> ToUpperHexString for T
where T: UpperHex,

§

fn to_upper_hex_string(&self) -> String

Returns the String produced by Ts UpperHex implementation.

§Examples
use malachite_base::strings::ToUpperHexString;

assert_eq!(50u64.to_upper_hex_string(), "32");
assert_eq!((-100i16).to_upper_hex_string(), "FF9C");
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T, U> WrappingInto<U> for T
where U: WrappingFrom<T>,

§

fn wrapping_into(self) -> U

§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T, Rhs> NumAssignOps<Rhs> for T
where T: AddAssign<Rhs> + SubAssign<Rhs> + MulAssign<Rhs> + DivAssign<Rhs> + RemAssign<Rhs>,

Source§

impl<T, Rhs, Output> NumOps<Rhs, Output> for T
where T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, Base> RefNum<Base> for T
where T: NumOps<Base, Base> + for<'r> NumOps<&'r Base, Base>,