# [−]Struct lumol::types::Complex

pub struct Complex { /* fields omitted */ }

Complex number, with double precision real and imaginary parts.

Complex implements all the usual arithmetic operations:


let w = Complex::cartesian(-1.0, 0.5);
let z = Complex::cartesian(4.0, 2.0);

let c = w + z;
assert_eq!(c, Complex::cartesian(3.0, 2.5));

// Subtraction
let c = w - z;
assert_eq!(c, Complex::cartesian(-5.0, -1.5));

// Multiplication
let c = w * z;
assert_eq!(c, Complex::cartesian(-5.0, 0.0));

let c = 42.0 * w;
assert_eq!(c, Complex::cartesian(-42.0, 21.0));

// Division
let c = z / 2.0;
assert_eq!(c, Complex::cartesian(2.0, 1.0));

## Implementations

### impl Complex

#### pub fn polar(r: f64, phi: f64) -> Complex

Create a new Complex from a norm r and a phase phi in radians.

# Examples

let z = Complex::polar(3.0, f64::consts::PI);
assert_eq!(z.norm(), 3.0);

#### pub fn cartesian(x: f64, y: f64) -> Complex

Create a complex from Cartesian coordinates

# Examples

let z = Complex::cartesian(3.0, -2.0);
assert_eq!(z.real(), 3.0);
assert_eq!(z.imag(), -2.0);

#### pub fn zero() -> Complex

Create a new Complex with both cartesian coordinate set to 0.

# Examples

let z = Complex::zero();
assert_eq!(z.norm(), 0.0);

#### pub fn real(&self) -> f64

Get the real part of the complex

# Examples

let z = Complex::cartesian(3.0, -2.0);
assert_eq!(z.real(), 3.0);

#### pub fn imag(&self) -> f64

Get the imaginary part of the complex

# Examples

let z = Complex::cartesian(3.0, -2.0);
assert_eq!(z.imag(), -2.0);

#### pub fn phase(&self) -> f64

Get the phase of the complex in the [-π, π) interval

# Examples

let z = Complex::polar(2.0, 0.3);
assert_eq!(z.phase(), 0.3);

#### pub fn norm(&self) -> f64

Get the norm of the complex

# Examples

let z = Complex::polar(2.0, 0.3);
assert_eq!(z.norm(), 2.0);

let z = Complex::cartesian(2.0, 1.0);
assert_eq!(z.norm(), f64::sqrt(5.0));

#### pub fn norm2(&self) -> f64

Get the square of the norm if this complex

# Examples

let z = Complex::cartesian(2.0, 1.0);
assert_eq!(z.norm2(), 5.0);

#### pub fn conj(&self) -> Complex

Get the conjugate of the complex

# Examples

let z = Complex::cartesian(2.0, 1.0);
assert_eq!(z.conj(), Complex::cartesian(2.0, -1.0));

## Trait Implementations

### impl Add<Complex> for Complex

#### type Output = Complex

The resulting type after applying the + operator.

### impl Div<Complex> for Complex

#### type Output = Complex

The resulting type after applying the / operator.

### impl Div<f64> for Complex

#### type Output = Complex

The resulting type after applying the / operator.

### impl Mul<Complex> for Complex

#### type Output = Complex

The resulting type after applying the * operator.

### impl Mul<f64> for Complex

#### type Output = Complex

The resulting type after applying the * operator.

### impl Neg for Complex

#### type Output = Complex

The resulting type after applying the - operator.

### impl Sub<Complex> for Complex

#### type Output = Complex

The resulting type after applying the - operator.

## Blanket Implementations

### impl<T> Pointable for T

#### type Init = T

The type for initializers.

### impl<T> ToOwned for T where    T: Clone, [src]

#### type Owned = T

The resulting type after obtaining ownership.

### impl<T, U> TryFrom<U> for T where    U: Into<T>, [src]

#### type Error = Infallible

The type returned in the event of a conversion error.

### impl<T, U> TryInto<U> for T where    U: TryFrom<T>, [src]

#### type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.