Skip to main content

GaussianInteger

Struct GaussianInteger 

Source
pub struct GaussianInteger {
    pub real: Integer,
    pub imaginary: Integer,
}
Expand description

A Gaussian integer: a complex number whose real and imaginary parts are both integers.

The fields are public, since every combination of real and imaginary parts is a valid Gaussian integer.

Fields§

§real: Integer§imaginary: Integer

Implementations§

Source§

impl GaussianInteger

Source

pub fn checked_roots(&self, exp: u64) -> Vec<Self>

Returns all the $n$th roots of a GaussianInteger: none if it is not a perfect $n$th power, one if it is zero, and otherwise $\gcd(n, 4)$ of them, in the canonical order of ComparableGaussianInteger, lexicographic by real part and then imaginary part.

The principal root is the one whose argument lies in $(-\pi/g, \pi/g]$ for $g = \gcd(n, 4)$; see CheckedRoot.

$$ f(z, n) = \{ w \in \Z[i] : w^n = z \}. $$

§Worst-case complexity

$T(n) = O(n^2)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is the maximum number of significant bits of the real and imaginary parts of self.

§Panics

Panics if exp is zero.

§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let roots = |s, exp| {
    GaussianInteger::from_str(s)
        .unwrap()
        .checked_roots(exp)
        .iter()
        .map(ToString::to_string)
        .collect::<Vec<_>>()
};
assert_eq!(roots("-4", 4), ["-1-i", "-1+i", "1-i", "1+i"]);
assert_eq!(roots("-4", 2), ["-2i", "2i"]);
assert_eq!(roots("-8", 3), ["-2"]);
assert_eq!(roots("3+4i", 3), Vec::<String>::new());
assert_eq!(
    GaussianInteger::ZERO.checked_roots(7),
    [GaussianInteger::ZERO]
);
Source§

impl GaussianInteger

Source

pub fn checked_sqrts(&self) -> Vec<Self>

Returns all the square roots of a GaussianInteger: none if it is not a perfect square, one if it is zero, and otherwise the principal root and its negative, in the canonical order of ComparableGaussianInteger, lexicographic by real part and then imaginary part.

The principal root is the one with positive real part or, if that is zero, with non-negative imaginary part; see CheckedSqrt.

$$ f(z) = \{ w \in \Z[i] : w^2 = z \}. $$

§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 the maximum number of significant bits of the real and imaginary parts of self.

§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let roots = |s| {
    GaussianInteger::from_str(s)
        .unwrap()
        .checked_sqrts()
        .iter()
        .map(ToString::to_string)
        .collect::<Vec<_>>()
};
assert_eq!(roots("3+4i"), ["-2-i", "2+i"]);
assert_eq!(roots("-1"), ["-i", "i"]);
assert_eq!(roots("2+i"), Vec::<String>::new());
assert_eq!(
    GaussianInteger::ZERO.checked_sqrts(),
    [GaussianInteger::ZERO]
);
Source§

impl GaussianInteger

Source

pub fn remove_one_plus_i(&self) -> (Self, u64)

Removes the largest power of $1 + i$ from a GaussianInteger, taking it by reference and returning the reduced GaussianInteger together with the exponent of that power.

$1 + i$ is the Gaussian prime above 2, with $(1 + i)^2 = 2i$. If $(1 + i)^k$ is the largest power of $1 + i$ that divides self, this returns $(\text{self} / (1 + i)^k, k)$. The exponent is twice the largest power of 2 dividing both parts, plus one more when the parts have the same 2-adic valuation, since then both are odd after the shift and their sum is even. Zero is left alone, with an exponent of 0, since every power of $1 + i$ divides it.

§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::Two;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// 6+2i = (-1-2i)(1+i)^3
let (q, k) = GaussianInteger::from_str("6+2i")
    .unwrap()
    .remove_one_plus_i();
assert_eq!(q.to_string(), "-1-2i");
assert_eq!(k, 3);

// 2 = (-i)(1+i)^2
let (q, k) = GaussianInteger::TWO.remove_one_plus_i();
assert_eq!(q.to_string(), "-i");
assert_eq!(k, 2);

// 3+2i is not divisible by 1+i
let (q, k) = GaussianInteger::from_str("3+2i")
    .unwrap()
    .remove_one_plus_i();
assert_eq!(q.to_string(), "3+2i");
assert_eq!(k, 0);
Source

pub fn remove_one_plus_i_assign(&mut self) -> u64

Removes the largest power of $1 + i$ from a GaussianInteger in place, returning the exponent of that power.

$1 + i$ is the Gaussian prime above 2, with $(1 + i)^2 = 2i$. If $(1 + i)^k$ is the largest power of $1 + i$ that divides self, this replaces self with $\text{self} / (1 + i)^k$ and returns $k$. Zero is left alone, with an exponent of 0, since every power of $1 + i$ divides it.

§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_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// 6+2i = (-1-2i)(1+i)^3
let mut x = GaussianInteger::from_str("6+2i").unwrap();
assert_eq!(x.remove_one_plus_i_assign(), 3);
assert_eq!(x.to_string(), "-1-2i");

// 1000000000000 = 244140625 (1+i)^24
let mut x = GaussianInteger::from(1000000000000u64);
assert_eq!(x.remove_one_plus_i_assign(), 24);
assert_eq!(x.to_string(), "244140625");
Source§

impl GaussianInteger

Source

pub fn max_significant_bits(&self) -> u64

Returns the larger of the numbers of significant bits of the real and imaginary parts of a GaussianInteger, each taken in absolute value.

This is the size measure that FLINT’s fmpzi_bits computes, and the one that the sizes of the parts are compared against when an algorithm is chosen; the SignificantBits implementation sums the two counts instead.

$$ f(a + bi) = \max(\operatorname{bits}(a), \operatorname{bits}(b)), $$ where $\operatorname{bits}(n)$ is the number of significant bits of $|n|$, with $\operatorname{bits}(0) = 0$.

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

assert_eq!(GaussianInteger::ZERO.max_significant_bits(), 0);
assert_eq!(
    GaussianInteger::from_str("3+4i")
        .unwrap()
        .max_significant_bits(),
    3
);
assert_eq!(
    GaussianInteger::from_str("1000000000000+i")
        .unwrap()
        .max_significant_bits(),
    40
);

Trait Implementations§

Source§

impl AbsSquared for GaussianInteger

Source§

fn abs_squared(self) -> Integer

Computes the squared absolute value of a GaussianInteger, taking it by value. This is the sum of the squares of the real and imaginary parts, also known as the norm. It is always a non-negative Integer.

