[]Struct lumol::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);

// Addition
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 AddAssign<Complex> for Complex

impl Clone for Complex

impl Copy for Complex

impl Debug for Complex

impl Default for Complex

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 DivAssign<Complex> for Complex

impl DivAssign<f64> for Complex

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 MulAssign<Complex> for Complex

impl MulAssign<f64> for Complex

impl Neg for Complex

type Output = Complex

The resulting type after applying the - operator.

impl One for Complex

impl PartialEq<Complex> for Complex

impl StructuralPartialEq for Complex

impl Sub<Complex> for Complex

type Output = Complex

The resulting type after applying the - operator.

impl SubAssign<Complex> for Complex

impl Zero for Complex

Auto Trait Implementations

impl RefUnwindSafe for Complex

impl Send for Complex

impl Sync for Complex

impl Unpin for Complex

impl UnwindSafe for Complex

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

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

impl<T> LinalgScalar for T where
    T: One<Output = T> + Add<T, Output = T> + Sub<T, Output = T> + 'static + Mul<T> + Copy + Div<T, Output = T> + Zero
[src]

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.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,