Skip to main content

Complex

Struct Complex 

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

A complex number stored in rectangular form.

Fields§

§re: T

The real component.

§im: T

The imaginary component.

Implementations§

§

impl<T> Complex<T>

pub const fn new(re: T, im: T) -> Complex<T>

Creates a complex number from real and imaginary parts.

pub const fn real(&self) -> &T

Returns the real component.

pub const fn imaginary(&self) -> &T

Returns the imaginary component.

§

impl<T> Complex<T>
where T: Default,

pub fn from_real(re: T) -> Complex<T>

Creates a real-only complex value.

pub fn from_imaginary(im: T) -> Complex<T>

Creates an imaginary-only complex value.

§

impl<T> Complex<T>
where T: Default + From<u8>,

pub fn zero() -> Complex<T>

Returns 0 + 0i.

pub fn one() -> Complex<T>

Returns 1 + 0i.

pub fn i() -> Complex<T>

Returns 0 + 1i.

§

impl<T> Complex<T>
where T: Copy + Neg<Output = T>,

pub fn conjugate(&self) -> Complex<T>

Returns the complex conjugate.

§

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

pub fn magnitude_squared(&self) -> T

Returns the squared magnitude, re^2 + im^2.

§

impl Complex<f32>

pub fn magnitude(&self) -> f32

Returns the magnitude, sqrt(re^2 + im^2).

pub fn argument(&self) -> f32

Returns the argument in radians.

pub fn from_polar(magnitude: f32, argument: f32) -> Complex<f32>

Builds a complex value from polar coordinates.

pub fn to_polar(&self) -> (f32, f32)

Returns (magnitude, argument) in polar form.

§

impl Complex<f64>

pub fn magnitude(&self) -> f64

Returns the magnitude, sqrt(re^2 + im^2).

pub fn argument(&self) -> f64

Returns the argument in radians.

pub fn from_polar(magnitude: f64, argument: f64) -> Complex<f64>

Builds a complex value from polar coordinates.

pub fn to_polar(&self) -> (f64, f64)

Returns (magnitude, argument) in polar form.

Trait Implementations§

§

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

§

type Output = Complex<T>

The resulting type after applying the + operator.
§

fn add(self, rhs: Complex<T>) -> <Complex<T> as Add>::Output

Performs the + operation. Read more
§

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

§

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

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

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

Performs copy-assignment from source. Read more
§

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

§

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

Formats the value using the given formatter. Read more
§

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

§

fn default() -> Complex<T>

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

impl<T> Display for Complex<T>
where T: Copy + Default + Display + Neg<Output = T> + PartialEq + PartialOrd,

§

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

Formats the value using the given formatter. Read more
§

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

§

type Output = Complex<T>

The resulting type after applying the / operator.
§

fn div(self, rhs: Complex<T>) -> <Complex<T> as Div>::Output

Performs the / operation. Read more
§

impl<T> From<Imaginary<T>> for Complex<T>
where T: Default,

§

fn from(value: Imaginary<T>) -> Complex<T>

Converts to this type from the input type.
§

impl<T> From<T> for Complex<T>
where T: Default,

§

fn from(value: T) -> Complex<T>

Converts to this type from the input type.
§

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

§

type Output = Complex<T>

The resulting type after applying the * operator.
§

fn mul(self, rhs: Complex<T>) -> <Complex<T> as Mul>::Output

Performs the * operation. Read more
§

impl<T> Neg for Complex<T>
where T: Neg<Output = T>,

§

type Output = Complex<T>

The resulting type after applying the - operator.
§

fn neg(self) -> <Complex<T> as Neg>::Output

Performs the unary - operation. Read more
§

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

§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

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

§

type Output = Complex<T>

The resulting type after applying the - operator.
§

fn sub(self, rhs: Complex<T>) -> <Complex<T> as Sub>::Output

Performs the - operation. Read more
§

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

§

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

§

impl<T> StructuralPartialEq for Complex<T>

Auto Trait Implementations§

§

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

§

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> UnsafeUnpin for Complex<T>
where T: UnsafeUnpin,

§

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

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 = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.