$$ f(x) = |x|^2 = \Re(x)^2 + \Im(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 the maximum number of significant bits of the real and imaginary parts.

§Examples
use malachite_base::num::arithmetic::traits::AbsSquared;
use malachite_base::num::basic::traits::{I, Zero};
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

assert_eq!(GaussianInteger::ZERO.abs_squared(), 0);
assert_eq!(GaussianInteger::I.abs_squared(), 1);
assert_eq!(GaussianInteger::from_str("2-3i").unwrap().abs_squared(), 13);
assert_eq!(GaussianInteger::from(-123).abs_squared(), 15129);
Source§

type Output = Integer

Source§

impl AbsSquared for &GaussianInteger

Source§

fn abs_squared(self) -> Integer

Computes the squared absolute value of a GaussianInteger, taking it by reference. This is the sum of the squares of the real and imaginary parts, also known as the norm. It is always a non-negative Integer.

$$ f(x) = |x|^2 = \Re(x)^2 + \Im(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 the maximum number of significant bits of the real and imaginary parts.

§Examples
use malachite_base::num::arithmetic::traits::AbsSquared;
use malachite_base::num::basic::traits::{I, Zero};
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

assert_eq!((&GaussianInteger::ZERO).abs_squared(), 0);
assert_eq!((&GaussianInteger::I).abs_squared(), 1);
let x = GaussianInteger::from_str("2-3i").unwrap();
assert_eq!((&x).abs_squared(), 13);
Source§

type Output = Integer

Source§

impl AbsSquaredAssign for GaussianInteger

Source§

fn abs_squared_assign(&mut self)

Replaces a GaussianInteger with its squared absolute value: the purely real value $|x|^2$, embedded in the same type. The real part becomes the sum of the squares of the real and imaginary parts (the norm), and the imaginary part becomes zero.

$$ x \gets |x|^2 = \Re(x)^2 + \Im(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 the maximum number of significant bits of the real and imaginary parts.

§Examples
use malachite_base::num::arithmetic::traits::AbsSquaredAssign;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let mut x = GaussianInteger::from_str("2-3i").unwrap();
x.abs_squared_assign();
assert_eq!(x.to_string(), "13");
Source§

impl Add for GaussianInteger

Source§

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

Adds two GaussianIntegers, taking both 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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Examples
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let x = GaussianInteger::from_str("2-3i").unwrap();
let y = GaussianInteger::from_str("-1+4i").unwrap();
assert_eq!((x + y).to_string(), "1+i");
Source§

type Output = GaussianInteger

The resulting type after applying the + operator.
Source§

impl Add<&GaussianInteger> for GaussianInteger

Source§

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

Adds two GaussianIntegers, 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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Examples
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let x = GaussianInteger::from_str("2-3i").unwrap();
let y = GaussianInteger::from_str("-1+4i").unwrap();
assert_eq!((x + &y).to_string(), "1+i");
Source§

type Output = GaussianInteger

The resulting type after applying the + operator.
Source§

impl Add<&GaussianInteger> for &GaussianInteger

Source§

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

Adds two GaussianIntegers, 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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Examples
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let x = GaussianInteger::from_str("1000000000000+i").unwrap();
let y = GaussianInteger::from_str("i").unwrap();
assert_eq!((&x + &y).to_string(), "1000000000000+2i");
Source§

type Output = GaussianInteger

The resulting type after applying the + operator.
Source§

impl Add<GaussianInteger> for &GaussianInteger

Source§

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

Adds two GaussianIntegers, 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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Examples
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let x = GaussianInteger::from_str("2-3i").unwrap();
let y = GaussianInteger::from_str("-1+4i").unwrap();
assert_eq!((&x + y).to_string(), "1+i");
Source§

type Output = GaussianInteger

The resulting type after applying the + operator.
Source§

impl AddAssign for GaussianInteger

Source§

fn add_assign(&mut self, other: Self)

Adds a GaussianInteger to a GaussianInteger in place, taking the GaussianInteger on the right-hand side by value.

$$ 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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Examples
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let x = GaussianInteger::from_str("2-3i").unwrap();
let y = GaussianInteger::from_str("-1+4i").unwrap();
let mut sum = x;
sum += y;
assert_eq!(sum.to_string(), "1+i");
Source§

impl AddAssign<&GaussianInteger> for GaussianInteger

Source§

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

Adds a GaussianInteger to a GaussianInteger in place, taking the GaussianInteger 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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Examples
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let x = GaussianInteger::from_str("2-3i").unwrap();
let y = GaussianInteger::from_str("-1+4i").unwrap();
let mut sum = x;
sum += &y;
assert_eq!(sum.to_string(), "1+i");
Source§

impl CanonicalUnitIPow for GaussianInteger

Source§

fn canonical_unit_i_pow(&self) -> u64

Finds the power of $i$ that brings a GaussianInteger into canonical unit form.

A nonzero value has four associates, $x$, $ix$, $-x$, and $-ix$; the canonical one is the associate whose argument lies in $(-\pi/4, \pi/4]$, that is, whose real part $a$ is positive and whose imaginary part $b$ satisfies $-a < b \leq a$. The result is the $k \in \{0, 1, 2, 3\}$ such that $x i^k$ is canonical, and 0 for zero. The choice of associate, including the tie on the diagonals, matches FLINT’s fmpzi_canonical_unit_i_pow.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is the maximum number of significant bits of the real and imaginary parts.

§Examples
use malachite_base::num::arithmetic::traits::CanonicalUnitIPow;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

assert_eq!(
    GaussianInteger::from_str("2+i")
        .unwrap()
        .canonical_unit_i_pow(),
    0
);
assert_eq!(
    GaussianInteger::from_str("-1+2i")
        .unwrap()
        .canonical_unit_i_pow(),
    3
);
assert_eq!(
    GaussianInteger::from_str("-2-i")
        .unwrap()
        .canonical_unit_i_pow(),
    2
);
assert_eq!(
    GaussianInteger::from_str("1-2i")
        .unwrap()
        .canonical_unit_i_pow(),
    1
);
assert_eq!(
    GaussianInteger::from_str("1+i")
        .unwrap()
        .canonical_unit_i_pow(),
    0
);
assert_eq!(
    GaussianInteger::from_str("1-i")
        .unwrap()
        .canonical_unit_i_pow(),
    1
);
assert_eq!(
    GaussianInteger::from_str("0")
        .unwrap()
        .canonical_unit_i_pow(),
    0
);
Source§

impl CanonicalizeUnit for GaussianInteger

Source§

fn canonicalize_unit(self) -> Self

Brings a GaussianInteger into canonical unit form, taking it by value.

The result is the associate $x i^k$ whose argument lies in $(-\pi/4, \pi/4]$, where $k$ is given by canonical_unit_i_pow; zero is its own canonical form.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is the maximum number of significant bits of the real and imaginary parts.

§Examples
use malachite_base::num::arithmetic::traits::CanonicalizeUnit;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

assert_eq!(
    GaussianInteger::from_str("-1+2i")
        .unwrap()
        .canonicalize_unit()
        .to_string(),
    "2+i"
);
assert_eq!(
    GaussianInteger::from_str("1-i")
        .unwrap()
        .canonicalize_unit()
        .to_string(),
    "1+i"
);
assert_eq!(
    GaussianInteger::from_str("-3")
        .unwrap()
        .canonicalize_unit()
        .to_string(),
    "3"
);
Source§

type Output = GaussianInteger

Source§

impl CanonicalizeUnit for &GaussianInteger

Source§

fn canonicalize_unit(self) -> GaussianInteger

Brings a GaussianInteger into canonical unit form, taking it by reference.

The result is the associate $x i^k$ whose argument lies in $(-\pi/4, \pi/4]$, where $k$ is given by canonical_unit_i_pow; zero is its own canonical form.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is the maximum number of significant bits of the real and imaginary parts.

§Examples
use malachite_base::num::arithmetic::traits::CanonicalizeUnit;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let x = GaussianInteger::from_str("-1+2i").unwrap();
assert_eq!((&x).canonicalize_unit().to_string(), "2+i");
Source§

type Output = GaussianInteger

Source§

impl CanonicalizeUnitAssign for GaussianInteger

Source§

fn canonicalize_unit_assign(&mut self)

Brings a GaussianInteger into canonical unit form in place.

The result is the associate $x i^k$ whose argument lies in $(-\pi/4, \pi/4]$, where $k$ is given by canonical_unit_i_pow; zero is its own canonical form.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is the maximum number of significant bits of the real and imaginary parts.

§Examples
use malachite_base::num::arithmetic::traits::CanonicalizeUnitAssign;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let mut x = GaussianInteger::from_str("-1+2i").unwrap();
x.canonicalize_unit_assign();
assert_eq!(x.to_string(), "2+i");
Source§

impl CheckedDiv for GaussianInteger

Source§

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

Divides a GaussianInteger by another GaussianInteger, taking both by value. Returns None when the second GaussianInteger is zero.

The quotient is the Gaussian integer nearest to the exact quotient, with each part rounded to the nearest integer and ties rounded up. The quotient and remainder (which is not computed) satisfy $x = qy + r$ and $N(r) \leq N(y) / 2$, where $N$ is the norm. To get both at once, use div_rem.

$$ f(x, y) = \left \lfloor \frac{x \bar{y}}{N(y)} + \frac{1 + i}{2} \right \rfloor, $$ where the floor is taken on each part.

§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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Examples
use malachite_base::num::arithmetic::traits::CheckedDiv;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// (2+i)(3) + (-1) = 5+3i
let x = GaussianInteger::from_str("5+3i").unwrap();
let y = GaussianInteger::from_str("2+i").unwrap();
assert_eq!((x.clone().checked_div(y)).unwrap().to_string(), "3");
assert_eq!((x.clone().checked_div(GaussianInteger::ZERO)), None);
Source§

type Output = GaussianInteger

Source§

impl CheckedDiv<&GaussianInteger> for GaussianInteger

Source§

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

Divides a GaussianInteger by another GaussianInteger, taking the first by value and the second by reference. Returns None when the second GaussianInteger is zero.

The quotient is the Gaussian integer nearest to the exact quotient, with each part rounded to the nearest integer and ties rounded up. The quotient and remainder (which is not computed) satisfy $x = qy + r$ and $N(r) \leq N(y) / 2$, where $N$ is the norm. To get both at once, use div_rem.

$$ f(x, y) = \left \lfloor \frac{x \bar{y}}{N(y)} + \frac{1 + i}{2} \right \rfloor, $$ where the floor is taken on each part.

§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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Examples
use malachite_base::num::arithmetic::traits::CheckedDiv;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// (2+i)(3) + (-1) = 5+3i
let x = GaussianInteger::from_str("5+3i").unwrap();
let y = GaussianInteger::from_str("2+i").unwrap();
assert_eq!((x.clone().checked_div(&y)).unwrap().to_string(), "3");
assert_eq!((x.clone().checked_div(&GaussianInteger::ZERO)), None);
Source§

type Output = GaussianInteger

Source§

impl CheckedDiv<&GaussianInteger> for &GaussianInteger

Source§

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

Divides a GaussianInteger by another GaussianInteger, taking both by reference. Returns None when the second GaussianInteger is zero.

The quotient is the Gaussian integer nearest to the exact quotient, with each part rounded to the nearest integer and ties rounded up. The quotient and remainder (which is not computed) satisfy $x = qy + r$ and $N(r) \leq N(y) / 2$, where $N$ is the norm. To get both at once, use div_rem.

$$ f(x, y) = \left \lfloor \frac{x \bar{y}}{N(y)} + \frac{1 + i}{2} \right \rfloor, $$ where the floor is taken on each part.

§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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Examples
use malachite_base::num::arithmetic::traits::CheckedDiv;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// (2+i)(3) + (-1) = 5+3i
let x = GaussianInteger::from_str("5+3i").unwrap();
let y = GaussianInteger::from_str("2+i").unwrap();
assert_eq!(((&x).checked_div(&y)).unwrap().to_string(), "3");
assert_eq!(((&x).checked_div(&GaussianInteger::ZERO)), None);
Source§

type Output = GaussianInteger

Source§

impl CheckedDiv<GaussianInteger> for &GaussianInteger

Source§

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

Divides a GaussianInteger by another GaussianInteger, taking the first by reference and the second by value. Returns None when the second GaussianInteger is zero.

The quotient is the Gaussian integer nearest to the exact quotient, with each part rounded to the nearest integer and ties rounded up. The quotient and remainder (which is not computed) satisfy $x = qy + r$ and $N(r) \leq N(y) / 2$, where $N$ is the norm. To get both at once, use div_rem.

$$ f(x, y) = \left \lfloor \frac{x \bar{y}}{N(y)} + \frac{1 + i}{2} \right \rfloor, $$ where the floor is taken on each part.

§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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Examples
use malachite_base::num::arithmetic::traits::CheckedDiv;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// (2+i)(3) + (-1) = 5+3i
let x = GaussianInteger::from_str("5+3i").unwrap();
let y = GaussianInteger::from_str("2+i").unwrap();
assert_eq!(((&x).checked_div(y)).unwrap().to_string(), "3");
assert_eq!(((&x).checked_div(GaussianInteger::ZERO)), None);
Source§

type Output = GaussianInteger

Source§

impl CheckedRoot<u64> for GaussianInteger

Source§

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

Returns the principal $n$th root of a GaussianInteger, or None if it is not a perfect $n$th power. The GaussianInteger is taken by value.

A nonzero Gaussian integer has either no $n$th roots or exactly $\gcd(n, 4)$ of them: if $w$ is one, the others are $w\zeta$ for the units $\zeta$ with $\zeta^n = 1$. The one returned is the principal root, whose argument lies in $(-\pi/g, \pi/g]$ for $g = \gcd(n, 4)$: the unique root for odd $n$, the root with positive real part (or zero real part and positive imaginary part) for $n \equiv 2 \pmod 4$, and the root in canonical unit form for $4 \mid n$.

Writing $n = 2^e m$ with $m$ odd, the unique $m$th root is found exactly through the norm: with $N = N(z)^{1/m}$ and $d = \gcd(z, N)$, the quotient $N d / \bar{d}$ is the square of the root up to a unit, and the unit is fixed by raising to the $m$th power. Square roots are then taken $e$ times over the candidate set, which never exceeds four roots.

$$ f(z, n) = \begin{cases} \operatorname{Some}(\sqrt[n]{z}) & \text{if} \quad \sqrt[n]{z} \in \Z[i], \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$

§Worst-case complexity

$T(n) = O(n^2)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is the maximum number of significant bits of the real and imaginary parts of self.

§Panics

Panics if exp is zero.

§Examples
use malachite_base::num::arithmetic::traits::CheckedRoot;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let root = |s, exp| {
    GaussianInteger::from_str(s)
        .unwrap()
        .checked_root(exp)
        .map(|r| r.to_string())
};
// (2+i)^5 = -38+41i
assert_eq!(root("-38+41i", 5), Some("2+i".to_string()));
// -4 = (1+i)^4, and 1+i is the principal root of the four
assert_eq!(root("-4", 4), Some("1+i".to_string()));
// the unique cube root of -8 is -2
assert_eq!(root("-8", 3), Some("-2".to_string()));
assert_eq!(root("3+4i", 3), None);
Source§

type Output = GaussianInteger

Source§

impl CheckedRoot<u64> for &GaussianInteger

Source§

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

Returns the principal $n$th root of a GaussianInteger, or None if it is not a perfect $n$th power. The GaussianInteger is taken by reference.

A nonzero Gaussian integer has either no $n$th roots or exactly $\gcd(n, 4)$ of them: if $w$ is one, the others are $w\zeta$ for the units $\zeta$ with $\zeta^n = 1$. The one returned is the principal root, whose argument lies in $(-\pi/g, \pi/g]$ for $g = \gcd(n, 4)$: the unique root for odd $n$, the root with positive real part (or zero real part and positive imaginary part) for $n \equiv 2 \pmod 4$, and the root in canonical unit form for $4 \mid n$.

Writing $n = 2^e m$ with $m$ odd, the unique $m$th root is found exactly through the norm: with $N = N(z)^{1/m}$ and $d = \gcd(z, N)$, the quotient $N d / \bar{d}$ is the square of the root up to a unit, and the unit is fixed by raising to the $m$th power. Square roots are then taken $e$ times over the candidate set, which never exceeds four roots.

$$ f(z, n) = \begin{cases} \operatorname{Some}(\sqrt[n]{z}) & \text{if} \quad \sqrt[n]{z} \in \Z[i], \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$

§Worst-case complexity

$T(n) = O(n^2)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is the maximum number of significant bits of the real and imaginary parts of self.

§Panics

Panics if exp is zero.

§Examples
use malachite_base::num::arithmetic::traits::CheckedRoot;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let root = |s, exp| {
    (&GaussianInteger::from_str(s).unwrap())
        .checked_root(exp)
        .map(|r| r.to_string())
};
// (2+i)^5 = -38+41i
assert_eq!(root("-38+41i", 5), Some("2+i".to_string()));
// -4 = (1+i)^4, and 1+i is the principal root of the four
assert_eq!(root("-4", 4), Some("1+i".to_string()));
// the unique cube root of -8 is -2
assert_eq!(root("-8", 3), Some("-2".to_string()));
assert_eq!(root("3+4i", 3), None);
Source§

type Output = GaussianInteger

Source§

impl CheckedSqrt for GaussianInteger

Source§

fn checked_sqrt(self) -> Option<Self>

Returns the principal square root of a GaussianInteger, or None if it is not a perfect square. The GaussianInteger is taken by value.

A nonzero Gaussian integer that is a perfect square has two square roots, each the negative of the other; the one returned is the principal root, whose real part is positive or, if it is zero, whose imaginary part is non-negative. That is the root whose argument lies in $(-\pi/2, \pi/2]$.

The root is found through the norm: if $a + bi = (x + yi)^2$ then $N = \sqrt{a^2 + b^2}$ is an integer, $x^2 = (N + a) / 2$, $y^2 = (N - a) / 2$, and $2xy = b$ fixes the sign of $y$ relative to that of $x$.

$$ f(z) = \begin{cases} \operatorname{Some}(\sqrt{z}) & \text{if} \quad \sqrt{z} \in \Z[i], \\ \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 the maximum number of significant bits of the real and imaginary parts of self.

§Examples
use malachite_base::num::arithmetic::traits::CheckedSqrt;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// (2+i)^2 = 3+4i
assert_eq!(
    GaussianInteger::from_str("3+4i")
        .unwrap()
        .checked_sqrt()
        .unwrap()
        .to_string(),
    "2+i"
);
// (1-i)^2 = -2i
assert_eq!(
    GaussianInteger::from_str("-2i")
        .unwrap()
        .checked_sqrt()
        .unwrap()
        .to_string(),
    "1-i"
);
// -4 = (2i)^2, and 2i is the principal root
assert_eq!(
    GaussianInteger::from(-4)
        .checked_sqrt()
        .unwrap()
        .to_string(),
    "2i"
);
assert!(
    GaussianInteger::from_str("2+i")
        .unwrap()
        .checked_sqrt()
        .is_none()
);
Source§

type Output = GaussianInteger

Source§

impl CheckedSqrt for &GaussianInteger

Source§

fn checked_sqrt(self) -> Option<GaussianInteger>

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

A nonzero Gaussian integer that is a perfect square has two square roots, each the negative of the other; the one returned is the principal root, whose real part is positive or, if it is zero, whose imaginary part is non-negative. That is the root whose argument lies in $(-\pi/2, \pi/2]$.

The root is found through the norm: if $a + bi = (x + yi)^2$ then $N = \sqrt{a^2 + b^2}$ is an integer, $x^2 = (N + a) / 2$, $y^2 = (N - a) / 2$, and $2xy = b$ fixes the sign of $y$ relative to that of $x$.

$$ f(z) = \begin{cases} \operatorname{Some}(\sqrt{z}) & \text{if} \quad \sqrt{z} \in \Z[i], \\ \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 the maximum number of significant bits of the real and imaginary parts of self.

§Examples
use malachite_base::num::arithmetic::traits::CheckedSqrt;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// (2+i)^2 = 3+4i
assert_eq!(
    (&GaussianInteger::from_str("3+4i").unwrap())
        .checked_sqrt()
        .unwrap()
        .to_string(),
    "2+i"
);
// (1-i)^2 = -2i
assert_eq!(
    (&GaussianInteger::from_str("-2i").unwrap())
        .checked_sqrt()
        .unwrap()
        .to_string(),
    "1-i"
);
// -4 = (2i)^2, and 2i is the principal root
assert_eq!(
    (&GaussianInteger::from(-4))
        .checked_sqrt()
        .unwrap()
        .to_string(),
    "2i"
);
assert!(
    (&GaussianInteger::from_str("2+i").unwrap())
        .checked_sqrt()
        .is_none()
);
Source§

type Output = GaussianInteger

Source§

impl Clone for GaussianInteger

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Conjugate for GaussianInteger

Source§

fn conjugate(self) -> Self

Computes the complex conjugate of a GaussianInteger, taking it by value. The sign of the imaginary part is flipped.

$$ f(x) = \overline{x} = \Re(x) - \Im(x) i. $$

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::num::arithmetic::traits::Conjugate;
use malachite_base::num::basic::traits::I;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

assert_eq!(GaussianInteger::I.conjugate().to_string(), "-i");
assert_eq!(
    GaussianInteger::from_str("2-3i")
        .unwrap()
        .conjugate()
        .to_string(),
    "2+3i"
);
assert_eq!(
    GaussianInteger::from_str("-123")
        .unwrap()
        .conjugate()
        .to_string(),
    "-123"
);
Source§

type Output = GaussianInteger

Source§

impl Conjugate for &GaussianInteger

Source§

fn conjugate(self) -> GaussianInteger

Computes the complex conjugate of a GaussianInteger, taking it by reference. The sign of the imaginary part is flipped.

$$ f(x) = \overline{x} = \Re(x) - \Im(x) i. $$

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is the maximum number of significant bits of the real and imaginary parts.

§Examples
use malachite_base::num::arithmetic::traits::Conjugate;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let x = GaussianInteger::from_str("2-3i").unwrap();
assert_eq!((&x).conjugate().to_string(), "2+3i");
Source§

type Output = GaussianInteger

Source§

impl ConjugateAssign for GaussianInteger

Source§

fn conjugate_assign(&mut self)

Replaces a GaussianInteger with its complex conjugate. The sign of the imaginary part is flipped.

$$ x \gets \overline{x} = \Re(x) - \Im(x) i. $$

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::num::arithmetic::traits::ConjugateAssign;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let mut x = GaussianInteger::from_str("2-3i").unwrap();
x.conjugate_assign();
assert_eq!(x.to_string(), "2+3i");
Source§

impl Content for GaussianInteger

Source§

fn content(self) -> Natural

Computes the content of a GaussianInteger, the GCD of its real and imaginary parts, taking the GaussianInteger by value.

$$ f(a + bi) = \gcd(|a|, |b|). $$

§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 the maximum number of significant bits of the real and imaginary parts of self.

§Examples
use malachite_base::num::arithmetic::traits::Content;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

assert_eq!(GaussianInteger::from_str("-6+9i").unwrap().content(), 3);
assert_eq!(GaussianInteger::from_str("7+11i").unwrap().content(), 1);
Source§

type Output = Natural

Source§

impl Content for &GaussianInteger

Source§

fn content(self) -> Natural

Computes the content of a GaussianInteger, the GCD of its real and imaginary parts, taking the GaussianInteger by reference.

$$ f(a + bi) = \gcd(|a|, |b|). $$

§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 the maximum number of significant bits of the real and imaginary parts of self.

§Examples
use malachite_base::num::arithmetic::traits::Content;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

assert_eq!((&GaussianInteger::from_str("-6+9i").unwrap()).content(), 3);
assert_eq!((&GaussianInteger::from_str("7+11i").unwrap()).content(), 1);
Source§

type Output = Natural

Source§

impl ContentAndPrimitivePart for GaussianInteger

Source§

fn content_and_primitive_part(self) -> (Natural, Self)

Splits a GaussianInteger into its content and its primitive part, taking the GaussianInteger by value.

The content of a Gaussian integer is the GCD of its real and imaginary parts, a non-negative integer, and the primitive part is the Gaussian integer with coprime parts that remains after dividing it out; their product is the original number. Zero has content 0 and primitive part 0, and the unit of a nonzero number stays in its primitive part.

$$ f(a + bi) = \left ( g, \frac{a}{g} + \frac{b}{g} i \right ), \quad \text{where } g = \gcd(|a|, |b|). $$

§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 the maximum number of significant bits of the real and imaginary parts of self.

§Examples
use malachite_base::num::arithmetic::traits::ContentAndPrimitivePart;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let (content, primitive) = GaussianInteger::from_str("-6+9i")
    .unwrap()
    .content_and_primitive_part();
assert_eq!(content, 3);
assert_eq!(primitive.to_string(), "-2+3i");
Source§

type Content = Natural

Source§

type PrimitivePart = GaussianInteger

Source§

impl ContentAndPrimitivePart for &GaussianInteger

Source§

fn content_and_primitive_part(self) -> (Natural, GaussianInteger)

Splits a GaussianInteger into its content and its primitive part, taking the GaussianInteger by reference.

The content of a Gaussian integer is the GCD of its real and imaginary parts, a non-negative integer, and the primitive part is the Gaussian integer with coprime parts that remains after dividing it out; their product is the original number. Zero has content 0 and primitive part 0, and the unit of a nonzero number stays in its primitive part.

$$ f(a + bi) = \left ( g, \frac{a}{g} + \frac{b}{g} i \right ), \quad \text{where } g = \gcd(|a|, |b|). $$

§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 the maximum number of significant bits of the real and imaginary parts of self.

§Examples
use malachite_base::num::arithmetic::traits::ContentAndPrimitivePart;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let x = GaussianInteger::from_str("-6+9i").unwrap();
let (content, primitive) = (&x).content_and_primitive_part();
assert_eq!(content, 3);
assert_eq!(primitive.to_string(), "-2+3i");
Source§

type Content = Natural

Source§

type PrimitivePart = GaussianInteger

Source§

impl ConvertibleFrom<&GaussianInteger> for Integer

Source§

fn convertible_from(x: &GaussianInteger) -> bool

Determines whether a GaussianInteger can be converted to an Integer (that is, whether it is real), taking the GaussianInteger by reference.

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::num::conversion::traits::ConvertibleFrom;
use malachite_nz::gaussian_integer::GaussianInteger;
use malachite_nz::integer::Integer;
use std::str::FromStr;

let x = GaussianInteger::from_str("123").unwrap();
assert_eq!(Integer::convertible_from(&x), true);

let x = GaussianInteger::from_str("-123").unwrap();
assert_eq!(Integer::convertible_from(&x), true);

let x = GaussianInteger::from_str("2-3i").unwrap();
assert_eq!(Integer::convertible_from(&x), false);
Source§

impl ConvertibleFrom<&GaussianInteger> for Natural

Source§

fn convertible_from(x: &GaussianInteger) -> bool

Determines whether a GaussianInteger can be converted to a Natural (that is, whether it is real and non-negative), taking the GaussianInteger by reference.

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::num::conversion::traits::ConvertibleFrom;
use malachite_nz::gaussian_integer::GaussianInteger;
use malachite_nz::natural::Natural;
use std::str::FromStr;

let x = GaussianInteger::from_str("123").unwrap();
assert_eq!(Natural::convertible_from(&x), true);

let x = GaussianInteger::from_str("-123").unwrap();
assert_eq!(Natural::convertible_from(&x), false);

let x = GaussianInteger::from_str("2-3i").unwrap();
assert_eq!(Natural::convertible_from(&x), false);
Source§

impl ConvertibleFrom<&GaussianInteger> for f32

Source§

fn convertible_from(x: &GaussianInteger) -> bool

Determines whether a GaussianInteger can be converted to a primitive float (that is, whether it is real and exactly equal to some float), taking the GaussianInteger by reference.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is x.real.significant_bits().

§Examples

See here.

Source§

impl ConvertibleFrom<&GaussianInteger> for f64

Source§

fn convertible_from(x: &GaussianInteger) -> bool

Determines whether a GaussianInteger can be converted to a primitive float (that is, whether it is real and exactly equal to some float), taking the GaussianInteger by reference.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is x.real.significant_bits().

§Examples

See here.

Source§

impl ConvertibleFrom<&GaussianInteger> for u8

Source§

fn convertible_from(x: &GaussianInteger) -> bool

Determines whether a GaussianInteger can be converted to a primitive integer (that is, whether it is real and representable), taking the GaussianInteger by reference.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

Source§

impl ConvertibleFrom<&GaussianInteger> for u16

Source§

fn convertible_from(x: &GaussianInteger) -> bool

Determines whether a GaussianInteger can be converted to a primitive integer (that is, whether it is real and representable), taking the GaussianInteger by reference.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

Source§

impl ConvertibleFrom<&GaussianInteger> for u32

Source§

fn convertible_from(x: &GaussianInteger) -> bool

Determines whether a GaussianInteger can be converted to a primitive integer (that is, whether it is real and representable), taking the GaussianInteger by reference.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

Source§

impl ConvertibleFrom<&GaussianInteger> for u64

Source§

fn convertible_from(x: &GaussianInteger) -> bool

Determines whether a GaussianInteger can be converted to a primitive integer (that is, whether it is real and representable), taking the GaussianInteger by reference.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

Source§

impl ConvertibleFrom<&GaussianInteger> for u128

Source§

fn convertible_from(x: &GaussianInteger) -> bool

Determines whether a GaussianInteger can be converted to a primitive integer (that is, whether it is real and representable), taking the GaussianInteger by reference.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

Source§

impl ConvertibleFrom<&GaussianInteger> for usize

Source§

fn convertible_from(x: &GaussianInteger) -> bool

Determines whether a GaussianInteger can be converted to a primitive integer (that is, whether it is real and representable), taking the GaussianInteger by reference.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

Source§

impl ConvertibleFrom<&GaussianInteger> for i8

Source§

fn convertible_from(x: &GaussianInteger) -> bool

Determines whether a GaussianInteger can be converted to a primitive integer (that is, whether it is real and representable), taking the GaussianInteger by reference.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

Source§

impl ConvertibleFrom<&GaussianInteger> for i16

Source§

fn convertible_from(x: &GaussianInteger) -> bool

Determines whether a GaussianInteger can be converted to a primitive integer (that is, whether it is real and representable), taking the GaussianInteger by reference.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

Source§

impl ConvertibleFrom<&GaussianInteger> for i32

Source§

fn convertible_from(x: &GaussianInteger) -> bool

Determines whether a GaussianInteger can be converted to a primitive integer (that is, whether it is real and representable), taking the GaussianInteger by reference.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

Source§

impl ConvertibleFrom<&GaussianInteger> for i64

Source§

fn convertible_from(x: &GaussianInteger) -> bool

Determines whether a GaussianInteger can be converted to a primitive integer (that is, whether it is real and representable), taking the GaussianInteger by reference.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

Source§

impl ConvertibleFrom<&GaussianInteger> for i128

Source§

fn convertible_from(x: &GaussianInteger) -> bool

Determines whether a GaussianInteger can be converted to a primitive integer (that is, whether it is real and representable), taking the GaussianInteger by reference.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

Source§

impl ConvertibleFrom<&GaussianInteger> for isize

Source§

fn convertible_from(x: &GaussianInteger) -> bool

Determines whether a GaussianInteger can be converted to a primitive integer (that is, whether it is real and representable), taking the GaussianInteger by reference.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

Source§

impl ConvertibleFrom<f32> for GaussianInteger

Source§

fn convertible_from(value: f32) -> bool

Determines whether a primitive float can be converted to a GaussianInteger (that is, whether it is finite and an integer).

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

Source§

impl ConvertibleFrom<f64> for GaussianInteger

Source§

fn convertible_from(value: f64) -> bool

Determines whether a primitive float can be converted to a GaussianInteger (that is, whether it is finite and an integer).

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

Source§

impl Debug for GaussianInteger

Source§

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

Converts a GaussianInteger to a String.

This is the same as the Display::fmt implementation, so that a collection of GaussianIntegers is written the same way its elements are displayed.

§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 the maximum number of significant bits of the real and imaginary parts.

§Examples
use core::str::FromStr;
use malachite_base::strings::ToDebugString;
use malachite_nz::gaussian_integer::GaussianInteger;

let xs = vec![
    GaussianInteger::from_str("2-3i").unwrap(),
    GaussianInteger::from_str("i").unwrap(),
    GaussianInteger::from_str("-5").unwrap(),
];
assert_eq!(xs[0].to_debug_string(), "2-3i");
assert_eq!(xs[1].to_debug_string(), "i");
assert_eq!(xs[2].to_debug_string(), "-5");
assert_eq!(xs.to_debug_string(), "[2-3i, i, -5]");
Source§

impl Default for GaussianInteger

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for GaussianInteger

Source§

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

Converts a GaussianInteger to a String.

A value with a zero imaginary part is written as its real part alone; in particular, zero is "0". A purely imaginary value is written as a coefficient directly followed by 'i', with coefficients of 1 and -1 elided, giving "i" and "-i". Otherwise, the real term is written first and the imaginary term follows with a joining sign, as in "1+i" and "2-3i".

§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 the maximum number of significant bits of the real and imaginary parts.

§Examples
use malachite_base::num::conversion::traits::ImaginaryFrom;
use malachite_nz::gaussian_integer::GaussianInteger;
use malachite_nz::integer::Integer;

assert_eq!(GaussianInteger::default().to_string(), "0");
assert_eq!(GaussianInteger::from(2).to_string(), "2");
assert_eq!(GaussianInteger::from(-2).to_string(), "-2");
assert_eq!(GaussianInteger::imaginary_from(1).to_string(), "i");
assert_eq!(GaussianInteger::imaginary_from(-1).to_string(), "-i");
assert_eq!(GaussianInteger::imaginary_from(2).to_string(), "2i");
assert_eq!(GaussianInteger::imaginary_from(-2).to_string(), "-2i");

let g = GaussianInteger {
    real: Integer::from(1),
    imaginary: Integer::from(1),
};
assert_eq!(g.to_string(), "1+i");
let g = GaussianInteger {
    real: Integer::from(1),
    imaginary: Integer::from(-1),
};
assert_eq!(g.to_string(), "1-i");
let g = GaussianInteger {
    real: Integer::from(2),
    imaginary: Integer::from(3),
};
assert_eq!(g.to_string(), "2+3i");
let g = GaussianInteger {
    real: Integer::from(2),
    imaginary: Integer::from(-3),
};
assert_eq!(g.to_string(), "2-3i");
Source§

impl Div for GaussianInteger

Source§

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

Divides a GaussianInteger by another GaussianInteger, taking both by value.

The quotient is the Gaussian integer nearest to the exact quotient, with each part rounded to the nearest integer and ties rounded up. The quotient and remainder (which is not computed) satisfy $x = qy + r$ and $N(r) \leq N(y) / 2$, where $N$ is the norm. To get both at once, use div_rem.

$$ f(x, y) = \left \lfloor \frac{x \bar{y}}{N(y)} + \frac{1 + i}{2} \right \rfloor, $$ where the floor is taken on each part.

§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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Panics

Panics if other is zero.

§Examples
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// (2+i)(3) + (-1) = 5+3i
let x = GaussianInteger::from_str("5+3i").unwrap();
let y = GaussianInteger::from_str("2+i").unwrap();
assert_eq!((x / y).to_string(), "3");
Source§

type Output = GaussianInteger

The resulting type after applying the / operator.
Source§

impl Div<&GaussianInteger> for GaussianInteger

Source§

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

Divides a GaussianInteger by another GaussianInteger, taking the first by value and the second by reference.

The quotient is the Gaussian integer nearest to the exact quotient, with each part rounded to the nearest integer and ties rounded up. The quotient and remainder (which is not computed) satisfy $x = qy + r$ and $N(r) \leq N(y) / 2$, where $N$ is the norm. To get both at once, use div_rem.

$$ f(x, y) = \left \lfloor \frac{x \bar{y}}{N(y)} + \frac{1 + i}{2} \right \rfloor, $$ where the floor is taken on each part.

§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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Panics

Panics if other is zero.

§Examples
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// (2+i)(3) + (-1) = 5+3i
let x = GaussianInteger::from_str("5+3i").unwrap();
let y = GaussianInteger::from_str("2+i").unwrap();
assert_eq!((x / &y).to_string(), "3");
Source§

type Output = GaussianInteger

The resulting type after applying the / operator.
Source§

impl Div<&GaussianInteger> for &GaussianInteger

Source§

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

Divides a GaussianInteger by another GaussianInteger, taking both by reference.

The quotient is the Gaussian integer nearest to the exact quotient, with each part rounded to the nearest integer and ties rounded up. The quotient and remainder (which is not computed) satisfy $x = qy + r$ and $N(r) \leq N(y) / 2$, where $N$ is the norm. To get both at once, use div_rem.

$$ f(x, y) = \left \lfloor \frac{x \bar{y}}{N(y)} + \frac{1 + i}{2} \right \rfloor, $$ where the floor is taken on each part.

§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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Panics

Panics if other is zero.

§Examples
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// (2+i)(3) + (-1) = 5+3i
let x = GaussianInteger::from_str("5+3i").unwrap();
let y = GaussianInteger::from_str("2+i").unwrap();
assert_eq!((&x / &y).to_string(), "3");
Source§

type Output = GaussianInteger

The resulting type after applying the / operator.
Source§

impl Div<GaussianInteger> for &GaussianInteger

Source§

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

Divides a GaussianInteger by another GaussianInteger, taking the first by reference and the second by value.

The quotient is the Gaussian integer nearest to the exact quotient, with each part rounded to the nearest integer and ties rounded up. The quotient and remainder (which is not computed) satisfy $x = qy + r$ and $N(r) \leq N(y) / 2$, where $N$ is the norm. To get both at once, use div_rem.

$$ f(x, y) = \left \lfloor \frac{x \bar{y}}{N(y)} + \frac{1 + i}{2} \right \rfloor, $$ where the floor is taken on each part.

§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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Panics

Panics if other is zero.

§Examples
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// (2+i)(3) + (-1) = 5+3i
let x = GaussianInteger::from_str("5+3i").unwrap();
let y = GaussianInteger::from_str("2+i").unwrap();
assert_eq!((&x / y).to_string(), "3");
Source§

type Output = GaussianInteger

The resulting type after applying the / operator.
Source§

impl DivAssign for GaussianInteger

Source§

fn div_assign(&mut self, other: Self)

Divides a GaussianInteger by another GaussianInteger in place, taking the GaussianInteger on the right-hand side by value.

The quotient is the Gaussian integer nearest to the exact quotient, with each part rounded to the nearest integer and ties rounded up. The quotient and remainder (which is not computed) satisfy $x = qy + r$ and $N(r) \leq N(y) / 2$, where $N$ is the norm. To get both at once, use div_rem.

$$ x \gets \left \lfloor \frac{x \bar{y}}{N(y)} + \frac{1 + i}{2} \right \rfloor, $$ where the floor is taken on each part.

§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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Panics

Panics if other is zero.

§Examples
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// (2+i)(3) + (-1) = 5+3i
let mut x = GaussianInteger::from_str("5+3i").unwrap();
x /= GaussianInteger::from_str("2+i").unwrap();
assert_eq!(x.to_string(), "3");
Source§

impl DivAssign<&GaussianInteger> for GaussianInteger

Source§

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

Divides a GaussianInteger by another GaussianInteger in place, taking the GaussianInteger on the right-hand side by reference.

The quotient is the Gaussian integer nearest to the exact quotient, with each part rounded to the nearest integer and ties rounded up. The quotient and remainder (which is not computed) satisfy $x = qy + r$ and $N(r) \leq N(y) / 2$, where $N$ is the norm. To get both at once, use div_rem.

$$ x \gets \left \lfloor \frac{x \bar{y}}{N(y)} + \frac{1 + i}{2} \right \rfloor, $$ where the floor is taken on each part.

§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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Panics

Panics if other is zero.

§Examples
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// (2+i)(3) + (-1) = 5+3i
let mut x = GaussianInteger::from_str("5+3i").unwrap();
x /= &GaussianInteger::from_str("2+i").unwrap();
assert_eq!(x.to_string(), "3");
Source§

impl DivAssignRem for GaussianInteger

Source§

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

Divides a GaussianInteger by another GaussianInteger in place, taking the GaussianInteger on the right-hand side by value and returning the remainder.

The quotient is the Gaussian integer nearest to the exact quotient, with each part rounded to the nearest integer and ties rounded up; the remainder is what is left over. This is the division of the Gaussian integers as a Euclidean domain: the quotient and remainder satisfy $x = qy + r$ and $N(r) \leq N(y) / 2$, where $N$ is the norm, so the remainder is always smaller than the divisor.

$$ x \gets q, \quad f(x, y) = x - qy, \quad \text{where } q = \left \lfloor \frac{x \bar{y}}{N(y)} + \frac{1 + i}{2} \right \rfloor $$ and the floor is taken on each part.

§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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Panics

Panics if other is zero.

§Examples
use malachite_base::num::arithmetic::traits::DivAssignRem;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// (2+i)(3) + (-1) = 5+3i
let mut x = GaussianInteger::from_str("5+3i").unwrap();
let r = x.div_assign_rem(GaussianInteger::from_str("2+i").unwrap());
assert_eq!(x.to_string(), "3");
assert_eq!(r.to_string(), "-1");
Source§

type RemOutput = GaussianInteger

Source§

impl DivAssignRem<&GaussianInteger> for GaussianInteger

Source§

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

Divides a GaussianInteger by another GaussianInteger in place, taking the GaussianInteger on the right-hand side by reference and returning the remainder.

The quotient is the Gaussian integer nearest to the exact quotient, with each part rounded to the nearest integer and ties rounded up; the remainder is what is left over. This is the division of the Gaussian integers as a Euclidean domain: the quotient and remainder satisfy $x = qy + r$ and $N(r) \leq N(y) / 2$, where $N$ is the norm, so the remainder is always smaller than the divisor.

$$ x \gets q, \quad f(x, y) = x - qy, \quad \text{where } q = \left \lfloor \frac{x \bar{y}}{N(y)} + \frac{1 + i}{2} \right \rfloor $$ and the floor is taken on each part.

§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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Panics

Panics if other is zero.

§Examples
use malachite_base::num::arithmetic::traits::DivAssignRem;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// (2+i)(3) + (-1) = 5+3i
let mut x = GaussianInteger::from_str("5+3i").unwrap();
let r = x.div_assign_rem(&GaussianInteger::from_str("2+i").unwrap());
assert_eq!(x.to_string(), "3");
assert_eq!(r.to_string(), "-1");
Source§

type RemOutput = GaussianInteger

Source§

impl DivExact for GaussianInteger

Source§

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

Divides a GaussianInteger by another GaussianInteger, taking both by value. The first GaussianInteger 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}. $$

§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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Panics

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

§Examples
use malachite_base::num::arithmetic::traits::DivExact;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// (3+4i)(5-2i) = 23+14i
let x = GaussianInteger::from_str("23+14i").unwrap();
let y = GaussianInteger::from_str("5-2i").unwrap();
assert_eq!((x.div_exact(y)).to_string(), "3+4i");
Source§

type Output = GaussianInteger

Source§

impl DivExact<&GaussianInteger> for GaussianInteger

Source§

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

Divides a GaussianInteger by another GaussianInteger, taking the first by value and the second by reference. The first GaussianInteger 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}. $$

§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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Panics

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

§Examples
use malachite_base::num::arithmetic::traits::DivExact;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// (3+4i)(5-2i) = 23+14i
let x = GaussianInteger::from_str("23+14i").unwrap();
let y = GaussianInteger::from_str("5-2i").unwrap();
assert_eq!((x.div_exact(&y)).to_string(), "3+4i");
Source§

type Output = GaussianInteger

Source§

impl DivExact<&GaussianInteger> for &GaussianInteger

Source§

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

Divides a GaussianInteger by another GaussianInteger, taking both by reference. The first GaussianInteger 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}. $$

