Struct ComplexNumber

Source
pub struct ComplexNumber<T: ComplexNumberRequiredTraits<T>> {
    pub real: T,
    pub complex: T,
}

Fields§

§real: T§complex: T

Implementations§

Source§

impl<T: ComplexNumberRequiredTraits<T>> ComplexNumber<T>

Source

pub fn new(real: T, complex: T) -> ComplexNumber<T>

Source

pub fn complex_conjugate(&self) -> Self

Creates a new complex number that is the complex conjugate of the original

use matrix::complex_number::ComplexNumber;
use rand::prelude::*;
let mut rng = rand::thread_rng();
let real = rng.gen_range(1.0..=100.0);
let complex = rng.gen_range(1.0..=100.0);
let complex_number = ComplexNumber::new(real, complex);

assert_eq!(
    complex_number.complex_conjugate(),
    ComplexNumber::new(real, -complex,)
);
Source

pub fn magnitude(&self) -> T

Calculates the cartesian magnitude of a complex number Requires T to implement the sqrt trait which exposes the square_root() method

use matrix::complex_number::ComplexNumber;
let test_complex_number = ComplexNumber::new(3.0, 4.0);
assert_eq!(test_complex_number.magnitude(), 5.0);
Source

pub fn normalized(&self) -> Self

Creates a new complex number that is a normalised copy of the first.


use matrix::complex_number::ComplexNumber;
let test_complex_number = ComplexNumber::new(3.0, 4.0);
let normalised = test_complex_number.normalized();
assert_eq!(normalised.real, 0.6);
assert_eq!(normalised.complex, 0.8);
Source

pub fn square_root(&self) -> Self

Calculates the square root of a complex number

use matrix::complex_number::ComplexNumber;
let complex = ComplexNumber::new(3.0, 4.0);

assert_eq!(complex.square_root(), ComplexNumber::new(2.0, 1.0));
Source

pub fn powf(&self, n: T) -> Self

Implementation of the Pow trait for ComplexNumber

Trait Implementations§

Source§

impl<T: ComplexNumberRequiredTraits<T>> Add for ComplexNumber<T>

Source§

type Output = ComplexNumber<T>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<T: ComplexNumberRequiredTraits<T>> AddAssign for ComplexNumber<T>

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl<T: Clone + ComplexNumberRequiredTraits<T>> Clone for ComplexNumber<T>

Source§

fn clone(&self) -> ComplexNumber<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
Source§

impl<T: Debug + ComplexNumberRequiredTraits<T>> Debug for ComplexNumber<T>

Source§

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

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

impl<T: ComplexNumberRequiredTraits<T>> Default for ComplexNumber<T>

Source§

fn default() -> Self

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

impl<T: ComplexNumberRequiredTraits<T>> Display for ComplexNumber<T>

Source§

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

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

impl<T: ComplexNumberRequiredTraits<T>> Div for ComplexNumber<T>

Source§

type Output = ComplexNumber<T>

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl<T: ComplexNumberRequiredTraits<T>> DivAssign for ComplexNumber<T>

Source§

fn div_assign(&mut self, rhs: Self)

Performs the /= operation. Read more
Source§

impl<T: ComplexNumberRequiredTraits<T>> From<u8> for ComplexNumber<T>

Source§

fn from(value: u8) -> Self

Converts to this type from the input type.
Source§

impl<T: ComplexNumberRequiredTraits<T>> Mul for ComplexNumber<T>

Source§

type Output = ComplexNumber<T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<T: ComplexNumberRequiredTraits<T>> MulAssign for ComplexNumber<T>

Source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
Source§

impl<T: ComplexNumberRequiredTraits<T>> Neg for ComplexNumber<T>

Source§

type Output = ComplexNumber<T>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<T: PartialEq + ComplexNumberRequiredTraits<T>> PartialEq for ComplexNumber<T>

Source§

fn eq(&self, other: &ComplexNumber<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.
Source§

impl<T: PartialOrd + ComplexNumberRequiredTraits<T>> PartialOrd for ComplexNumber<T>

Source§

fn partial_cmp(&self, other: &ComplexNumber<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: ComplexNumberRequiredTraits<T>> Pow for ComplexNumber<T>

Source§

fn pow(&self, n: ComplexNumber<T>) -> Self

Source§

impl<T: ComplexNumberRequiredTraits<T>> Sqrt for ComplexNumber<T>

Source§

fn square_root(&self) -> Self

Source§

impl<T: ComplexNumberRequiredTraits<T>> Sub for ComplexNumber<T>

Source§

type Output = ComplexNumber<T>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<T: Copy + ComplexNumberRequiredTraits<T>> Copy for ComplexNumber<T>

Source§

impl<T: ComplexNumberRequiredTraits<T>> StructuralPartialEq for ComplexNumber<T>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for ComplexNumber<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.
Source§

impl<T> ComplexNumberRequiredTraits<T> for T
where T: Div<Output = T> + Add<Output = T, Output = T> + Add + Mul<Output = T> + AddAssign + MulAssign + DivAssign + Clone + Copy + Display + PartialOrd + Neg<Output = T> + Sub<Output = T> + Default + Sqrt + Pow + From<u8> + ?Sized,

Source§

impl<T> MatrixElementRequiredTraits<T> for T
where T: Div<Output = T> + Add<Output = T, Output = T> + Add + Mul<Output = T> + AddAssign + MulAssign + DivAssign + Clone + Copy + Display + PartialOrd + Neg<Output = T> + Sub<Output = T> + Default + Sqrt + Pow + From<u8> + ?Sized,