Struct matrix::complex::Complex

source ·
pub struct Complex {
    pub real: f32,
    pub imag: f32,
}
Expand description

A struct representing a complex number with f32 real and imaginary components.

Fields§

§real: f32§imag: f32

Implementations§

source§

impl Complex

source

pub fn new(real: f32, imag: f32) -> Self

Creates a new Complex number given a real and imaginary part.

§Arguments
  • real - The real component of the complex number.
  • imag - The imaginary component of the complex number.
§Returns

A new Complex number with the specified real and imaginary components.

§Example
use matrix::Complex;

let complex_num = Complex::new(3.0, 4.0);
assert_eq!(complex_num.real, 3.0);
assert_eq!(complex_num.imag, 4.0);
source

pub fn conjugate(self) -> Self

Returns the conjugate of the complex number.

The conjugate of a complex number a + bi is given by a - bi.

complex numbers magnitude formula
§Returns

A new Complex number with the same real component and a negated imaginary component.

§Example
use matrix::Complex;

let complex_num = Complex::new(3.0, 4.0);
let conjugate = complex_num.conjugate();
assert_eq!(conjugate, Complex::new(3.0, -4.0));
source

pub fn magnitude(&self) -> f32

Computes the magnitude (or modulus) of the complex number.

The magnitude of a complex number ( z = a + bi ) is calculated as:

complex numbers magnitude formula

where a is the real part and b is the imaginary part of the complex number.

§Returns

A f64 value representing the magnitude of the complex number.

§Example
use matrix::Complex;

let complex_num = Complex::new(3.0, 4.0);
assert_eq!(complex_num.magnitude(), 5.0);

Trait Implementations§

source§

impl Add for Complex

source§

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

Adds two Complex numbers.

Given two complex numbers a + bi and c + di, the sum is:

complex nums addition
§Arguments
  • self - The first Complex number.
  • other - The second Complex number to add.
§Returns

A new Complex number which is the sum of self and other.

§Example
use matrix::Complex;

let a = Complex::new(3.0, 4.0);
let b = Complex::new(1.0, 2.0);
assert_eq!(a + b, Complex::new(4.0, 6.0));
§

type Output = Complex

The resulting type after applying the + operator.
source§

impl AddAssign for Complex

source§

fn add_assign(&mut self, other: Self)

Adds another Complex number to self.

source§

impl Clone for Complex

source§

fn clone(&self) -> Complex

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

source§

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

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

impl Display for Complex

source§

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

Formats the Complex for display.

§Parameters
  • f: A mutable reference to a fmt::Formatter for formatting.
§Returns
  • fmt::Result: Indicates success or failure of the formatting.
source§

impl Div for Complex

source§

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

Divides one Complex number by another.

Given two complex numbers a + bi and c + di, the quotient is:

complex nums multiplication formula
§Arguments
  • self - The Complex number to be divided.
  • other - The Complex number to divide by.
§Returns

A new Complex number which is the quotient of self and other.

§Example
use matrix::Complex;

let a = Complex::new(3.0, 2.0);
let b = Complex::new(1.0, -1.0);
let result = a / b;
assert!((result.real - 0.5).abs() < 1e-10);
assert!((result.imag - 2.5).abs() < 1e-10);
§

type Output = Complex

The resulting type after applying the / operator.
source§

impl DivAssign for Complex

source§

fn div_assign(&mut self, other: Self)

Divides self by another Complex number.

source§

impl Mul for Complex

source§

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

Multiplies two Complex numbers.

Given two complex numbers a + bi and c + di, the product is:

complex nums multiplication formula
§Arguments
  • self - The first Complex number.
  • other - The second Complex number to multiply.
§Returns

A new Complex number which is the product of self and other.

§Example
use matrix::Complex;

let a = Complex::new(3.0, 4.0);
let b = Complex::new(1.0, 2.0);
assert_eq!(a * b, Complex::new(-5.0, 10.0));
§

type Output = Complex

The resulting type after applying the * operator.
source§

impl MulAssign for Complex

source§

fn mul_assign(&mut self, other: Self)

Multiplies self by another Complex number.

source§

impl PartialEq for Complex

source§

fn eq(&self, other: &Complex) -> 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 PartialOrd for Complex

source§

fn partial_cmp(&self, other: &Complex) -> 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

This method 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

This method 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

This method 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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Scalar for Complex

source§

fn fma(a: Self, b: Self, c: Self) -> Self

Fused Multiply-Add (FMA): Computes a * b + c for Complex numbers.

source§

fn fms(a: Self, b: Self, c: Self) -> Self

Fused Multiply-Subtract (FMS): Computes a * b - c for Complex numbers.

source§

fn from_f32(value: f32) -> Self

Converts an f32 value to a Complex number with a zero imaginary part.

§Arguments
  • value - The f32 value to convert.
§Returns

A new Complex number with the real part set to value and imaginary part set to 0.

source§

fn to_f32(self) -> f32

Converts the real part of the Complex number to f32, ignoring the imaginary part.

§Returns

The real part of self as an f32 value.

source§

impl Sub for Complex

source§

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

Subtracts one Complex number from another.

Given two complex numbers a + bi and c + di, the difference is:

complex nums addition
§Arguments
  • self - The Complex number to be subtracted from.
  • other - The Complex number to subtract.
§Returns

A new Complex number which is the difference of self and other.

§Example
use matrix::Complex;

let a = Complex::new(3.0, 4.0);
let b = Complex::new(1.0, 2.0);
assert_eq!(a - b, Complex::new(2.0, 2.0));
§

type Output = Complex

The resulting type after applying the - operator.
source§

impl SubAssign for Complex

source§

fn sub_assign(&mut self, other: Self)

Subtracts another Complex number from self.

source§

impl Zero for Complex

source§

fn zero() -> Self

Returns the additive identity of Complex, which is 0 + 0i.

source§

fn is_zero(&self) -> bool

Checks if the Complex number is zero (both real and imaginary parts are zero).

source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.
source§

impl Copy for Complex

source§

impl StructuralPartialEq for Complex

Auto Trait Implementations§

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

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

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

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.