§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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Panics

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

§Examples
use malachite_base::num::arithmetic::traits::DivExact;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// (3+4i)(5-2i) = 23+14i
let x = GaussianInteger::from_str("23+14i").unwrap();
let y = GaussianInteger::from_str("5-2i").unwrap();
assert_eq!(((&x).div_exact(&y)).to_string(), "3+4i");
Source§

type Output = GaussianInteger

Source§

impl DivExact<GaussianInteger> for &GaussianInteger

Source§

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

Divides a GaussianInteger by another GaussianInteger, taking the first by reference and the second by value. The first GaussianInteger 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}. $$

§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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Panics

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

§Examples
use malachite_base::num::arithmetic::traits::DivExact;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// (3+4i)(5-2i) = 23+14i
let x = GaussianInteger::from_str("23+14i").unwrap();
let y = GaussianInteger::from_str("5-2i").unwrap();
assert_eq!(((&x).div_exact(y)).to_string(), "3+4i");
Source§

type Output = GaussianInteger

Source§

impl DivExactAssign for GaussianInteger

Source§

fn div_exact_assign(&mut self, other: Self)

Divides a GaussianInteger by another GaussianInteger in place, taking the GaussianInteger on the right-hand side by value. The first GaussianInteger 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}. $$

§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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Panics

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

§Examples
use malachite_base::num::arithmetic::traits::DivExactAssign;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// (3+4i)(5-2i) = 23+14i
let mut x = GaussianInteger::from_str("23+14i").unwrap();
x.div_exact_assign(GaussianInteger::from_str("5-2i").unwrap());
assert_eq!(x.to_string(), "3+4i");
Source§

impl DivExactAssign<&GaussianInteger> for GaussianInteger

Source§

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

Divides a GaussianInteger by another GaussianInteger in place, taking the GaussianInteger on the right-hand side by reference. The first GaussianInteger 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}. $$

§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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Panics

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

§Examples
use malachite_base::num::arithmetic::traits::DivExactAssign;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// (3+4i)(5-2i) = 23+14i
let mut x = GaussianInteger::from_str("23+14i").unwrap();
x.div_exact_assign(&GaussianInteger::from_str("5-2i").unwrap());
assert_eq!(x.to_string(), "3+4i");
Source§

impl DivI for GaussianInteger

Source§

fn div_i(self) -> Self

Divides a GaussianInteger by $i$, taking it by value. This is a clockwise quarter turn.

$$ f(a + bi) = (a + bi)/i = b - ai. $$

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::num::arithmetic::traits::DivI;
use malachite_base::num::basic::traits::I;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

assert_eq!(GaussianInteger::I.div_i().to_string(), "1");
assert_eq!(
    GaussianInteger::from_str("2-3i")
        .unwrap()
        .div_i()
        .to_string(),
    "-3-2i"
);
Source§

type Output = GaussianInteger

Source§

impl DivI for &GaussianInteger

Source§

fn div_i(self) -> GaussianInteger

Divides a GaussianInteger by $i$, taking it by reference. This is a clockwise quarter turn.

$$ f(a + bi) = (a + bi)/i = b - ai. $$

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is the maximum number of significant bits of the real and imaginary parts.

§Examples
use malachite_base::num::arithmetic::traits::DivI;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let x = GaussianInteger::from_str("2-3i").unwrap();
assert_eq!((&x).div_i().to_string(), "-3-2i");
Source§

type Output = GaussianInteger

Source§

impl DivIAssign for GaussianInteger

Source§

fn div_i_assign(&mut self)

Divides a GaussianInteger by $i$ in place. This is a clockwise quarter turn.

$$ a + bi \gets b - ai. $$

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::num::arithmetic::traits::DivIAssign;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let mut x = GaussianInteger::from_str("2-3i").unwrap();
x.div_i_assign();
assert_eq!(x.to_string(), "-3-2i");
Source§

impl DivRem for GaussianInteger

Source§

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

Divides a GaussianInteger by another GaussianInteger, taking both by value and returning the quotient and remainder.

The quotient is the Gaussian integer nearest to the exact quotient, with each part rounded to the nearest integer and ties rounded up; the remainder is what is left over. This is the division of the Gaussian integers as a Euclidean domain: the quotient and remainder satisfy $x = qy + r$ and $N(r) \leq N(y) / 2$, where $N$ is the norm, so the remainder is always smaller than the divisor.

$$ f(x, y) = (q, x - qy), \quad \text{where } q = \left \lfloor \frac{x \bar{y}}{N(y)} + \frac{1 + i}{2} \right \rfloor $$ and the floor is taken on each part.

§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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Panics

Panics if other is zero.

§Examples
use malachite_base::num::arithmetic::traits::DivRem;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// (2+i)(3) + (-1) = 5+3i
let x = GaussianInteger::from_str("5+3i").unwrap();
let y = GaussianInteger::from_str("2+i").unwrap();
let (q, r) = x.div_rem(y);
assert_eq!(q.to_string(), "3");
assert_eq!(r.to_string(), "-1");
Source§

type DivOutput = GaussianInteger

Source§

type RemOutput = GaussianInteger

Source§

impl DivRem<&GaussianInteger> for GaussianInteger

Source§

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

Divides a GaussianInteger by another GaussianInteger, taking the first by value and the second by reference and returning the quotient and remainder.

The quotient is the Gaussian integer nearest to the exact quotient, with each part rounded to the nearest integer and ties rounded up; the remainder is what is left over. This is the division of the Gaussian integers as a Euclidean domain: the quotient and remainder satisfy $x = qy + r$ and $N(r) \leq N(y) / 2$, where $N$ is the norm, so the remainder is always smaller than the divisor.

$$ f(x, y) = (q, x - qy), \quad \text{where } q = \left \lfloor \frac{x \bar{y}}{N(y)} + \frac{1 + i}{2} \right \rfloor $$ and the floor is taken on each part.

§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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Panics

Panics if other is zero.

§Examples
use malachite_base::num::arithmetic::traits::DivRem;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// (2+i)(3) + (-1) = 5+3i
let x = GaussianInteger::from_str("5+3i").unwrap();
let y = GaussianInteger::from_str("2+i").unwrap();
let (q, r) = x.div_rem(&y);
assert_eq!(q.to_string(), "3");
assert_eq!(r.to_string(), "-1");
Source§

type DivOutput = GaussianInteger

Source§

type RemOutput = GaussianInteger

Source§

impl DivRem<&GaussianInteger> for &GaussianInteger

Source§

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

Divides a GaussianInteger by another GaussianInteger, taking both by reference and returning the quotient and remainder.

The quotient is the Gaussian integer nearest to the exact quotient, with each part rounded to the nearest integer and ties rounded up; the remainder is what is left over. This is the division of the Gaussian integers as a Euclidean domain: the quotient and remainder satisfy $x = qy + r$ and $N(r) \leq N(y) / 2$, where $N$ is the norm, so the remainder is always smaller than the divisor.

$$ f(x, y) = (q, x - qy), \quad \text{where } q = \left \lfloor \frac{x \bar{y}}{N(y)} + \frac{1 + i}{2} \right \rfloor $$ and the floor is taken on each part.

§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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Panics

Panics if other is zero.

§Examples
use malachite_base::num::arithmetic::traits::DivRem;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// (2+i)(3) + (-1) = 5+3i
let x = GaussianInteger::from_str("5+3i").unwrap();
let y = GaussianInteger::from_str("2+i").unwrap();
let (q, r) = (&x).div_rem(&y);
assert_eq!(q.to_string(), "3");
assert_eq!(r.to_string(), "-1");
Source§

type DivOutput = GaussianInteger

Source§

type RemOutput = GaussianInteger

Source§

impl DivRem<GaussianInteger> for &GaussianInteger

Source§

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

Divides a GaussianInteger by another GaussianInteger, taking the first by reference and the second by value and returning the quotient and remainder.

The quotient is the Gaussian integer nearest to the exact quotient, with each part rounded to the nearest integer and ties rounded up; the remainder is what is left over. This is the division of the Gaussian integers as a Euclidean domain: the quotient and remainder satisfy $x = qy + r$ and $N(r) \leq N(y) / 2$, where $N$ is the norm, so the remainder is always smaller than the divisor.

$$ f(x, y) = (q, x - qy), \quad \text{where } q = \left \lfloor \frac{x \bar{y}}{N(y)} + \frac{1 + i}{2} \right \rfloor $$ and the floor is taken on each part.

§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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Panics

Panics if other is zero.

§Examples
use malachite_base::num::arithmetic::traits::DivRem;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// (2+i)(3) + (-1) = 5+3i
let x = GaussianInteger::from_str("5+3i").unwrap();
let y = GaussianInteger::from_str("2+i").unwrap();
let (q, r) = (&x).div_rem(y);
assert_eq!(q.to_string(), "3");
assert_eq!(r.to_string(), "-1");
Source§

type DivOutput = GaussianInteger

Source§

type RemOutput = GaussianInteger

Source§

impl Eq for GaussianInteger

Source§

impl EqAbs for GaussianInteger

Source§

fn eq_abs(&self, other: &Self) -> bool

Determines whether the absolute values of two GaussianIntegers are equal.

The absolute value of a complex number is its distance from the origin, so this is equivalent to comparing squared absolute values. The comparison delegates to OrdAbs, whose componentwise and crosswise screens usually decide the answer without computing the squared absolute values.

§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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Examples
use malachite_base::num::comparison::traits::EqAbs;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let x = GaussianInteger::from_str("1+2i").unwrap();
let y = GaussianInteger::from_str("-2+i").unwrap();
assert!(x.eq_abs(&y));

let x = GaussianInteger::from_str("2+2i").unwrap();
let y = GaussianInteger::from_str("3i").unwrap();
// |2+2i|^2 = 8 and |3i|^2 = 9
assert_eq!(x.eq_abs(&y), false);
Source§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
Source§

impl EqAbs<GaussianInteger> for Integer

Source§

fn eq_abs(&self, other: &GaussianInteger) -> bool

Determines whether the absolute values of an Integer and a GaussianInteger are equal.

§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 the maximum number of significant bits of the real and imaginary parts of other and of self.

§Examples
use malachite_base::num::comparison::traits::EqAbs;
use malachite_nz::gaussian_integer::GaussianInteger;
use malachite_nz::integer::Integer;
use std::str::FromStr;

// |3+4i| = 5
let y = GaussianInteger::from_str("3+4i").unwrap();
assert!(Integer::from(-5).eq_abs(&y));
assert_eq!(Integer::from(4).eq_abs(&y), false);
Source§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
Source§

impl EqAbs<GaussianInteger> for Natural

Source§

fn eq_abs(&self, other: &GaussianInteger) -> bool

Determines whether the absolute values of a Natural and a GaussianInteger are equal.

§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 the maximum number of significant bits of the real and imaginary parts of other and of self.

§Examples
use malachite_base::num::comparison::traits::EqAbs;
use malachite_nz::gaussian_integer::GaussianInteger;
use malachite_nz::natural::Natural;
use std::str::FromStr;

// |3+4i| = 5
let y = GaussianInteger::from_str("3+4i").unwrap();
assert!(Natural::from(5u32).eq_abs(&y));
assert_eq!(Natural::from(4u32).eq_abs(&y), false);
Source§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
Source§

impl EqAbs<GaussianInteger> for f32

Source§

fn eq_abs(&self, other: &GaussianInteger) -> bool

Determines whether the absolute values of a primitive float and a GaussianInteger are equal.

No infinity or NaN is equal in absolute value to a GaussianInteger.

§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 the maximum number of significant bits of the real and imaginary parts of other.

