Struct quantr::Complex

source ·
pub struct Complex<T> {
    pub re: T,
    pub im: T,
}
Expand description

Generic complex number.

Fields§

§re: T§im: T

Implementations§

source§

impl Complex<f64>

source

pub fn exp_im(theta: f64) -> Complex<f64>

Returns exp(i*theta) as a complex number.

Example
use quantr::Complex;
use quantr::complex_im;
use std::f64::consts::PI;

let num: Complex<f64> = Complex::<f64>::exp_im(0.5f64 * PI);
source§

impl Complex<f32>

source

pub fn exp_im(theta: f32) -> Complex<f32>

Returns exp(i*theta) as a complex number.

Example
use quantr::Complex;
use quantr::complex_im;
use std::f32::consts::PI;

let num: Complex<f32> = Complex::<f32>::exp_im(0.5f32 * PI);
source§

impl<T: Add<Output = T> + Mul<Output = T> + Copy> Complex<T>

source

pub fn abs_square(self) -> T

Absolute square of a complex number, that is |z|^2 = a^2+b^2 where z = a + bi.

Example
use quantr::Complex;

let z: Complex<i16> = Complex{ re: 3i16, im: 4i16 };
assert_eq!(z.abs_square(), 25i16);
source§

impl<T: Add<Output = T> + Mul<Output = T> + Sqr + Copy> Complex<T>

source

pub fn abs(&self) -> T

Absolute value of a complex number, that is |z| = Sqrt(a^2+b^2) where z = a + bi.

Example
use quantr::Complex;

let z: Complex<f64> = Complex{ re: 3f64, im: 4f64 };
assert_eq!(z.abs(), 5f64);

Trait Implementations§

source§

impl<T: Add<Output = T>> Add for Complex<T>

Addition of two generic complex numbers.

source§

fn add(self, rhs: Self) -> Self::Output

Example
use quantr::Complex;

let z1: Complex<i16> = Complex{ re: -4i16, im: 2i16 };
let z2: Complex<i16> = Complex{ re: 2i16, im: 7i16 };
assert_eq!(z1 + z2, Complex{ re: -2i16, im: 9i16 });
§

type Output = Complex<T>

The resulting type after applying the + operator.
source§

impl<T: Clone> Clone for Complex<T>

source§

fn clone(&self) -> Complex<T>

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for Complex<T>

source§

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

Formats the value using the given formatter. Read more
source§

impl<T: Display> Display for Complex<T>

source§

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

Formats the value using the given formatter. Read more
source§

impl Mul<Complex<f64>> for f64

Multiplication Complex<f64> * f64.

source§

fn mul(self, rhs: Complex<f64>) -> Self::Output

RHS scalar multiplication: Complex<f64> * f64.

Example
use quantr::Complex;

let z1: f64 = 2f64;
let z2: Complex<f64> = Complex{ re: 2f64, im: 7f64 };
assert_eq!(z2 * z1, Complex{ re: 4f64, im: 14f64 });
§

type Output = Complex<f64>

The resulting type after applying the * operator.
source§

impl Mul<f64> for Complex<f64>

source§

fn mul(self, rhs: f64) -> Self::Output

LHS scalar multiplication: f64 * Complex<f64>.

Example
use quantr::Complex;

let z1: f64 = 2f64;
let z2: Complex<f64> = Complex{ re: 2f64, im: 7f64 };
assert_eq!(z1 * z2, Complex{ re: 4f64, im: 14f64 });
§

type Output = Complex<f64>

The resulting type after applying the * operator.
source§

impl<T: Mul<Output = T> + Add<Output = T> + Sub<Output = T> + Copy> Mul for Complex<T>

Multiplying two generic complex numbers.

source§

fn mul(self, rhs: Self) -> Self::Output

Example
use quantr::Complex;

let z1: Complex<i16> = Complex{ re: -4i16, im: 2i16 };
let z2: Complex<i16> = Complex{ re: 2i16, im: 7i16 };
assert_eq!(z1 * z2, Complex{ re: -22i16, im: -24i16 });
§

type Output = Complex<T>

The resulting type after applying the * operator.
source§

impl<T: PartialEq> PartialEq for Complex<T>

source§

fn eq(&self, other: &Complex<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: Sub<Output = T>> Sub for Complex<T>

Subtracts two generic complex numbers.

source§

fn sub(self, rhs: Self) -> Self::Output

Example
use quantr::Complex;

let z1: Complex<i16> = Complex{ re: -4i16, im: 2i16 };
let z2: Complex<i16> = Complex{ re: 2i16, im: 7i16 };
assert_eq!(z1 - z2, Complex{ re: -6i16, im: -5i16 });
§

type Output = Complex<T>

The resulting type after applying the - operator.
source§

impl<T: Copy> Copy for Complex<T>

source§

impl<T> StructuralPartialEq for Complex<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Complex<T>
where T: RefUnwindSafe,

§

impl<T> Send for Complex<T>
where T: Send,

§

impl<T> Sync for Complex<T>
where T: Sync,

§

impl<T> Unpin for Complex<T>
where T: Unpin,

§

impl<T> UnwindSafe for Complex<T>
where T: UnwindSafe,

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<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

§

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§

default 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>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

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

§

fn vzip(self) -> V