§Examples

See here.

Source§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
Source§

impl EqAbs<GaussianInteger> for f64

Source§

fn eq_abs(&self, other: &GaussianInteger) -> bool

Determines whether the absolute values of a primitive float and a GaussianInteger are equal.

No infinity or NaN is equal in absolute value to a GaussianInteger.

§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 the maximum number of significant bits of the real and imaginary parts of other.

§Examples

See here.

Source§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
Source§

impl EqAbs<GaussianInteger> for u8

Source§

fn eq_abs(&self, other: &GaussianInteger) -> bool

Determines whether the absolute values of an unsigned primitive integer and a GaussianInteger are equal.

§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 the maximum number of significant bits of the real and imaginary parts of other.

§Examples

See here.

Source§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
Source§

impl EqAbs<GaussianInteger> for u16

Source§

fn eq_abs(&self, other: &GaussianInteger) -> bool

Determines whether the absolute values of an unsigned primitive integer and a GaussianInteger are equal.

§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 the maximum number of significant bits of the real and imaginary parts of other.

§Examples

See here.

Source§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
Source§

impl EqAbs<GaussianInteger> for u32

Source§

fn eq_abs(&self, other: &GaussianInteger) -> bool

Determines whether the absolute values of an unsigned primitive integer and a GaussianInteger are equal.

§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 the maximum number of significant bits of the real and imaginary parts of other.

§Examples

See here.

Source§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
Source§

impl EqAbs<GaussianInteger> for u64

Source§

fn eq_abs(&self, other: &GaussianInteger) -> bool

Determines whether the absolute values of an unsigned primitive integer and a GaussianInteger are equal.

§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 the maximum number of significant bits of the real and imaginary parts of other.

§Examples

See here.

Source§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
Source§

impl EqAbs<GaussianInteger> for u128

Source§

fn eq_abs(&self, other: &GaussianInteger) -> bool

Determines whether the absolute values of an unsigned primitive integer and a GaussianInteger are equal.

§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 the maximum number of significant bits of the real and imaginary parts of other.

§Examples

See here.

Source§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
Source§

impl EqAbs<GaussianInteger> for usize

Source§

fn eq_abs(&self, other: &GaussianInteger) -> bool

Determines whether the absolute values of an unsigned primitive integer and a GaussianInteger are equal.

§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 the maximum number of significant bits of the real and imaginary parts of other.

§Examples

See here.

Source§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
Source§

impl EqAbs<GaussianInteger> for i8

Source§

fn eq_abs(&self, other: &GaussianInteger) -> bool

Determines whether the absolute values of a signed primitive integer and a GaussianInteger are equal.

§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 the maximum number of significant bits of the real and imaginary parts of other.

§Examples

See here.

Source§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
Source§

impl EqAbs<GaussianInteger> for i16

Source§

fn eq_abs(&self, other: &GaussianInteger) -> bool

Determines whether the absolute values of a signed primitive integer and a GaussianInteger are equal.

§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 the maximum number of significant bits of the real and imaginary parts of other.

§Examples

See here.

Source§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
Source§

impl EqAbs<GaussianInteger> for i32

Source§

fn eq_abs(&self, other: &GaussianInteger) -> bool

Determines whether the absolute values of a signed primitive integer and a GaussianInteger are equal.

§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 the maximum number of significant bits of the real and imaginary parts of other.

§Examples

See here.

Source§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
Source§

impl EqAbs<GaussianInteger> for i64

Source§

fn eq_abs(&self, other: &GaussianInteger) -> bool

Determines whether the absolute values of a signed primitive integer and a GaussianInteger are equal.

§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 the maximum number of significant bits of the real and imaginary parts of other.

§Examples

See here.

Source§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
Source§

impl EqAbs<GaussianInteger> for i128

Source§

fn eq_abs(&self, other: &GaussianInteger) -> bool

Determines whether the absolute values of a signed primitive integer and a GaussianInteger are equal.

§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 the maximum number of significant bits of the real and imaginary parts of other.

§Examples

See here.

Source§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
Source§

impl EqAbs<GaussianInteger> for isize

Source§

fn eq_abs(&self, other: &GaussianInteger) -> bool

Determines whether the absolute values of a signed primitive integer and a GaussianInteger are equal.

§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 the maximum number of significant bits of the real and imaginary parts of other.

§Examples

See here.

Source§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
Source§

impl EqAbs<Integer> for GaussianInteger

Source§

fn eq_abs(&self, other: &Integer) -> bool

Determines whether the absolute values of a GaussianInteger and an Integer are equal.

The absolute value of a complex number is its distance from the origin, so two values are equal in absolute value exactly when their squared absolute values are equal. Purely real and purely imaginary values are handled by comparing single components. Otherwise, equality is impossible unless both components are smaller in absolute value than the real operand, so the squared absolute values are only computed in that case.

§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 the maximum number of significant bits of the real and imaginary parts of self and of other.

§Examples
use malachite_base::num::comparison::traits::EqAbs;
use malachite_nz::gaussian_integer::GaussianInteger;
use malachite_nz::integer::Integer;
use std::str::FromStr;

// |3+4i| = 5
let x = GaussianInteger::from_str("3+4i").unwrap();
assert!(x.eq_abs(&Integer::from(5)));
assert!(x.eq_abs(&Integer::from(-5)));
assert_eq!(x.eq_abs(&Integer::from(4)), false);
Source§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
Source§

impl EqAbs<Natural> for GaussianInteger

Source§

fn eq_abs(&self, other: &Natural) -> bool

Determines whether the absolute values of a GaussianInteger and a Natural are equal.

The absolute value of a complex number is its distance from the origin, so two values are equal in absolute value exactly when their squared absolute values are equal. Purely real and purely imaginary values are handled by comparing single components. Otherwise, equality is impossible unless both components are smaller in absolute value than the real operand, so the squared absolute values are only computed in that case.

§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 the maximum number of significant bits of the real and imaginary parts of self and of other.

§Examples
use malachite_base::num::comparison::traits::EqAbs;
use malachite_nz::gaussian_integer::GaussianInteger;
use malachite_nz::natural::Natural;
use std::str::FromStr;

// |3+4i| = 5
let x = GaussianInteger::from_str("3+4i").unwrap();
assert!(x.eq_abs(&Natural::from(5u32)));
assert_eq!(x.eq_abs(&Natural::from(4u32)), false);
Source§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
Source§

impl EqAbs<f32> for GaussianInteger

Source§

fn eq_abs(&self, other: &f32) -> bool

Determines whether the absolute values of a GaussianInteger and a primitive float are equal.

No GaussianInteger is equal in absolute value to an infinity or NaN. If the float is not an integer, its square is not an integer either (its odd mantissa contributes an odd square), so it cannot equal the absolute value of any GaussianInteger.

§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 the maximum number of significant bits of the real and imaginary parts of self.

§Examples

See here.

Source§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
Source§

impl EqAbs<f64> for GaussianInteger

Source§

fn eq_abs(&self, other: &f64) -> bool

Determines whether the absolute values of a GaussianInteger and a primitive float are equal.

No GaussianInteger is equal in absolute value to an infinity or NaN. If the float is not an integer, its square is not an integer either (its odd mantissa contributes an odd square), so it cannot equal the absolute value of any GaussianInteger.

§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 the maximum number of significant bits of the real and imaginary parts of self.

§Examples

See here.

Source§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
Source§

impl EqAbs<i8> for GaussianInteger

Source§

fn eq_abs(&self, other: &i8) -> bool

Determines whether the absolute values of a GaussianInteger and a signed primitive integer are equal.

§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 the maximum number of significant bits of the real and imaginary parts of self.

§Examples

See here.

Source§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
Source§

impl EqAbs<i16> for GaussianInteger

Source§

fn eq_abs(&self, other: &i16) -> bool

Determines whether the absolute values of a GaussianInteger and a signed primitive integer are equal.

§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 the maximum number of significant bits of the real and imaginary parts of self.

§Examples

See here.

Source§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
Source§

impl EqAbs<i32> for GaussianInteger

Source§

fn eq_abs(&self, other: &i32) -> bool

Determines whether the absolute values of a GaussianInteger and a signed primitive integer are equal.

§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 the maximum number of significant bits of the real and imaginary parts of self.

§Examples

See here.

Source§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
Source§

impl EqAbs<i64> for GaussianInteger

Source§

fn eq_abs(&self, other: &i64) -> bool

Determines whether the absolute values of a GaussianInteger and a signed primitive integer are equal.

§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 the maximum number of significant bits of the real and imaginary parts of self.

§Examples

See here.

Source§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
Source§

impl EqAbs<i128> for GaussianInteger

Source§

fn eq_abs(&self, other: &i128) -> bool

Determines whether the absolute values of a GaussianInteger and a signed primitive integer are equal.

§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 the maximum number of significant bits of the real and imaginary parts of self.

§Examples

See here.

Source§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
Source§

impl EqAbs<isize> for GaussianInteger

Source§

fn eq_abs(&self, other: &isize) -> bool

Determines whether the absolute values of a GaussianInteger and a signed primitive integer are equal.

§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 the maximum number of significant bits of the real and imaginary parts of self.

§Examples

See here.

Source§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
Source§

impl EqAbs<u8> for GaussianInteger

Source§

fn eq_abs(&self, other: &u8) -> bool

Determines whether the absolute values of a GaussianInteger and an unsigned primitive integer are equal.

§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 the maximum number of significant bits of the real and imaginary parts of self.

§Examples

See here.

Source§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
Source§

impl EqAbs<u16> for GaussianInteger

Source§

fn eq_abs(&self, other: &u16) -> bool

Determines whether the absolute values of a GaussianInteger and an unsigned primitive integer are equal.

§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 the maximum number of significant bits of the real and imaginary parts of self.

§Examples

See here.

Source§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
Source§

impl EqAbs<u32> for GaussianInteger

Source§

fn eq_abs(&self, other: &u32) -> bool

Determines whether the absolute values of a GaussianInteger and an unsigned primitive integer are equal.

§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 the maximum number of significant bits of the real and imaginary parts of self.

§Examples

See here.

Source§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
Source§

impl EqAbs<u64> for GaussianInteger

Source§

fn eq_abs(&self, other: &u64) -> bool

Determines whether the absolute values of a GaussianInteger and an unsigned primitive integer are equal.

§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 the maximum number of significant bits of the real and imaginary parts of self.

§Examples

See here.

Source§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
Source§

impl EqAbs<u128> for GaussianInteger

Source§

fn eq_abs(&self, other: &u128) -> bool

Determines whether the absolute values of a GaussianInteger and an unsigned primitive integer are equal.

§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 the maximum number of significant bits of the real and imaginary parts of self.

§Examples

See here.

Source§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
Source§

impl EqAbs<usize> for GaussianInteger

Source§

fn eq_abs(&self, other: &usize) -> bool

Determines whether the absolute values of a GaussianInteger and an unsigned primitive integer are equal.

§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 the maximum number of significant bits of the real and imaginary parts of self.

§Examples

See here.

Source§

fn ne_abs(&self, other: &Rhs) -> bool

Compares the absolute values of two numbers for inequality, taking both by reference. Read more
Source§

impl<T> From<T> for GaussianInteger
where Integer: From<T>,

Source§

fn from(x: T) -> Self

Converts a value of any type that converts to an Integer — including Integer itself, via the standard library’s reflexive From — to a purely real GaussianInteger.

§Worst-case complexity

Same as the complexity of the corresponding Integer conversion.

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

assert_eq!(GaussianInteger::from(123u32).to_string(), "123");
assert_eq!(GaussianInteger::from(-123i64).to_string(), "-123");
assert_eq!(
    GaussianInteger::from(Natural::from(123u32)).to_string(),
    "123"
);
assert_eq!(
    GaussianInteger::from(Integer::from(-123)).to_string(),
    "-123"
);
Source§

impl FromStr for GaussianInteger

Source§

fn from_str(s: &str) -> Result<Self, ()>

Converts a string to a GaussianInteger.

If the string does not represent a valid GaussianInteger, an Err is returned. The grammar is strict about structure: the real term must precede the imaginary term, the imaginary term must end in 'i', and no whitespace is allowed. It is permissive about coefficients, much as Rational’s parser accepts fractions that are not in lowest terms: "1i", "0i", "2+0i", and "0+1i" are all accepted, although Display never produces them. Each component follows Integer’s syntax, so leading zeros are allowed, and so is a single leading '-' or '+' on the leading term.

§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::gaussian_integer::GaussianInteger;

assert_eq!(GaussianInteger::from_str("0").unwrap().to_string(), "0");
assert_eq!(GaussianInteger::from_str("-2").unwrap().to_string(), "-2");
assert_eq!(GaussianInteger::from_str("i").unwrap().to_string(), "i");
assert_eq!(GaussianInteger::from_str("-i").unwrap().to_string(), "-i");
assert_eq!(
    GaussianInteger::from_str("2-3i").unwrap().to_string(),
    "2-3i"
);
assert_eq!(GaussianInteger::from_str("1i").unwrap().to_string(), "i");
assert_eq!(GaussianInteger::from_str("0i").unwrap().to_string(), "0");
assert_eq!(GaussianInteger::from_str("2+0i").unwrap().to_string(), "2");
assert_eq!(
    GaussianInteger::from_str("+2+1i").unwrap().to_string(),
    "2+i"
);

assert!(GaussianInteger::from_str("").is_err());
assert!(GaussianInteger::from_str("i+1").is_err());
assert!(GaussianInteger::from_str("1 + i").is_err());
assert!(GaussianInteger::from_str("2+-3i").is_err());
assert!(GaussianInteger::from_str("2ii").is_err());
Source§

type Err = ()

The associated error which can be returned from parsing.
Source§

impl Gcd for GaussianInteger

Source§

fn gcd(self, other: Self) -> Self

Computes the GCD (greatest common divisor) of two GaussianIntegers, taking both by value.

The Gaussian integers are a Euclidean domain, so any two have a GCD, defined up to multiplication by one of the four units $\pm 1, \pm i$. The one returned is in canonical unit form (see CanonicalizeUnit): its real part is positive and its imaginary part lies in $(-\text{real}, \text{real}]$, unless it is zero. The GCD of 0 and $x$ is the canonical form of $x$; in particular $\gcd(0, 0) = 0$, which makes sense if we interpret “greatest” to mean “greatest by the divisibility order”.

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

§Worst-case complexity

$T(n) = O(n^2)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is the maximum number of significant bits of the real and imaginary parts of self and other.

§Examples
use malachite_base::num::arithmetic::traits::Gcd;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// 3+4i = (2+i)^2 and 5 = (2+i)(2-i)
let x = GaussianInteger::from_str("3+4i").unwrap();
let y = GaussianInteger::from(5);
assert_eq!((x.gcd(y)).to_string(), "2+i");
Source§

type Output = GaussianInteger

Source§

impl Gcd<&GaussianInteger> for GaussianInteger

Source§

fn gcd(self, other: &Self) -> Self

Computes the GCD (greatest common divisor) of two GaussianIntegers, taking the first by value and the second by reference.

The Gaussian integers are a Euclidean domain, so any two have a GCD, defined up to multiplication by one of the four units $\pm 1, \pm i$. The one returned is in canonical unit form (see CanonicalizeUnit): its real part is positive and its imaginary part lies in $(-\text{real}, \text{real}]$, unless it is zero. The GCD of 0 and $x$ is the canonical form of $x$; in particular $\gcd(0, 0) = 0$, which makes sense if we interpret “greatest” to mean “greatest by the divisibility order”.

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

§Worst-case complexity

$T(n) = O(n^2)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is the maximum number of significant bits of the real and imaginary parts of self and other.

§Examples
use malachite_base::num::arithmetic::traits::Gcd;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// 3+4i = (2+i)^2 and 5 = (2+i)(2-i)
let x = GaussianInteger::from_str("3+4i").unwrap();
let y = GaussianInteger::from(5);
assert_eq!((x.gcd(&y)).to_string(), "2+i");
Source§

type Output = GaussianInteger

Source§

impl Gcd<&GaussianInteger> for &GaussianInteger

Source§

fn gcd(self, other: &GaussianInteger) -> GaussianInteger

Computes the GCD (greatest common divisor) of two GaussianIntegers, taking both by reference.

The Gaussian integers are a Euclidean domain, so any two have a GCD, defined up to multiplication by one of the four units $\pm 1, \pm i$. The one returned is in canonical unit form (see CanonicalizeUnit): its real part is positive and its imaginary part lies in $(-\text{real}, \text{real}]$, unless it is zero. The GCD of 0 and $x$ is the canonical form of $x$; in particular $\gcd(0, 0) = 0$, which makes sense if we interpret “greatest” to mean “greatest by the divisibility order”.

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

§Worst-case complexity

$T(n) = O(n^2)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is the maximum number of significant bits of the real and imaginary parts of self and other.

§Examples
use malachite_base::num::arithmetic::traits::Gcd;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// 3+4i = (2+i)^2 and 5 = (2+i)(2-i)
let x = GaussianInteger::from_str("3+4i").unwrap();
let y = GaussianInteger::from(5);
assert_eq!(((&x).gcd(&y)).to_string(), "2+i");
Source§

type Output = GaussianInteger

Source§

impl Gcd<GaussianInteger> for &GaussianInteger

Source§

fn gcd(self, other: GaussianInteger) -> GaussianInteger

Computes the GCD (greatest common divisor) of two GaussianIntegers, taking the first by reference and the second by value.

The Gaussian integers are a Euclidean domain, so any two have a GCD, defined up to multiplication by one of the four units $\pm 1, \pm i$. The one returned is in canonical unit form (see CanonicalizeUnit): its real part is positive and its imaginary part lies in $(-\text{real}, \text{real}]$, unless it is zero. The GCD of 0 and $x$ is the canonical form of $x$; in particular $\gcd(0, 0) = 0$, which makes sense if we interpret “greatest” to mean “greatest by the divisibility order”.

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

§Worst-case complexity

$T(n) = O(n^2)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is the maximum number of significant bits of the real and imaginary parts of self and other.

§Examples
use malachite_base::num::arithmetic::traits::Gcd;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// 3+4i = (2+i)^2 and 5 = (2+i)(2-i)
let x = GaussianInteger::from_str("3+4i").unwrap();
let y = GaussianInteger::from(5);
assert_eq!(((&x).gcd(y)).to_string(), "2+i");
Source§

type Output = GaussianInteger

Source§

impl GcdAssign for GaussianInteger

Source§

fn gcd_assign(&mut self, other: Self)

Replaces a GaussianInteger by its GCD (greatest common divisor) with another GaussianInteger, taking the GaussianInteger on the right-hand side by value.

The Gaussian integers are a Euclidean domain, so any two have a GCD, defined up to multiplication by one of the four units $\pm 1, \pm i$. The one returned is in canonical unit form (see CanonicalizeUnit): its real part is positive and its imaginary part lies in $(-\text{real}, \text{real}]$, unless it is zero. The GCD of 0 and $x$ is the canonical form of $x$; in particular $\gcd(0, 0) = 0$, which makes sense if we interpret “greatest” to mean “greatest by the divisibility order”.

$$ x \gets \gcd(x, y). $$

§Worst-case complexity

$T(n) = O(n^2)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is the maximum number of significant bits of the real and imaginary parts of self and other.

§Examples
use malachite_base::num::arithmetic::traits::GcdAssign;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// 3+4i = (2+i)^2 and 5 = (2+i)(2-i)
let mut x = GaussianInteger::from_str("3+4i").unwrap();
x.gcd_assign(GaussianInteger::from(5));
assert_eq!(x.to_string(), "2+i");
Source§

impl GcdAssign<&GaussianInteger> for GaussianInteger

Source§

fn gcd_assign(&mut self, other: &Self)

Replaces a GaussianInteger by its GCD (greatest common divisor) with another GaussianInteger, taking the GaussianInteger on the right-hand side by reference.

The Gaussian integers are a Euclidean domain, so any two have a GCD, defined up to multiplication by one of the four units $\pm 1, \pm i$. The one returned is in canonical unit form (see CanonicalizeUnit): its real part is positive and its imaginary part lies in $(-\text{real}, \text{real}]$, unless it is zero. The GCD of 0 and $x$ is the canonical form of $x$; in particular $\gcd(0, 0) = 0$, which makes sense if we interpret “greatest” to mean “greatest by the divisibility order”.

$$ x \gets \gcd(x, y). $$

§Worst-case complexity

$T(n) = O(n^2)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is the maximum number of significant bits of the real and imaginary parts of self and other.

§Examples
use malachite_base::num::arithmetic::traits::GcdAssign;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// 3+4i = (2+i)^2 and 5 = (2+i)(2-i)
let mut x = GaussianInteger::from_str("3+4i").unwrap();
x.gcd_assign(&GaussianInteger::from(5));
assert_eq!(x.to_string(), "2+i");
Source§

impl Hash for GaussianInteger

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

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
Source§

impl Height for GaussianInteger

Source§

fn to_height(&self) -> Natural

Returns the height of a GaussianInteger: the larger of the absolute values of its real and imaginary parts, taking the GaussianInteger by reference and cloning.

$$ f(a + bi) = H(a + bi) = \max(|a|, |b|). $$

§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::arithmetic::traits::Height;
use malachite_nz::gaussian_integer::GaussianInteger;

assert_eq!(GaussianInteger::from_str("3-5i").unwrap().to_height(), 5);
assert_eq!(GaussianInteger::from_str("-7").unwrap().to_height(), 7);
assert_eq!(GaussianInteger::from_str("0").unwrap().to_height(), 0);
Source§

fn into_height(self) -> Natural

Returns the height of a GaussianInteger: the larger of the absolute values of its real and imaginary parts, taking the GaussianInteger by value.

The larger part is moved out rather than cloned.

§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 core::str::FromStr;
use malachite_base::num::arithmetic::traits::Height;
use malachite_nz::gaussian_integer::GaussianInteger;

assert_eq!(GaussianInteger::from_str("3-5i").unwrap().into_height(), 5);
assert_eq!(GaussianInteger::from_str("0").unwrap().into_height(), 0);
Source§

fn height_significant_bits(&self) -> u64

Returns the number of significant bits of the height of a GaussianInteger.

Since bit length is monotone, this is the larger of the two parts’ bit lengths, without materializing the height.

§Worst-case complexity

Constant time and additional memory.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::Height;
use malachite_nz::gaussian_integer::GaussianInteger;

assert_eq!(
    GaussianInteger::from_str("3-5i")
        .unwrap()
        .height_significant_bits(),
    3
);
assert_eq!(
    GaussianInteger::from_str("0")
        .unwrap()
        .height_significant_bits(),
    0
);
Source§

type Output = Natural

Source§

impl HeightRef for GaussianInteger

Source§

fn height_ref(&self) -> &Natural

Returns a reference to the height of a GaussianInteger: the larger of the absolute values of its real and imaginary parts.

An Integer holds its magnitude as a Natural, so the height is already there to be lent and nothing needs to be built.

§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 core::str::FromStr;
use malachite_base::num::arithmetic::traits::HeightRef;
use malachite_nz::gaussian_integer::GaussianInteger;

assert_eq!(*GaussianInteger::from_str("3-5i").unwrap().height_ref(), 5);
assert_eq!(*GaussianInteger::from_str("0").unwrap().height_ref(), 0);
Source§

impl I for GaussianInteger

The constant i.

Source§

const I: Self

Source§

impl<T> ImaginaryFrom<T> for GaussianInteger
where Integer: From<T>,

Source§

fn imaginary_from(x: T) -> Self

Converts a value of any type that converts to an Integer — including Integer itself — to a purely imaginary GaussianInteger.

§Worst-case complexity

Same as the complexity of the corresponding Integer conversion.

§Examples
use malachite_base::num::conversion::traits::ImaginaryFrom;
use malachite_nz::gaussian_integer::GaussianInteger;
use malachite_nz::integer::Integer;
use malachite_nz::natural::Natural;

assert_eq!(GaussianInteger::imaginary_from(123u32).to_string(), "123i");
assert_eq!(
    GaussianInteger::imaginary_from(-123i64).to_string(),
    "-123i"
);
assert_eq!(
    GaussianInteger::imaginary_from(Natural::from(123u32)).to_string(),
    "123i"
);
assert_eq!(
    GaussianInteger::imaginary_from(Integer::from(-123)).to_string(),
    "-123i"
);
Source§

impl IsGaussianInteger for &GaussianInteger

Source§

fn is_gaussian_integer(self) -> bool

Determines whether a GaussianInteger is a Gaussian integer. It always returns true.

$f(x) = \textrm{true}$.

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::num::basic::traits::{I, One, Zero};
use malachite_base::num::conversion::traits::IsGaussianInteger;
use malachite_nz::gaussian_integer::GaussianInteger;

assert_eq!(GaussianInteger::ZERO.is_gaussian_integer(), true);
assert_eq!(GaussianInteger::ONE.is_gaussian_integer(), true);
assert_eq!(GaussianInteger::I.is_gaussian_integer(), true);
Source§

impl IsInteger for &GaussianInteger

Source§

fn is_integer(self) -> bool

Determines whether a GaussianInteger is an integer: that is, whether its imaginary part is zero.

$f(x) = x \in \Z$.

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::num::basic::traits::{I, One, Zero};
use malachite_base::num::conversion::traits::IsInteger;
use malachite_nz::gaussian_integer::GaussianInteger;

assert_eq!(GaussianInteger::ZERO.is_integer(), true);
assert_eq!(GaussianInteger::ONE.is_integer(), true);
assert_eq!(GaussianInteger::I.is_integer(), false);
assert_eq!(GaussianInteger::from(-100).is_integer(), true);
Source§

impl IsPowerOf2 for GaussianInteger

Source§

fn is_power_of_2(&self) -> bool

Determines whether a GaussianInteger is an integer power of 2.

Only purely real, positive values qualify; in particular, $i$ and its multiples are not powers of 2.

$f(x) = (\exists n \in \N : 2^n = x)$.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

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

§Examples
use malachite_base::num::arithmetic::traits::IsPowerOf2;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

assert_eq!(GaussianInteger::from(0x80).is_power_of_2(), true);
assert_eq!(GaussianInteger::from(-0x80).is_power_of_2(), false);
assert_eq!(GaussianInteger::from(0x81).is_power_of_2(), false);
assert_eq!(
    GaussianInteger::from_str("128i").unwrap().is_power_of_2(),
    false
);
assert_eq!(
    GaussianInteger::from_str("128+i").unwrap().is_power_of_2(),
    false
);
Source§

impl IsReal for &GaussianInteger

Source§

fn is_real(self) -> bool

Determines whether a GaussianInteger is a real number: that is, whether its imaginary part is zero.

$f(x) = x \in \R$.

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::num::basic::traits::{I, One, Zero};
use malachite_base::num::conversion::traits::IsReal;
use malachite_nz::gaussian_integer::GaussianInteger;

assert_eq!(GaussianInteger::ZERO.is_real(), true);
assert_eq!(GaussianInteger::ONE.is_real(), true);
assert_eq!(GaussianInteger::I.is_real(), false);
assert_eq!(GaussianInteger::from(-100).is_real(), true);
Source§

impl IsUnit for GaussianInteger

Source§

fn is_unit(&self) -> bool

Determines whether a GaussianInteger is a unit: one of $1$, $-1$, $i$, and $-i$, the four elements of $\mathbb{Z}[i]$ with a multiplicative inverse in $\mathbb{Z}[i]$.

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::num::arithmetic::traits::IsUnit;
use malachite_base::num::basic::traits::{I, NegativeI, NegativeOne, One, Two, Zero};
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

assert_eq!(GaussianInteger::ONE.is_unit(), true);
assert_eq!(GaussianInteger::NEGATIVE_ONE.is_unit(), true);
assert_eq!(GaussianInteger::I.is_unit(), true);
assert_eq!(GaussianInteger::NEGATIVE_I.is_unit(), true);
assert_eq!(GaussianInteger::ZERO.is_unit(), false);
assert_eq!(GaussianInteger::from_str("1+i").unwrap().is_unit(), false);
assert_eq!(GaussianInteger::TWO.is_unit(), false);
Source§

impl Mul for GaussianInteger

Source§

fn mul(self, other: Self) -> Self

Multiplies two GaussianIntegers, 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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Examples
use malachite_base::num::basic::traits::{I, One};
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

assert_eq!(
    GaussianInteger::I * -GaussianInteger::I,
    GaussianInteger::ONE
);
let x = GaussianInteger::from_str("2-3i").unwrap();
let y = GaussianInteger::from_str("-1+4i").unwrap();
assert_eq!((x * y).to_string(), "10+11i");
Source§

type Output = GaussianInteger

The resulting type after applying the * operator.
Source§

impl Mul<&GaussianInteger> for GaussianInteger

Source§

fn mul(self, other: &Self) -> Self

Multiplies two GaussianIntegers, 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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Examples
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let x = GaussianInteger::from_str("2-3i").unwrap();
let y = GaussianInteger::from_str("-1+4i").unwrap();
assert_eq!((x * &y).to_string(), "10+11i");
Source§

type Output = GaussianInteger

The resulting type after applying the * operator.
Source§

impl Mul<&GaussianInteger> for &GaussianInteger

Source§

fn mul(self, other: &GaussianInteger) -> GaussianInteger

Multiplies two GaussianIntegers, 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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Examples
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let x = GaussianInteger::from_str("2-3i").unwrap();
let y = GaussianInteger::from_str("-1+4i").unwrap();
assert_eq!((&x * &y).to_string(), "10+11i");
Source§

type Output = GaussianInteger

The resulting type after applying the * operator.
Source§

impl Mul<GaussianInteger> for &GaussianInteger

Source§

fn mul(self, other: GaussianInteger) -> GaussianInteger

Multiplies two GaussianIntegers, 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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Examples
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let x = GaussianInteger::from_str("2-3i").unwrap();
let y = GaussianInteger::from_str("-1+4i").unwrap();
assert_eq!((&x * y).to_string(), "10+11i");
Source§

type Output = GaussianInteger

The resulting type after applying the * operator.
Source§

impl MulAssign for GaussianInteger

Source§

fn mul_assign(&mut self, other: Self)

Multiplies a GaussianInteger by a GaussianInteger in place, taking the GaussianInteger 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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Examples
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let x = GaussianInteger::from_str("2-3i").unwrap();
let y = GaussianInteger::from_str("-1+4i").unwrap();
let mut product = x;
product *= y;
assert_eq!(product.to_string(), "10+11i");
Source§

impl MulAssign<&GaussianInteger> for GaussianInteger

Source§

fn mul_assign(&mut self, other: &Self)

Multiplies a GaussianInteger by a GaussianInteger in place, taking the GaussianInteger 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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Examples
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let x = GaussianInteger::from_str("2-3i").unwrap();
let y = GaussianInteger::from_str("-1+4i").unwrap();
let mut product = x;
product *= &y;
assert_eq!(product.to_string(), "10+11i");
Source§

impl MulI for GaussianInteger

Source§

fn mul_i(self) -> Self

Multiplies a GaussianInteger by $i$, taking it by value. This is a counterclockwise quarter turn.

$$ f(a + bi) = (a + bi)i = -b + ai. $$

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::num::arithmetic::traits::MulI;
use malachite_base::num::basic::traits::I;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

assert_eq!(GaussianInteger::I.mul_i().to_string(), "-1");
assert_eq!(
    GaussianInteger::from_str("2-3i")
        .unwrap()
        .mul_i()
        .to_string(),
    "3+2i"
);
Source§

type Output = GaussianInteger

Source§

impl MulI for &GaussianInteger

Source§

fn mul_i(self) -> GaussianInteger

Multiplies a GaussianInteger by $i$, taking it by reference. This is a counterclockwise quarter turn.

$$ f(a + bi) = (a + bi)i = -b + ai. $$

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is the maximum number of significant bits of the real and imaginary parts.

§Examples
use malachite_base::num::arithmetic::traits::MulI;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let x = GaussianInteger::from_str("2-3i").unwrap();
assert_eq!((&x).mul_i().to_string(), "3+2i");
Source§

type Output = GaussianInteger

Source§

impl MulIAssign for GaussianInteger

Source§

fn mul_i_assign(&mut self)

Multiplies a GaussianInteger by $i$ in place. This is a counterclockwise quarter turn.

$$ a + bi \gets -b + ai. $$

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::num::arithmetic::traits::MulIAssign;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let mut x = GaussianInteger::from_str("2-3i").unwrap();
x.mul_i_assign();
assert_eq!(x.to_string(), "3+2i");
Source§

impl MulIPow for GaussianInteger

Source§

fn mul_i_pow(self, k: u64) -> Self

Multiplies a GaussianInteger by $i^k$, taking the GaussianInteger by value.

Only $k$ modulo 4 matters: $i^0 = 1$, $i^1 = i$, $i^2 = -1$, and $i^3 = -i$, so the result is the number itself, a counterclockwise quarter turn, a half turn, or a clockwise quarter turn. Since $i^{-k} = i^{3k}$, a negative power is a matter of tripling the exponent.

$$ f(x, k) = i^k x. $$

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::num::arithmetic::traits::MulIPow;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let x = GaussianInteger::from_str("2+3i").unwrap();
assert_eq!(x.clone().mul_i_pow(0).to_string(), "2+3i");
assert_eq!(x.clone().mul_i_pow(1).to_string(), "-3+2i");
assert_eq!(x.clone().mul_i_pow(2).to_string(), "-2-3i");
assert_eq!(x.clone().mul_i_pow(3).to_string(), "3-2i");
assert_eq!(x.mul_i_pow(1000000000001).to_string(), "-3+2i");
Source§

type Output = GaussianInteger

Source§

impl MulIPow for &GaussianInteger

Source§

fn mul_i_pow(self, k: u64) -> GaussianInteger

Multiplies a GaussianInteger by $i^k$, taking the GaussianInteger by reference.

Only $k$ modulo 4 matters: $i^0 = 1$, $i^1 = i$, $i^2 = -1$, and $i^3 = -i$, so the result is the number itself, a counterclockwise quarter turn, a half turn, or a clockwise quarter turn. Since $i^{-k} = i^{3k}$, a negative power is a matter of tripling the exponent.

$$ f(x, k) = i^k 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::MulIPow;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let x = GaussianInteger::from_str("2+3i").unwrap();
assert_eq!((&x).mul_i_pow(0).to_string(), "2+3i");
assert_eq!((&x).mul_i_pow(1).to_string(), "-3+2i");
assert_eq!((&x).mul_i_pow(2).to_string(), "-2-3i");
assert_eq!((&x).mul_i_pow(3).to_string(), "3-2i");
assert_eq!((&x).mul_i_pow(1000000000001).to_string(), "-3+2i");
Source§

type Output = GaussianInteger

Source§

impl MulIPowAssign for GaussianInteger

Source§

fn mul_i_pow_assign(&mut self, k: u64)

Multiplies a GaussianInteger by $i^k$ in place.

Only $k$ modulo 4 matters: $i^0 = 1$, $i^1 = i$, $i^2 = -1$, and $i^3 = -i$, so the result is the number itself, a counterclockwise quarter turn, a half turn, or a clockwise quarter turn. Since $i^{-k} = i^{3k}$, a negative power is a matter of tripling the exponent.

$$ x \gets i^k x. $$

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::num::arithmetic::traits::MulIPowAssign;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let mut x = GaussianInteger::from_str("2+3i").unwrap();
x.mul_i_pow_assign(1);
assert_eq!(x.to_string(), "-3+2i");
x.mul_i_pow_assign(2);
assert_eq!(x.to_string(), "3-2i");
x.mul_i_pow_assign(1000000000001);
assert_eq!(x.to_string(), "2+3i");
Source§

impl Named for GaussianInteger

Source§

const NAME: &'static str = "GaussianInteger"

The name of this type, as given by the stringify macro.

See the documentation for impl_named for more details.

Source§

impl Neg for GaussianInteger

Source§

fn neg(self) -> Self

Negates a GaussianInteger, taking it by value. Both the real and imaginary parts are negated.

$$ f(x) = -x. $$

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::num::basic::traits::{I, Zero};
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

assert_eq!((-GaussianInteger::ZERO).to_string(), "0");
assert_eq!((-GaussianInteger::I).to_string(), "-i");
assert_eq!(
    (-GaussianInteger::from_str("2-3i").unwrap()).to_string(),
    "-2+3i"
);
Source§

type Output = GaussianInteger

The resulting type after applying the - operator.
Source§

impl Neg for &GaussianInteger

Source§

fn neg(self) -> GaussianInteger

Negates a GaussianInteger, taking it by reference. Both the real and imaginary parts are negated.

$$ 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 the maximum number of significant bits of the real and imaginary parts.

§Examples
use malachite_base::num::basic::traits::{I, Zero};
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

assert_eq!((-&GaussianInteger::ZERO).to_string(), "0");
assert_eq!((-&GaussianInteger::I).to_string(), "-i");
let x = GaussianInteger::from_str("2-3i").unwrap();
assert_eq!((-&x).to_string(), "-2+3i");
Source§

type Output = GaussianInteger

The resulting type after applying the - operator.
Source§

impl NegAssign for GaussianInteger

Source§

fn neg_assign(&mut self)

Negates a GaussianInteger in place. Both the real and imaginary parts are negated.

$$ x \gets -x. $$

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::num::arithmetic::traits::NegAssign;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let mut x = GaussianInteger::from_str("2-3i").unwrap();
x.neg_assign();
assert_eq!(x.to_string(), "-2+3i");
Source§

impl NegativeI for GaussianInteger

The constant -i.

Source§

const NEGATIVE_I: Self

Source§

impl NegativeOne for GaussianInteger

The constant -1.

Source§

impl One for GaussianInteger

The constant 1.

Source§

const ONE: Self

Source§

impl OrdAbs for GaussianInteger

Source§

fn cmp_abs(&self, other: &Self) -> Ordering

Compares the absolute values of two GaussianIntegers.

The absolute value of a complex number is its distance from the origin, so this is equivalent to comparing squared absolute values:

$$ f(x, y) = \operatorname{cmp}(|x|, |y|) = \operatorname{cmp}(|x|^2, |y|^2). $$

The squared absolute values are usually not actually computed: comparing the Integer parts componentwise, either directly or crosswise, often decides the ordering, and the AbsSquared fallback only runs when both pairings strictly conflict.

§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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Examples
use malachite_base::num::comparison::traits::{OrdAbs, PartialOrdAbs};
use malachite_nz::gaussian_integer::GaussianInteger;
use std::cmp::Ordering::*;
use std::str::FromStr;

let x = GaussianInteger::from_str("2+2i").unwrap();
let y = GaussianInteger::from_str("3i").unwrap();
// |2+2i|^2 = 8 and |3i|^2 = 9
assert_eq!(x.cmp_abs(&y), Less);
assert!(x.lt_abs(&y));

let x = GaussianInteger::from_str("1+2i").unwrap();
let y = GaussianInteger::from_str("-2+i").unwrap();
assert_eq!(x.cmp_abs(&y), Equal);

let x = GaussianInteger::from_str("3").unwrap();
let y = GaussianInteger::from_str("2+2i").unwrap();
// |3|^2 = 9 and |2+2i|^2 = 8
assert_eq!(x.cmp_abs(&y), Greater);
Source§

impl PartialEq for GaussianInteger

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<GaussianInteger> for Integer

Source§

fn eq(&self, other: &GaussianInteger) -> bool

Determines whether an Integer is equal to a GaussianInteger.

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

§Examples
use malachite_nz::gaussian_integer::GaussianInteger;
use malachite_nz::integer::Integer;
use std::str::FromStr;

assert!(Integer::from(123) == GaussianInteger::from(123));
assert!(Integer::from(123) != GaussianInteger::from_str("123+i").unwrap());
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<GaussianInteger> for Natural

Source§

fn eq(&self, other: &GaussianInteger) -> bool

Determines whether a Natural is equal to a GaussianInteger.

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

§Examples
use malachite_nz::gaussian_integer::GaussianInteger;
use malachite_nz::natural::Natural;
use std::str::FromStr;

assert!(Natural::from(123u32) == GaussianInteger::from(123));
assert!(Natural::from(123u32) != GaussianInteger::from_str("123+i").unwrap());
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<GaussianInteger> for f32

Source§

fn eq(&self, other: &GaussianInteger) -> bool

Determines whether a primitive float is equal to a GaussianInteger.

No infinity or NaN is equal to a GaussianInteger.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

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

§Examples

See here.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<GaussianInteger> for f64

Source§

fn eq(&self, other: &GaussianInteger) -> bool

Determines whether a primitive float is equal to a GaussianInteger.

No infinity or NaN is equal to a GaussianInteger.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

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

§Examples

See here.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<GaussianInteger> for u8

Source§

fn eq(&self, other: &GaussianInteger) -> bool

Determines whether an unsigned primitive integer is equal to a GaussianInteger.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<GaussianInteger> for u16

Source§

fn eq(&self, other: &GaussianInteger) -> bool

Determines whether an unsigned primitive integer is equal to a GaussianInteger.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<GaussianInteger> for u32

Source§

fn eq(&self, other: &GaussianInteger) -> bool

Determines whether an unsigned primitive integer is equal to a GaussianInteger.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<GaussianInteger> for u64

Source§

fn eq(&self, other: &GaussianInteger) -> bool

Determines whether an unsigned primitive integer is equal to a GaussianInteger.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<GaussianInteger> for u128

Source§

fn eq(&self, other: &GaussianInteger) -> bool

Determines whether an unsigned primitive integer is equal to a GaussianInteger.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<GaussianInteger> for usize

Source§

fn eq(&self, other: &GaussianInteger) -> bool

Determines whether an unsigned primitive integer is equal to a GaussianInteger.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<GaussianInteger> for i8

Source§

fn eq(&self, other: &GaussianInteger) -> bool

Determines whether a signed primitive integer is equal to a GaussianInteger.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<GaussianInteger> for i16

Source§

fn eq(&self, other: &GaussianInteger) -> bool

Determines whether a signed primitive integer is equal to a GaussianInteger.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<GaussianInteger> for i32

Source§

fn eq(&self, other: &GaussianInteger) -> bool

Determines whether a signed primitive integer is equal to a GaussianInteger.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<GaussianInteger> for i64

Source§

fn eq(&self, other: &GaussianInteger) -> bool

Determines whether a signed primitive integer is equal to a GaussianInteger.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<GaussianInteger> for i128

Source§

fn eq(&self, other: &GaussianInteger) -> bool

Determines whether a signed primitive integer is equal to a GaussianInteger.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<GaussianInteger> for isize

Source§

fn eq(&self, other: &GaussianInteger) -> bool

Determines whether a signed primitive integer is equal to a GaussianInteger.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<GaussianInteger> for IntegerPolynomial

Source§

fn eq(&self, other: &GaussianInteger) -> bool

Determines whether an IntegerPolynomial is equal to a GaussianInteger.

The polynomial is equal to the GaussianInteger when it is the constant polynomial with that value, so the zero polynomial is equal to 0 and nothing else, no polynomial is equal to a GaussianInteger with a nonzero imaginary part, and no polynomial of positive degree is equal to any GaussianInteger.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is min(self.coefficient(0).significant_bits(), other.real.significant_bits()).

§Examples

See here.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<GaussianInteger> for NaturalPolynomial

Source§

fn eq(&self, other: &GaussianInteger) -> bool

Determines whether a NaturalPolynomial is equal to a GaussianInteger.

The polynomial is equal to the GaussianInteger when it is the constant polynomial with that value, so the zero polynomial is equal to 0 and nothing else, no polynomial is equal to a GaussianInteger with a nonzero imaginary part or a negative real part, and no polynomial of positive degree is equal to any GaussianInteger.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is min(self.coefficient(0).significant_bits(), other.real.significant_bits()).

§Examples

See here.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<Integer> for GaussianInteger

Source§

fn eq(&self, other: &Integer) -> bool

Determines whether a GaussianInteger is equal to 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.real.significant_bits(), other.significant_bits()).

§Examples
use malachite_nz::gaussian_integer::GaussianInteger;
use malachite_nz::integer::Integer;
use std::str::FromStr;

assert!(GaussianInteger::from(123) == Integer::from(123));
assert!(GaussianInteger::from_str("123+i").unwrap() != Integer::from(123));
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<IntegerPolynomial> for GaussianInteger

Source§

fn eq(&self, other: &IntegerPolynomial) -> bool

Determines whether a GaussianInteger is equal to an IntegerPolynomial.

The GaussianInteger is equal to the polynomial when the polynomial is the constant polynomial with that value, so 0 is equal to the zero polynomial, and a GaussianInteger with a nonzero imaginary part is equal to no polynomial.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is min(self.real.significant_bits(), other.coefficient(0).significant_bits()).

§Examples

See here.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<Natural> for GaussianInteger

Source§

fn eq(&self, other: &Natural) -> bool

Determines whether a GaussianInteger is equal to 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.real.significant_bits(), other.significant_bits()).

§Examples
use malachite_nz::gaussian_integer::GaussianInteger;
use malachite_nz::natural::Natural;
use std::str::FromStr;

assert!(GaussianInteger::from(123) == Natural::from(123u32));
assert!(GaussianInteger::from_str("123+i").unwrap() != Natural::from(123u32));
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<NaturalPolynomial> for GaussianInteger

Source§

fn eq(&self, other: &NaturalPolynomial) -> bool

Determines whether a GaussianInteger is equal to a NaturalPolynomial.

The GaussianInteger is equal to the polynomial when the polynomial is the constant polynomial with that value, so 0 is equal to the zero polynomial, and a GaussianInteger with a nonzero imaginary part or a negative real part is equal to no polynomial.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is min(self.real.significant_bits(), other.coefficient(0).significant_bits()).

§Examples

See here.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<f32> for GaussianInteger

Source§

fn eq(&self, other: &f32) -> bool

Determines whether a GaussianInteger is equal to a primitive float.

No GaussianInteger is equal to an infinity or NaN.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

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

§Examples

See here.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<f64> for GaussianInteger

Source§

fn eq(&self, other: &f64) -> bool

Determines whether a GaussianInteger is equal to a primitive float.

No GaussianInteger is equal to an infinity or NaN.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

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

§Examples

See here.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<i8> for GaussianInteger

Source§

fn eq(&self, other: &i8) -> bool

Determines whether a GaussianInteger is equal to a signed primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<i16> for GaussianInteger

Source§

fn eq(&self, other: &i16) -> bool

Determines whether a GaussianInteger is equal to a signed primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<i32> for GaussianInteger

Source§

fn eq(&self, other: &i32) -> bool

Determines whether a GaussianInteger is equal to a signed primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<i64> for GaussianInteger

Source§

fn eq(&self, other: &i64) -> bool

Determines whether a GaussianInteger is equal to a signed primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<i128> for GaussianInteger

Source§

fn eq(&self, other: &i128) -> bool

Determines whether a GaussianInteger is equal to a signed primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<isize> for GaussianInteger

Source§

fn eq(&self, other: &isize) -> bool

Determines whether a GaussianInteger is equal to a signed primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<u8> for GaussianInteger

Source§

fn eq(&self, other: &u8) -> bool

Determines whether a GaussianInteger is equal to an unsigned primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<u16> for GaussianInteger

Source§

fn eq(&self, other: &u16) -> bool

Determines whether a GaussianInteger is equal to an unsigned primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<u32> for GaussianInteger

Source§

fn eq(&self, other: &u32) -> bool

Determines whether a GaussianInteger is equal to an unsigned primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<u64> for GaussianInteger

Source§

fn eq(&self, other: &u64) -> bool

Determines whether a GaussianInteger is equal to an unsigned primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<u128> for GaussianInteger

Source§

fn eq(&self, other: &u128) -> bool

Determines whether a GaussianInteger is equal to an unsigned primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<usize> for GaussianInteger

Source§

fn eq(&self, other: &usize) -> bool

Determines whether a GaussianInteger is equal to an unsigned primitive integer.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrdAbs for GaussianInteger

Source§

fn partial_cmp_abs(&self, other: &Self) -> Option<Ordering>

Compares the absolute values of two GaussianIntegers.

See the documentation for the OrdAbs implementation.

Source§

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
Source§

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
Source§

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
Source§

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
Source§

impl PartialOrdAbs<GaussianInteger> for Integer

Source§

fn partial_cmp_abs(&self, other: &GaussianInteger) -> Option<Ordering>

Compares the absolute values of an Integer and a GaussianInteger.

§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 the maximum number of significant bits of the real and imaginary parts of other and of self.

§Examples
use malachite_base::num::comparison::traits::{EqAbs, PartialOrdAbs};
use malachite_nz::gaussian_integer::GaussianInteger;
use malachite_nz::integer::Integer;
use std::str::FromStr;

// |3+4i| = 5
let y = GaussianInteger::from_str("3+4i").unwrap();
assert!(Integer::from(-5).eq_abs(&y));
assert!(Integer::from(4).lt_abs(&y));
assert!(Integer::from(-6).gt_abs(&y));
Source§

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
Source§

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
Source§

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
Source§

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
Source§

impl PartialOrdAbs<GaussianInteger> for Natural

Source§

fn partial_cmp_abs(&self, other: &GaussianInteger) -> Option<Ordering>

Compares the absolute values of a Natural and a GaussianInteger.

§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 the maximum number of significant bits of the real and imaginary parts of other and of self.

§Examples
use malachite_base::num::comparison::traits::{EqAbs, PartialOrdAbs};
use malachite_nz::gaussian_integer::GaussianInteger;
use malachite_nz::natural::Natural;
use std::str::FromStr;

// |3+4i| = 5
let y = GaussianInteger::from_str("3+4i").unwrap();
assert!(Natural::from(5u32).eq_abs(&y));
assert!(Natural::from(4u32).lt_abs(&y));
assert!(Natural::from(6u32).gt_abs(&y));
Source§

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
Source§

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
Source§

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
Source§

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
Source§

impl PartialOrdAbs<GaussianInteger> for f32

Source§

fn partial_cmp_abs(&self, other: &GaussianInteger) -> Option<Ordering>

Compares the absolute values of a primitive float and a GaussianInteger.

NaN is not comparable to any GaussianInteger. $\infty$ and $-\infty$ are greater in absolute value than any GaussianInteger.

§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 the maximum number of significant bits of the real and imaginary parts of other and self.sci_exponent().abs().

§Examples

See here.

Source§

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
Source§

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
Source§

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
Source§

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
Source§

impl PartialOrdAbs<GaussianInteger> for f64

Source§

fn partial_cmp_abs(&self, other: &GaussianInteger) -> Option<Ordering>

Compares the absolute values of a primitive float and a GaussianInteger.

NaN is not comparable to any GaussianInteger. $\infty$ and $-\infty$ are greater in absolute value than any GaussianInteger.

§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 the maximum number of significant bits of the real and imaginary parts of other and self.sci_exponent().abs().

§Examples

See here.

Source§

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
Source§

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
Source§

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
Source§

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
Source§

impl PartialOrdAbs<GaussianInteger> for u8

Source§

fn partial_cmp_abs(&self, other: &GaussianInteger) -> Option<Ordering>

Compares the absolute values of an unsigned primitive integer and a GaussianInteger.

§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 the maximum number of significant bits of the real and imaginary parts of other.

§Examples

See here.

Source§

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
Source§

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
Source§

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
Source§

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
Source§

impl PartialOrdAbs<GaussianInteger> for u16

Source§

fn partial_cmp_abs(&self, other: &GaussianInteger) -> Option<Ordering>

Compares the absolute values of an unsigned primitive integer and a GaussianInteger.

§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 the maximum number of significant bits of the real and imaginary parts of other.

§Examples

See here.

Source§

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
Source§

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
Source§

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
Source§

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
Source§

impl PartialOrdAbs<GaussianInteger> for u32

Source§

fn partial_cmp_abs(&self, other: &GaussianInteger) -> Option<Ordering>

Compares the absolute values of an unsigned primitive integer and a GaussianInteger.

§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 the maximum number of significant bits of the real and imaginary parts of other.

§Examples

See here.

Source§

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
Source§

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
Source§

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
Source§

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
Source§

impl PartialOrdAbs<GaussianInteger> for u64

Source§

fn partial_cmp_abs(&self, other: &GaussianInteger) -> Option<Ordering>

Compares the absolute values of an unsigned primitive integer and a GaussianInteger.

§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 the maximum number of significant bits of the real and imaginary parts of other.

§Examples

See here.

Source§

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
Source§

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
Source§

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
Source§

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
Source§

impl PartialOrdAbs<GaussianInteger> for u128

Source§

fn partial_cmp_abs(&self, other: &GaussianInteger) -> Option<Ordering>

Compares the absolute values of an unsigned primitive integer and a GaussianInteger.

§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 the maximum number of significant bits of the real and imaginary parts of other.

§Examples

See here.

Source§

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
Source§

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
Source§

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
Source§

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
Source§

impl PartialOrdAbs<GaussianInteger> for usize

Source§

fn partial_cmp_abs(&self, other: &GaussianInteger) -> Option<Ordering>

Compares the absolute values of an unsigned primitive integer and a GaussianInteger.

§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 the maximum number of significant bits of the real and imaginary parts of other.

§Examples

See here.

Source§

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
Source§

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
Source§

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
Source§

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
Source§

impl PartialOrdAbs<GaussianInteger> for i8

Source§

fn partial_cmp_abs(&self, other: &GaussianInteger) -> Option<Ordering>

Compares the absolute values of a signed primitive integer and a GaussianInteger.

§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 the maximum number of significant bits of the real and imaginary parts of other.

§Examples

See here.

Source§

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
Source§

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
Source§

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
Source§

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
Source§

impl PartialOrdAbs<GaussianInteger> for i16

Source§

fn partial_cmp_abs(&self, other: &GaussianInteger) -> Option<Ordering>

Compares the absolute values of a signed primitive integer and a GaussianInteger.

§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 the maximum number of significant bits of the real and imaginary parts of other.

§Examples

See here.

Source§

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
Source§

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
Source§

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
Source§

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
Source§

impl PartialOrdAbs<GaussianInteger> for i32

Source§

fn partial_cmp_abs(&self, other: &GaussianInteger) -> Option<Ordering>

Compares the absolute values of a signed primitive integer and a GaussianInteger.

§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 the maximum number of significant bits of the real and imaginary parts of other.

§Examples

See here.

Source§

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
Source§

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
Source§

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
Source§

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
Source§

impl PartialOrdAbs<GaussianInteger> for i64

Source§

fn partial_cmp_abs(&self, other: &GaussianInteger) -> Option<Ordering>

Compares the absolute values of a signed primitive integer and a GaussianInteger.

§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 the maximum number of significant bits of the real and imaginary parts of other.

§Examples

See here.

Source§

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
Source§

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
Source§

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
Source§

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
Source§

impl PartialOrdAbs<GaussianInteger> for i128

Source§

fn partial_cmp_abs(&self, other: &GaussianInteger) -> Option<Ordering>

Compares the absolute values of a signed primitive integer and a GaussianInteger.

§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 the maximum number of significant bits of the real and imaginary parts of other.

§Examples

See here.

Source§

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
Source§

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
Source§

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
Source§

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
Source§

impl PartialOrdAbs<GaussianInteger> for isize

Source§

fn partial_cmp_abs(&self, other: &GaussianInteger) -> Option<Ordering>

Compares the absolute values of a signed primitive integer and a GaussianInteger.

§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 the maximum number of significant bits of the real and imaginary parts of other.

§Examples

See here.

Source§

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
Source§

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
Source§

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
Source§

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
Source§

impl PartialOrdAbs<Integer> for GaussianInteger

Source§

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

Compares the absolute values of a GaussianInteger and an Integer.

The absolute value of a complex number is its distance from the origin, so this is equivalent to comparing squared absolute values. Purely real and purely imaginary values are handled by comparing single components. Otherwise, the complex value is greater in absolute value unless both of its components are smaller in absolute value than the real operand, so the squared absolute values are only computed in that case.

§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 the maximum number of significant bits of the real and imaginary parts of self and of other.

§Examples
use malachite_base::num::comparison::traits::{EqAbs, PartialOrdAbs};
use malachite_nz::gaussian_integer::GaussianInteger;
use malachite_nz::integer::Integer;
use std::str::FromStr;

// |3+4i| = 5
let x = GaussianInteger::from_str("3+4i").unwrap();
assert!(x.eq_abs(&Integer::from(-5)));
assert!(x.gt_abs(&Integer::from(4)));
assert!(x.lt_abs(&Integer::from(-6)));
Source§

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
Source§

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
Source§

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
Source§

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
Source§

impl PartialOrdAbs<Natural> for GaussianInteger

Source§

fn partial_cmp_abs(&self, other: &Natural) -> Option<Ordering>

Compares the absolute values of a GaussianInteger and a Natural.

The absolute value of a complex number is its distance from the origin, so this is equivalent to comparing squared absolute values. Purely real and purely imaginary values are handled by comparing single components. Otherwise, the complex value is greater in absolute value unless both of its components are smaller in absolute value than the real operand, so the squared absolute values are only computed in that case.

§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 the maximum number of significant bits of the real and imaginary parts of self and of other.

§Examples
use malachite_base::num::comparison::traits::{EqAbs, PartialOrdAbs};
use malachite_nz::gaussian_integer::GaussianInteger;
use malachite_nz::natural::Natural;
use std::str::FromStr;

// |3+4i| = 5
let x = GaussianInteger::from_str("3+4i").unwrap();
assert!(x.eq_abs(&Natural::from(5u32)));
assert!(x.gt_abs(&Natural::from(4u32)));
assert!(x.lt_abs(&Natural::from(6u32)));
Source§

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
Source§

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
Source§

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
Source§

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
Source§

impl PartialOrdAbs<f32> for GaussianInteger

Source§

fn partial_cmp_abs(&self, other: &f32) -> Option<Ordering>

Compares the absolute values of a GaussianInteger and a primitive float.

NaN is not comparable to any GaussianInteger. $\infty$ and $-\infty$ are greater in absolute value than any GaussianInteger. When the squared absolute values must be compared, the float’s square is represented exactly as an odd square times a power of two, so the comparison is 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 the maximum number of significant bits of the real and imaginary parts of self and other.sci_exponent().abs().

§Examples

See here.

Source§

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
Source§

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
Source§

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
Source§

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
Source§

impl PartialOrdAbs<f64> for GaussianInteger

Source§

fn partial_cmp_abs(&self, other: &f64) -> Option<Ordering>

Compares the absolute values of a GaussianInteger and a primitive float.

NaN is not comparable to any GaussianInteger. $\infty$ and $-\infty$ are greater in absolute value than any GaussianInteger. When the squared absolute values must be compared, the float’s square is represented exactly as an odd square times a power of two, so the comparison is 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 the maximum number of significant bits of the real and imaginary parts of self and other.sci_exponent().abs().

§Examples

See here.

Source§

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
Source§

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
Source§

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
Source§

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
Source§

impl PartialOrdAbs<i8> for GaussianInteger

Source§

fn partial_cmp_abs(&self, other: &i8) -> Option<Ordering>

Compares the absolute values of a GaussianInteger and a signed primitive integer.

§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 the maximum number of significant bits of the real and imaginary parts of self.

§Examples

See here.

Source§

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
Source§

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
Source§

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
Source§

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
Source§

impl PartialOrdAbs<i16> for GaussianInteger

Source§

fn partial_cmp_abs(&self, other: &i16) -> Option<Ordering>

Compares the absolute values of a GaussianInteger and a signed primitive integer.

§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 the maximum number of significant bits of the real and imaginary parts of self.

§Examples

See here.

Source§

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
Source§

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
Source§

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
Source§

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
Source§

impl PartialOrdAbs<i32> for GaussianInteger

Source§

fn partial_cmp_abs(&self, other: &i32) -> Option<Ordering>

Compares the absolute values of a GaussianInteger and a signed primitive integer.

§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 the maximum number of significant bits of the real and imaginary parts of self.

§Examples

See here.

Source§

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
Source§

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
Source§

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
Source§

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
Source§

impl PartialOrdAbs<i64> for GaussianInteger

Source§

fn partial_cmp_abs(&self, other: &i64) -> Option<Ordering>

Compares the absolute values of a GaussianInteger and a signed primitive integer.

§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 the maximum number of significant bits of the real and imaginary parts of self.

§Examples

See here.

Source§

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
Source§

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
Source§

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
Source§

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
Source§

impl PartialOrdAbs<i128> for GaussianInteger

Source§

fn partial_cmp_abs(&self, other: &i128) -> Option<Ordering>

Compares the absolute values of a GaussianInteger and a signed primitive integer.

§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 the maximum number of significant bits of the real and imaginary parts of self.

§Examples

See here.

Source§

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
Source§

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
Source§

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
Source§

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
Source§

impl PartialOrdAbs<isize> for GaussianInteger

Source§

fn partial_cmp_abs(&self, other: &isize) -> Option<Ordering>

Compares the absolute values of a GaussianInteger and a signed primitive integer.

§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 the maximum number of significant bits of the real and imaginary parts of self.

§Examples

See here.

Source§

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
Source§

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
Source§

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
Source§

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
Source§

impl PartialOrdAbs<u8> for GaussianInteger

Source§

fn partial_cmp_abs(&self, other: &u8) -> Option<Ordering>

Compares the absolute values of a GaussianInteger and an unsigned primitive integer.

§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 the maximum number of significant bits of the real and imaginary parts of self.

§Examples

See here.

Source§

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
Source§

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
Source§

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
Source§

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
Source§

impl PartialOrdAbs<u16> for GaussianInteger

Source§

fn partial_cmp_abs(&self, other: &u16) -> Option<Ordering>

Compares the absolute values of a GaussianInteger and an unsigned primitive integer.

§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 the maximum number of significant bits of the real and imaginary parts of self.

§Examples

See here.

Source§

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
Source§

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
Source§

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
Source§

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
Source§

impl PartialOrdAbs<u32> for GaussianInteger

Source§

fn partial_cmp_abs(&self, other: &u32) -> Option<Ordering>

Compares the absolute values of a GaussianInteger and an unsigned primitive integer.

§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 the maximum number of significant bits of the real and imaginary parts of self.

§Examples

See here.

Source§

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
Source§

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
Source§

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
Source§

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
Source§

impl PartialOrdAbs<u64> for GaussianInteger

Source§

fn partial_cmp_abs(&self, other: &u64) -> Option<Ordering>

Compares the absolute values of a GaussianInteger and an unsigned primitive integer.

§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 the maximum number of significant bits of the real and imaginary parts of self.

§Examples

See here.

Source§

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
Source§

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
Source§

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
Source§

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
Source§

impl PartialOrdAbs<u128> for GaussianInteger

Source§

fn partial_cmp_abs(&self, other: &u128) -> Option<Ordering>

Compares the absolute values of a GaussianInteger and an unsigned primitive integer.

§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 the maximum number of significant bits of the real and imaginary parts of self.

§Examples

See here.

Source§

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
Source§

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
Source§

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
Source§

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
Source§

impl PartialOrdAbs<usize> for GaussianInteger

Source§

fn partial_cmp_abs(&self, other: &usize) -> Option<Ordering>

Compares the absolute values of a GaussianInteger and an unsigned primitive integer.

§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 the maximum number of significant bits of the real and imaginary parts of self.

§Examples

See here.

Source§

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
Source§

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
Source§

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
Source§

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
Source§

impl Pow<u64> for GaussianInteger

Source§

fn pow(self, exp: u64) -> Self

Raises a GaussianInteger to a power, taking the GaussianInteger 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 the maximum number of significant bits of the real and imaginary parts of self, and $m$ is exp.

§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

assert_eq!(
    GaussianInteger::from_str("2+i").unwrap().pow(5).to_string(),
    "-38+41i"
);
assert_eq!(
    GaussianInteger::from_str("1+i")
        .unwrap()
        .pow(10)
        .to_string(),
    "32i"
);
assert_eq!(
    GaussianInteger::from_str("-7+24i")
        .unwrap()
        .pow(4)
        .to_string(),
    "164833+354144i"
);
Source§

type Output = GaussianInteger

Source§

impl Pow<u64> for &GaussianInteger

Source§

fn pow(self, exp: u64) -> GaussianInteger

Raises a GaussianInteger to a power, taking the GaussianInteger 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 the maximum number of significant bits of the real and imaginary parts of self, and $m$ is exp.

§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

assert_eq!(
    (&GaussianInteger::from_str("2+i").unwrap())
        .pow(5)
        .to_string(),
    "-38+41i"
);
assert_eq!(
    (&GaussianInteger::from_str("1+i").unwrap())
        .pow(10)
        .to_string(),
    "32i"
);
assert_eq!(
    (&GaussianInteger::from_str("-7+24i").unwrap())
        .pow(4)
        .to_string(),
    "164833+354144i"
);
Source§

type Output = GaussianInteger

Source§

impl PowAssign<u64> for GaussianInteger

Source§

fn pow_assign(&mut self, exp: u64)

Raises a GaussianInteger 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 the maximum number of significant bits of the real and imaginary parts of self, and $m$ is exp.

§Examples
use malachite_base::num::arithmetic::traits::PowAssign;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let mut x = GaussianInteger::from_str("2+i").unwrap();
x.pow_assign(5);
assert_eq!(x.to_string(), "-38+41i");

let mut x = GaussianInteger::from_str("1+i").unwrap();
x.pow_assign(10);
assert_eq!(x.to_string(), "32i");
Source§

impl PowerOf2<u64> for GaussianInteger

Source§

fn power_of_2(pow: u64) -> Self

Raises 2 to an integer power, producing a purely real GaussianInteger.

$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::gaussian_integer::GaussianInteger;

assert_eq!(GaussianInteger::power_of_2(0).to_string(), "1");
assert_eq!(GaussianInteger::power_of_2(3).to_string(), "8");
assert_eq!(
    GaussianInteger::power_of_2(100).to_string(),
    "1267650600228229401496703205376"
);
Source§

impl PrimitivePart for GaussianInteger

Source§

fn primitive_part(self) -> Self

Computes the primitive part of a GaussianInteger, the GaussianInteger with coprime parts that remains after dividing out the content, taking the GaussianInteger by value.

$$ f(a + bi) = \frac{a}{g} + \frac{b}{g} i, \quad \text{where } g = \gcd(|a|, |b|). $$

§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 the maximum number of significant bits of the real and imaginary parts of self.

§Examples
use malachite_base::num::arithmetic::traits::PrimitivePart;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

assert_eq!(
    GaussianInteger::from_str("-6+9i")
        .unwrap()
        .primitive_part()
        .to_string(),
    "-2+3i"
);
Source§

type Output = GaussianInteger

Source§

impl PrimitivePart for &GaussianInteger

Source§

fn primitive_part(self) -> GaussianInteger

Computes the primitive part of a GaussianInteger, the GaussianInteger with coprime parts that remains after dividing out the content, taking the GaussianInteger by reference.

$$ f(a + bi) = \frac{a}{g} + \frac{b}{g} i, \quad \text{where } g = \gcd(|a|, |b|). $$

§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 the maximum number of significant bits of the real and imaginary parts of self.

§Examples
use malachite_base::num::arithmetic::traits::PrimitivePart;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

assert_eq!(
    (&GaussianInteger::from_str("-6+9i").unwrap())
        .primitive_part()
        .to_string(),
    "-2+3i"
);
Source§

type Output = GaussianInteger

Source§

impl Product for GaussianInteger

Source§

fn product<I>(xs: I) -> Self
where I: Iterator<Item = Self>,

Multiplies together all the GaussianIntegers 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 the total number of significant bits of the real and imaginary parts of the GaussianIntegers.

§Examples
use core::iter::Product;
use malachite_base::vecs::vec_from_str;
use malachite_nz::gaussian_integer::GaussianInteger;

assert_eq!(
    GaussianInteger::product(
        vec_from_str::<GaussianInteger>("[2, -3i, 5+i, 7-2i]")
            .unwrap()
            .into_iter()
    )
    .to_string(),
    "-18-222i"
);
Source§

impl<'a> Product<&'a GaussianInteger> for GaussianInteger

Source§

fn product<I>(xs: I) -> Self
where I: Iterator<Item = &'a Self>,

Multiplies together all the GaussianIntegers in an iterator of GaussianInteger 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 the total number of significant bits of the real and imaginary parts of the GaussianIntegers.

§Examples
use core::iter::Product;
use malachite_base::vecs::vec_from_str;
use malachite_nz::gaussian_integer::GaussianInteger;

assert_eq!(
    GaussianInteger::product(
        vec_from_str::<GaussianInteger>("[2, -3i, 5+i, 7-2i]")
            .unwrap()
            .iter()
    )
    .to_string(),
    "-18-222i"
);
Source§

impl Rem for GaussianInteger

Source§

fn rem(self, other: Self) -> Self

Divides a GaussianInteger by another GaussianInteger, taking both by value, and returns the remainder.

The quotient (which is not returned) is the Gaussian integer nearest to the exact quotient, with each part rounded to the nearest integer and ties rounded up, and the remainder is what is left over. The quotient and remainder satisfy $x = qy + r$ and $N(r) \leq N(y) / 2$, where $N$ is the norm. To get both at once, use div_rem.

$$ f(x, y) = x - qy, \quad \text{where } q = \left \lfloor \frac{x \bar{y}}{N(y)} + \frac{1 + i}{2} \right \rfloor $$ and the floor is taken on each part.

§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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Panics

Panics if other is zero.

§Examples
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// (2+i)(3) + (-1) = 5+3i
let x = GaussianInteger::from_str("5+3i").unwrap();
let y = GaussianInteger::from_str("2+i").unwrap();
assert_eq!((x % y).to_string(), "-1");
Source§

type Output = GaussianInteger

The resulting type after applying the % operator.
Source§

impl Rem<&GaussianInteger> for GaussianInteger

Source§

fn rem(self, other: &Self) -> Self

Divides a GaussianInteger by another GaussianInteger, taking the first by value and the second by reference, and returns the remainder.

The quotient (which is not returned) is the Gaussian integer nearest to the exact quotient, with each part rounded to the nearest integer and ties rounded up, and the remainder is what is left over. The quotient and remainder satisfy $x = qy + r$ and $N(r) \leq N(y) / 2$, where $N$ is the norm. To get both at once, use div_rem.

$$ f(x, y) = x - qy, \quad \text{where } q = \left \lfloor \frac{x \bar{y}}{N(y)} + \frac{1 + i}{2} \right \rfloor $$ and the floor is taken on each part.

§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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Panics

Panics if other is zero.

§Examples
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// (2+i)(3) + (-1) = 5+3i
let x = GaussianInteger::from_str("5+3i").unwrap();
let y = GaussianInteger::from_str("2+i").unwrap();
assert_eq!((x % &y).to_string(), "-1");
Source§

type Output = GaussianInteger

The resulting type after applying the % operator.
Source§

impl Rem<&GaussianInteger> for &GaussianInteger

Source§

fn rem(self, other: &GaussianInteger) -> GaussianInteger

Divides a GaussianInteger by another GaussianInteger, taking both by reference, and returns the remainder.

The quotient (which is not returned) is the Gaussian integer nearest to the exact quotient, with each part rounded to the nearest integer and ties rounded up, and the remainder is what is left over. The quotient and remainder satisfy $x = qy + r$ and $N(r) \leq N(y) / 2$, where $N$ is the norm. To get both at once, use div_rem.

$$ f(x, y) = x - qy, \quad \text{where } q = \left \lfloor \frac{x \bar{y}}{N(y)} + \frac{1 + i}{2} \right \rfloor $$ and the floor is taken on each part.

§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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Panics

Panics if other is zero.

§Examples
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// (2+i)(3) + (-1) = 5+3i
let x = GaussianInteger::from_str("5+3i").unwrap();
let y = GaussianInteger::from_str("2+i").unwrap();
assert_eq!((&x % &y).to_string(), "-1");
Source§

type Output = GaussianInteger

The resulting type after applying the % operator.
Source§

impl Rem<GaussianInteger> for &GaussianInteger

Source§

fn rem(self, other: GaussianInteger) -> GaussianInteger

Divides a GaussianInteger by another GaussianInteger, taking the first by reference and the second by value, and returns the remainder.

The quotient (which is not returned) is the Gaussian integer nearest to the exact quotient, with each part rounded to the nearest integer and ties rounded up, and the remainder is what is left over. The quotient and remainder satisfy $x = qy + r$ and $N(r) \leq N(y) / 2$, where $N$ is the norm. To get both at once, use div_rem.

$$ f(x, y) = x - qy, \quad \text{where } q = \left \lfloor \frac{x \bar{y}}{N(y)} + \frac{1 + i}{2} \right \rfloor $$ and the floor is taken on each part.

§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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Panics

Panics if other is zero.

§Examples
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// (2+i)(3) + (-1) = 5+3i
let x = GaussianInteger::from_str("5+3i").unwrap();
let y = GaussianInteger::from_str("2+i").unwrap();
assert_eq!((&x % y).to_string(), "-1");
Source§

type Output = GaussianInteger

The resulting type after applying the % operator.
Source§

impl RemAssign for GaussianInteger

Source§

fn rem_assign(&mut self, other: Self)

Divides a GaussianInteger by another GaussianInteger in place, taking the GaussianInteger on the right-hand side by value and replacing the first GaussianInteger with the remainder.

The quotient (which is not returned) is the Gaussian integer nearest to the exact quotient, with each part rounded to the nearest integer and ties rounded up, and the remainder is what is left over. The quotient and remainder satisfy $x = qy + r$ and $N(r) \leq N(y) / 2$, where $N$ is the norm. To get both at once, use div_rem.

$$ x \gets x - qy, \quad \text{where } q = \left \lfloor \frac{x \bar{y}}{N(y)} + \frac{1 + i}{2} \right \rfloor $$ and the floor is taken on each part.

§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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Panics

Panics if other is zero.

§Examples
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// (2+i)(3) + (-1) = 5+3i
let mut x = GaussianInteger::from_str("5+3i").unwrap();
x %= GaussianInteger::from_str("2+i").unwrap();
assert_eq!(x.to_string(), "-1");
Source§

impl RemAssign<&GaussianInteger> for GaussianInteger

Source§

fn rem_assign(&mut self, other: &Self)

Divides a GaussianInteger by another GaussianInteger in place, taking the GaussianInteger on the right-hand side by reference and replacing the first GaussianInteger with the remainder.

The quotient (which is not returned) is the Gaussian integer nearest to the exact quotient, with each part rounded to the nearest integer and ties rounded up, and the remainder is what is left over. The quotient and remainder satisfy $x = qy + r$ and $N(r) \leq N(y) / 2$, where $N$ is the norm. To get both at once, use div_rem.

$$ x \gets x - qy, \quad \text{where } q = \left \lfloor \frac{x \bar{y}}{N(y)} + \frac{1 + i}{2} \right \rfloor $$ and the floor is taken on each part.

§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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Panics

Panics if other is zero.

§Examples
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

// (2+i)(3) + (-1) = 5+3i
let mut x = GaussianInteger::from_str("5+3i").unwrap();
x %= &GaussianInteger::from_str("2+i").unwrap();
assert_eq!(x.to_string(), "-1");
Source§

impl Shl<u8> for GaussianInteger

Source§

fn shl(self, bits: u8) -> GaussianInteger

Left-shifts a GaussianInteger (multiplies it by a power of 2), taking it by value. Both parts are shifted.

$$ 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 the maximum number of significant bits of the real and imaginary parts of self, and $m$ is bits.

§Examples

See here.

Source§

type Output = GaussianInteger

The resulting type after applying the << operator.
Source§

impl Shl<u8> for &GaussianInteger

Source§

fn shl(self, bits: u8) -> GaussianInteger

Left-shifts a GaussianInteger (multiplies it by a power of 2), taking it by reference. Both parts are shifted.

$$ 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 the maximum number of significant bits of the real and imaginary parts of self, and $m$ is bits.

§Examples

See here.

Source§

type Output = GaussianInteger

The resulting type after applying the << operator.
Source§

impl Shl<u16> for GaussianInteger

Source§

fn shl(self, bits: u16) -> GaussianInteger

Left-shifts a GaussianInteger (multiplies it by a power of 2), taking it by value. Both parts are shifted.

$$ 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 the maximum number of significant bits of the real and imaginary parts of self, and $m$ is bits.

§Examples

See here.

Source§

type Output = GaussianInteger

The resulting type after applying the << operator.
Source§

impl Shl<u16> for &GaussianInteger

Source§

fn shl(self, bits: u16) -> GaussianInteger

Left-shifts a GaussianInteger (multiplies it by a power of 2), taking it by reference. Both parts are shifted.

$$ 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 the maximum number of significant bits of the real and imaginary parts of self, and $m$ is bits.

§Examples

See here.

Source§

type Output = GaussianInteger

The resulting type after applying the << operator.
Source§

impl Shl<u32> for GaussianInteger

Source§

fn shl(self, bits: u32) -> GaussianInteger

Left-shifts a GaussianInteger (multiplies it by a power of 2), taking it by value. Both parts are shifted.

$$ 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 the maximum number of significant bits of the real and imaginary parts of self, and $m$ is bits.

§Examples

See here.

Source§

type Output = GaussianInteger

The resulting type after applying the << operator.
Source§

impl Shl<u32> for &GaussianInteger

Source§

fn shl(self, bits: u32) -> GaussianInteger

Left-shifts a GaussianInteger (multiplies it by a power of 2), taking it by reference. Both parts are shifted.

$$ 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 the maximum number of significant bits of the real and imaginary parts of self, and $m$ is bits.

§Examples

See here.

Source§

type Output = GaussianInteger

The resulting type after applying the << operator.
Source§

impl Shl<u64> for GaussianInteger

Source§

fn shl(self, bits: u64) -> GaussianInteger

Left-shifts a GaussianInteger (multiplies it by a power of 2), taking it by value. Both parts are shifted.

$$ 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 the maximum number of significant bits of the real and imaginary parts of self, and $m$ is bits.

§Examples

See here.

Source§

type Output = GaussianInteger

The resulting type after applying the << operator.
Source§

impl Shl<u64> for &GaussianInteger

Source§

fn shl(self, bits: u64) -> GaussianInteger

Left-shifts a GaussianInteger (multiplies it by a power of 2), taking it by reference. Both parts are shifted.

$$ 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 the maximum number of significant bits of the real and imaginary parts of self, and $m$ is bits.

§Examples

See here.

Source§

type Output = GaussianInteger

The resulting type after applying the << operator.
Source§

impl Shl<u128> for GaussianInteger

Source§

fn shl(self, bits: u128) -> GaussianInteger

Left-shifts a GaussianInteger (multiplies it by a power of 2), taking it by value. Both parts are shifted.

$$ 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 the maximum number of significant bits of the real and imaginary parts of self, and $m$ is bits.

§Examples

See here.

Source§

type Output = GaussianInteger

The resulting type after applying the << operator.
Source§

impl Shl<u128> for &GaussianInteger

Source§

fn shl(self, bits: u128) -> GaussianInteger

Left-shifts a GaussianInteger (multiplies it by a power of 2), taking it by reference. Both parts are shifted.

$$ 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 the maximum number of significant bits of the real and imaginary parts of self, and $m$ is bits.

§Examples

See here.

Source§

type Output = GaussianInteger

The resulting type after applying the << operator.
Source§

impl Shl<usize> for GaussianInteger

Source§

fn shl(self, bits: usize) -> GaussianInteger

Left-shifts a GaussianInteger (multiplies it by a power of 2), taking it by value. Both parts are shifted.

$$ 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 the maximum number of significant bits of the real and imaginary parts of self, and $m$ is bits.

§Examples

See here.

Source§

type Output = GaussianInteger

The resulting type after applying the << operator.
Source§

impl Shl<usize> for &GaussianInteger

Source§

fn shl(self, bits: usize) -> GaussianInteger

Left-shifts a GaussianInteger (multiplies it by a power of 2), taking it by reference. Both parts are shifted.

$$ 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 the maximum number of significant bits of the real and imaginary parts of self, and $m$ is bits.

§Examples

See here.

Source§

type Output = GaussianInteger

The resulting type after applying the << operator.
Source§

impl ShlAssign<u8> for GaussianInteger

Source§

fn shl_assign(&mut self, bits: u8)

Left-shifts a GaussianInteger (multiplies it by a power of 2), in place. Both parts are shifted.

$$ 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 the maximum number of significant bits of the real and imaginary parts of self, and $m$ is bits.

§Examples

See here.

Source§

impl ShlAssign<u16> for GaussianInteger

Source§

fn shl_assign(&mut self, bits: u16)

Left-shifts a GaussianInteger (multiplies it by a power of 2), in place. Both parts are shifted.

$$ 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 the maximum number of significant bits of the real and imaginary parts of self, and $m$ is bits.

§Examples

See here.

Source§

impl ShlAssign<u32> for GaussianInteger

Source§

fn shl_assign(&mut self, bits: u32)

Left-shifts a GaussianInteger (multiplies it by a power of 2), in place. Both parts are shifted.

$$ 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 the maximum number of significant bits of the real and imaginary parts of self, and $m$ is bits.

§Examples

See here.

Source§

impl ShlAssign<u64> for GaussianInteger

Source§

fn shl_assign(&mut self, bits: u64)

Left-shifts a GaussianInteger (multiplies it by a power of 2), in place. Both parts are shifted.

$$ 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 the maximum number of significant bits of the real and imaginary parts of self, and $m$ is bits.

§Examples

See here.

Source§

impl ShlAssign<u128> for GaussianInteger

Source§

fn shl_assign(&mut self, bits: u128)

Left-shifts a GaussianInteger (multiplies it by a power of 2), in place. Both parts are shifted.

$$ 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 the maximum number of significant bits of the real and imaginary parts of self, and $m$ is bits.

§Examples

See here.

Source§

impl ShlAssign<usize> for GaussianInteger

Source§

fn shl_assign(&mut self, bits: usize)

Left-shifts a GaussianInteger (multiplies it by a power of 2), in place. Both parts are shifted.

$$ 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 the maximum number of significant bits of the real and imaginary parts of self, and $m$ is bits.

§Examples

See here.

Source§

impl SignificantBits for &GaussianInteger

Source§

fn significant_bits(self) -> u64

Returns the sum of the numbers of significant bits of the real and imaginary parts of a GaussianInteger, each taken in absolute value.

$$ f(a + bi) = \operatorname{bits}(a) + \operatorname{bits}(b), $$ where $\operatorname{bits}(n)$ is the number of significant bits of $|n|$, with $\operatorname{bits}(0) = 0$. The larger of the two counts alone is available as max_significant_bits.

§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::gaussian_integer::GaussianInteger;
use std::str::FromStr;

assert_eq!(GaussianInteger::ZERO.significant_bits(), 0);
assert_eq!(GaussianInteger::from(100).significant_bits(), 7);
assert_eq!(
    GaussianInteger::from_str("3+4i")
        .unwrap()
        .significant_bits(),
    5
);
assert_eq!(
    GaussianInteger::from_str("1000000000000+i")
        .unwrap()
        .significant_bits(),
    41
);
Source§

impl Square for GaussianInteger

Source§

fn square(self) -> Self

Squares a GaussianInteger, 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 the maximum number of significant bits of the real and imaginary parts.

§Examples
use malachite_base::num::arithmetic::traits::Square;
use malachite_base::num::basic::traits::I;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

assert_eq!(GaussianInteger::I.square().to_string(), "-1");
let x = GaussianInteger::from_str("2-3i").unwrap();
assert_eq!(x.square().to_string(), "-5-12i");
Source§

type Output = GaussianInteger

Source§

impl Square for &GaussianInteger

Source§

fn square(self) -> GaussianInteger

Squares a GaussianInteger, 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 the maximum number of significant bits of the real and imaginary parts.

§Examples
use malachite_base::num::arithmetic::traits::Square;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let x = GaussianInteger::from_str("2-3i").unwrap();
assert_eq!((&x).square().to_string(), "-5-12i");
Source§

type Output = GaussianInteger

Source§

impl SquareAssign for GaussianInteger

Source§

fn square_assign(&mut self)

Squares a GaussianInteger 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 the maximum number of significant bits of the real and imaginary parts.

§Examples
use malachite_base::num::arithmetic::traits::SquareAssign;
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let mut x = GaussianInteger::from_str("2-3i").unwrap();
x.square_assign();
assert_eq!(x.to_string(), "-5-12i");
Source§

impl StructuralPartialEq for GaussianInteger

Source§

impl Sub for GaussianInteger

Source§

fn sub(self, other: Self) -> Self

Subtracts two GaussianIntegers, taking both 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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Examples
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let x = GaussianInteger::from_str("2-3i").unwrap();
let y = GaussianInteger::from_str("-1+4i").unwrap();
assert_eq!((x - y).to_string(), "3-7i");
Source§

type Output = GaussianInteger

The resulting type after applying the - operator.
Source§

impl Sub<&GaussianInteger> for GaussianInteger

Source§

fn sub(self, other: &Self) -> Self

Subtracts two GaussianIntegers, 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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Examples
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let x = GaussianInteger::from_str("2-3i").unwrap();
let y = GaussianInteger::from_str("-1+4i").unwrap();
assert_eq!((x - &y).to_string(), "3-7i");
Source§

type Output = GaussianInteger

The resulting type after applying the - operator.
Source§

impl Sub<&GaussianInteger> for &GaussianInteger

Source§

fn sub(self, other: &GaussianInteger) -> GaussianInteger

Subtracts two GaussianIntegers, 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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Examples
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let x = GaussianInteger::from_str("1000000000000+i").unwrap();
let y = GaussianInteger::from_str("i").unwrap();
assert_eq!((&x - &y).to_string(), "1000000000000");
Source§

type Output = GaussianInteger

The resulting type after applying the - operator.
Source§

impl Sub<GaussianInteger> for &GaussianInteger

Source§

fn sub(self, other: GaussianInteger) -> GaussianInteger

Subtracts two GaussianIntegers, 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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Examples
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let x = GaussianInteger::from_str("2-3i").unwrap();
let y = GaussianInteger::from_str("-1+4i").unwrap();
assert_eq!((&x - y).to_string(), "3-7i");
Source§

type Output = GaussianInteger

The resulting type after applying the - operator.
Source§

impl SubAssign for GaussianInteger

Source§

fn sub_assign(&mut self, other: Self)

Subtracts a GaussianInteger from a GaussianInteger in place, taking the GaussianInteger on the right-hand side by value.

$$ 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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Examples
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let x = GaussianInteger::from_str("2-3i").unwrap();
let y = GaussianInteger::from_str("-1+4i").unwrap();
let mut sum = x;
sum -= y;
assert_eq!(sum.to_string(), "3-7i");
Source§

impl SubAssign<&GaussianInteger> for GaussianInteger

Source§

fn sub_assign(&mut self, other: &Self)

Subtracts a GaussianInteger from a GaussianInteger in place, taking the GaussianInteger 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 the maximum number of significant bits of the real and imaginary parts of self and other.

§Examples
use malachite_nz::gaussian_integer::GaussianInteger;
use std::str::FromStr;

let x = GaussianInteger::from_str("2-3i").unwrap();
let y = GaussianInteger::from_str("-1+4i").unwrap();
let mut sum = x;
sum -= &y;
assert_eq!(sum.to_string(), "3-7i");
Source§

impl Sum for GaussianInteger

Source§

fn sum<I>(xs: I) -> Self
where I: Iterator<Item = Self>,

Adds up all the GaussianIntegers 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 the total number of significant bits of the real and imaginary parts of the GaussianIntegers.

§Examples
use core::iter::Sum;
use malachite_base::vecs::vec_from_str;
use malachite_nz::gaussian_integer::GaussianInteger;

assert_eq!(
    GaussianInteger::sum(
        vec_from_str::<GaussianInteger>("[2, -3i, 5+i, 7-2i]")
            .unwrap()
            .into_iter()
    )
    .to_string(),
    "14-4i"
);
Source§

impl<'a> Sum<&'a GaussianInteger> for GaussianInteger

Source§

fn sum<I>(xs: I) -> Self
where I: Iterator<Item = &'a Self>,

Adds up all the GaussianIntegers in an iterator of GaussianInteger 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 the total number of significant bits of the real and imaginary parts of the GaussianIntegers.

§Examples
use core::iter::Sum;
use malachite_base::vecs::vec_from_str;
use malachite_nz::gaussian_integer::GaussianInteger;

assert_eq!(
    GaussianInteger::sum(
        vec_from_str::<GaussianInteger>("[2, -3i, 5+i, 7-2i]")
            .unwrap()
            .iter()
    )
    .to_string(),
    "14-4i"
);
Source§

impl ToLatex for GaussianInteger

Source§

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

Writes a GaussianInteger as a LaTeX math-mode fragment.

The fragment is what Display gives, which is already how a Gaussian integer is written in mathematics: a value with a zero imaginary part is its real part alone, a purely imaginary value is a coefficient directly followed by i with coefficients of 1 and -1 elided, and otherwise the real term comes first and the imaginary term follows with a joining sign.

The imaginary unit is written as a plain i, which LaTeX sets in italics, as most mathematical writing does. An upright one would need a spelling of its own, and would not match what Display gives.

§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 the maximum number of significant bits of the real and imaginary parts.

§Examples
use malachite_base::num::conversion::traits::ImaginaryFrom;
use malachite_base::strings::latex::ToLatex;
use malachite_nz::gaussian_integer::GaussianInteger;

assert_eq!(GaussianInteger::default().to_latex_string(), "0");
assert_eq!(GaussianInteger::from(2).to_latex_string(), "2");
assert_eq!(GaussianInteger::from(-2).to_latex_string(), "-2");
assert_eq!(GaussianInteger::imaginary_from(1).to_latex_string(), "i");
assert_eq!(GaussianInteger::imaginary_from(-1).to_latex_string(), "-i");
assert_eq!(GaussianInteger::imaginary_from(2).to_latex_string(), "2i");
valuefragmentrenders as
GaussianInteger::default()0$0$
GaussianInteger::from(-2)-2$-2$
GaussianInteger::imaginary_from(1)i$i$
GaussianInteger::imaginary_from(2)2i$2i$
Source§

fn to_latex(&self) -> LatexWrapper<'_, Self>
where Self: Sized,

Converts a value to a LaTeX math-mode fragment. Read more
Source§

fn to_latex_string(&self) -> String
where Self: Sized,

Converts a value to a LaTeX math-mode fragment, as a String. Read more
Source§

impl ToTypst for GaussianInteger

Source§

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

Writes a GaussianInteger as a Typst math-mode fragment.

The fragment is what Display gives, which is already how a Gaussian integer is written in mathematics: a value with a zero imaginary part is its real part alone, a purely imaginary value is a coefficient directly followed by i with coefficients of 1 and -1 elided, and otherwise the real term comes first and the imaginary term follows with a joining sign.

The imaginary unit is written as a plain i, which Typst sets in italics, as most mathematical writing does. An upright one would need a spelling of its own, and would not match what Display gives.

§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 the maximum number of significant bits of the real and imaginary parts.

§Examples
use malachite_base::num::conversion::traits::ImaginaryFrom;
use malachite_base::strings::typst::ToTypst;
use malachite_nz::gaussian_integer::GaussianInteger;

assert_eq!(GaussianInteger::default().to_typst_string(), "0");
assert_eq!(GaussianInteger::from(2).to_typst_string(), "2");
assert_eq!(GaussianInteger::from(-2).to_typst_string(), "-2");
assert_eq!(GaussianInteger::imaginary_from(1).to_typst_string(), "i");
assert_eq!(GaussianInteger::imaginary_from(-1).to_typst_string(), "-i");
assert_eq!(GaussianInteger::imaginary_from(2).to_typst_string(), "2i");
valuefragment
GaussianInteger::default()0
GaussianInteger::from(-2)-2
GaussianInteger::imaginary_from(1)i
GaussianInteger::imaginary_from(2)2i
Source§

fn to_typst(&self) -> TypstWrapper<'_, Self>
where Self: Sized,

Converts a value to a Typst math-mode fragment. Read more
Source§

fn to_typst_string(&self) -> String
where Self: Sized,

Converts a value to a Typst math-mode fragment, as a String. Read more
Source§

impl TryFrom<&GaussianInteger> for Integer

Source§

fn try_from(x: &GaussianInteger) -> Result<Self, Self::Error>

Converts a GaussianInteger to an Integer, taking the GaussianInteger by reference. If the GaussianInteger is not real, 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.real.significant_bits().

§Examples
use malachite_nz::gaussian_integer::GaussianInteger;
use malachite_nz::gaussian_integer::conversion::integer_from_gaussian_integer::*;
use malachite_nz::integer::Integer;
use std::str::FromStr;

let x = GaussianInteger::from_str("123").unwrap();
assert_eq!(Integer::try_from(&x).unwrap(), 123);

let x = GaussianInteger::from_str("-123").unwrap();
assert_eq!(Integer::try_from(&x).unwrap(), -123);

let x = GaussianInteger::from_str("2-3i").unwrap();
assert_eq!(Integer::try_from(&x), Err(IntegerFromGaussianIntegerError));
Source§

type Error = IntegerFromGaussianIntegerError

The type returned in the event of a conversion error.
Source§

impl TryFrom<&GaussianInteger> for Natural

Source§

fn try_from(x: &GaussianInteger) -> Result<Self, Self::Error>

Converts a GaussianInteger to a Natural, taking the GaussianInteger by reference. If the GaussianInteger is not real or 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 x.real.significant_bits().

§Examples
use malachite_nz::gaussian_integer::GaussianInteger;
use malachite_nz::gaussian_integer::conversion::natural_from_gaussian_integer::*;
use malachite_nz::natural::Natural;
use std::str::FromStr;

let x = GaussianInteger::from_str("123").unwrap();
assert_eq!(Natural::try_from(&x).unwrap(), 123);

let x = GaussianInteger::from_str("-123").unwrap();
assert_eq!(Natural::try_from(&x), Err(NaturalFromGaussianIntegerError));

let x = GaussianInteger::from_str("2-3i").unwrap();
assert_eq!(Natural::try_from(&x), Err(NaturalFromGaussianIntegerError));
Source§

type Error = NaturalFromGaussianIntegerError

The type returned in the event of a conversion error.
Source§

impl TryFrom<&GaussianInteger> for f32

Source§

fn try_from(x: &GaussianInteger) -> Result<f32, Self::Error>

Converts a GaussianInteger to a primitive float, returning an error if the GaussianInteger is not real or isn’t exactly equal to some float.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is x.real.significant_bits().

§Examples

See here.

Source§

type Error = PrimitiveFloatFromGaussianIntegerError

The type returned in the event of a conversion error.
Source§

impl TryFrom<&GaussianInteger> for f64

Source§

fn try_from(x: &GaussianInteger) -> Result<f64, Self::Error>

Converts a GaussianInteger to a primitive float, returning an error if the GaussianInteger is not real or isn’t exactly equal to some float.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is x.real.significant_bits().

§Examples

See here.

Source§

type Error = PrimitiveFloatFromGaussianIntegerError

The type returned in the event of a conversion error.
Source§

impl TryFrom<&GaussianInteger> for u8

Source§

fn try_from(x: &GaussianInteger) -> Result<u8, Self::Error>

Converts a GaussianInteger to a primitive integer, returning an error if the GaussianInteger is not real or cannot be represented.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

Source§

type Error = PrimitiveIntFromGaussianIntegerError

The type returned in the event of a conversion error.
Source§

impl TryFrom<&GaussianInteger> for u16

Source§

fn try_from(x: &GaussianInteger) -> Result<u16, Self::Error>

Converts a GaussianInteger to a primitive integer, returning an error if the GaussianInteger is not real or cannot be represented.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

Source§

type Error = PrimitiveIntFromGaussianIntegerError

The type returned in the event of a conversion error.
Source§

impl TryFrom<&GaussianInteger> for u32

Source§

fn try_from(x: &GaussianInteger) -> Result<u32, Self::Error>

Converts a GaussianInteger to a primitive integer, returning an error if the GaussianInteger is not real or cannot be represented.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

Source§

type Error = PrimitiveIntFromGaussianIntegerError

The type returned in the event of a conversion error.
Source§

impl TryFrom<&GaussianInteger> for u64

Source§

fn try_from(x: &GaussianInteger) -> Result<u64, Self::Error>

Converts a GaussianInteger to a primitive integer, returning an error if the GaussianInteger is not real or cannot be represented.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

Source§

type Error = PrimitiveIntFromGaussianIntegerError

The type returned in the event of a conversion error.
Source§

impl TryFrom<&GaussianInteger> for u128

Source§

fn try_from(x: &GaussianInteger) -> Result<u128, Self::Error>

Converts a GaussianInteger to a primitive integer, returning an error if the GaussianInteger is not real or cannot be represented.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

Source§

type Error = PrimitiveIntFromGaussianIntegerError

The type returned in the event of a conversion error.
Source§

impl TryFrom<&GaussianInteger> for usize

Source§

fn try_from(x: &GaussianInteger) -> Result<usize, Self::Error>

Converts a GaussianInteger to a primitive integer, returning an error if the GaussianInteger is not real or cannot be represented.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

Source§

type Error = PrimitiveIntFromGaussianIntegerError

The type returned in the event of a conversion error.
Source§

impl TryFrom<&GaussianInteger> for i8

Source§

fn try_from(x: &GaussianInteger) -> Result<i8, Self::Error>

Converts a GaussianInteger to a primitive integer, returning an error if the GaussianInteger is not real or cannot be represented.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

Source§

type Error = PrimitiveIntFromGaussianIntegerError

The type returned in the event of a conversion error.
Source§

impl TryFrom<&GaussianInteger> for i16

Source§

fn try_from(x: &GaussianInteger) -> Result<i16, Self::Error>

Converts a GaussianInteger to a primitive integer, returning an error if the GaussianInteger is not real or cannot be represented.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

Source§

type Error = PrimitiveIntFromGaussianIntegerError

The type returned in the event of a conversion error.
Source§

impl TryFrom<&GaussianInteger> for i32

Source§

fn try_from(x: &GaussianInteger) -> Result<i32, Self::Error>

Converts a GaussianInteger to a primitive integer, returning an error if the GaussianInteger is not real or cannot be represented.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

Source§

type Error = PrimitiveIntFromGaussianIntegerError

The type returned in the event of a conversion error.
Source§

impl TryFrom<&GaussianInteger> for i64

Source§

fn try_from(x: &GaussianInteger) -> Result<i64, Self::Error>

Converts a GaussianInteger to a primitive integer, returning an error if the GaussianInteger is not real or cannot be represented.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

Source§

type Error = PrimitiveIntFromGaussianIntegerError

The type returned in the event of a conversion error.
Source§

impl TryFrom<&GaussianInteger> for i128

Source§

fn try_from(x: &GaussianInteger) -> Result<i128, Self::Error>

Converts a GaussianInteger to a primitive integer, returning an error if the GaussianInteger is not real or cannot be represented.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

Source§

type Error = PrimitiveIntFromGaussianIntegerError

The type returned in the event of a conversion error.
Source§

impl TryFrom<&GaussianInteger> for isize

Source§

fn try_from(x: &GaussianInteger) -> Result<isize, Self::Error>

Converts a GaussianInteger to a primitive integer, returning an error if the GaussianInteger is not real or cannot be represented.

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

Source§

type Error = PrimitiveIntFromGaussianIntegerError

The type returned in the event of a conversion error.
Source§

impl TryFrom<GaussianInteger> for Integer

Source§

fn try_from(x: GaussianInteger) -> Result<Self, Self::Error>

Converts a GaussianInteger to an Integer, taking the GaussianInteger by value. If the GaussianInteger is not real, an error is returned.

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_nz::gaussian_integer::GaussianInteger;
use malachite_nz::gaussian_integer::conversion::integer_from_gaussian_integer::*;
use malachite_nz::integer::Integer;
use std::str::FromStr;

let x = GaussianInteger::from_str("123").unwrap();
assert_eq!(Integer::try_from(x).unwrap(), 123);

let x = GaussianInteger::from_str("-123").unwrap();
assert_eq!(Integer::try_from(x).unwrap(), -123);

let x = GaussianInteger::from_str("2-3i").unwrap();
assert_eq!(Integer::try_from(x), Err(IntegerFromGaussianIntegerError));
Source§

type Error = IntegerFromGaussianIntegerError

The type returned in the event of a conversion error.
Source§

impl TryFrom<GaussianInteger> for Natural

Source§

fn try_from(x: GaussianInteger) -> Result<Self, Self::Error>

Converts a GaussianInteger to a Natural, taking the GaussianInteger by value. If the GaussianInteger is not real or is negative, an error is returned.

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_nz::gaussian_integer::GaussianInteger;
use malachite_nz::gaussian_integer::conversion::natural_from_gaussian_integer::*;
use malachite_nz::natural::Natural;
use std::str::FromStr;

let x = GaussianInteger::from_str("123").unwrap();
assert_eq!(Natural::try_from(x).unwrap(), 123);

let x = GaussianInteger::from_str("-123").unwrap();
assert_eq!(Natural::try_from(x), Err(NaturalFromGaussianIntegerError));

let x = GaussianInteger::from_str("2-3i").unwrap();
assert_eq!(Natural::try_from(x), Err(NaturalFromGaussianIntegerError));
Source§

type Error = NaturalFromGaussianIntegerError

The type returned in the event of a conversion error.
Source§

impl TryFrom<f32> for GaussianInteger

Source§

fn try_from(value: f32) -> Result<GaussianInteger, Self::Error>

Converts a primitive float to a GaussianInteger, producing a purely real value.

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.

Source§

type Error = GaussianIntegerFromPrimitiveFloatError

The type returned in the event of a conversion error.
Source§

impl TryFrom<f64> for GaussianInteger

Source§

fn try_from(value: f64) -> Result<GaussianInteger, Self::Error>

Converts a primitive float to a GaussianInteger, producing a purely real value.

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.

Source§

type Error = GaussianIntegerFromPrimitiveFloatError

The type returned in the event of a conversion error.
Source§

impl Two for GaussianInteger

The constant 2.

Source§

const TWO: Self

Source§

impl Zero for GaussianInteger

The constant 0.

Source§

const ZERO: Self

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
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T, U> ExactFrom<T> for U
where U: TryFrom<T>,

Source§

fn exact_from(value: T) -> U

Source§

impl<T, U> ExactInto<U> for T
where U: ExactFrom<T>,

Source§

fn exact_into(self) -> U

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> ImaginaryInto<U> for T
where U: ImaginaryFrom<T>,

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
Source§

impl<T, U> OverflowingInto<U> for T
where U: OverflowingFrom<T>,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> RoundingInto<U> for T
where U: RoundingFrom<T>,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> SaturatingInto<U> for T
where U: SaturatingFrom<T>,

Source§

impl<T> ToDebugString for T
where T: Debug,

Source§

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T, U> WrappingInto<U> for T
where U: WrappingFrom<T>,

Source§

fn wrapping_into(self) -> U