Struct Complex

Source
pub struct Complex {
    pub real: f64,
    pub imaginary: f64,
}
Expand description

Represents a complex number

Fields§

§real: f64

The real part

§imaginary: f64

The imaginary part.

Implementations§

Source§

impl Complex

Source

pub const fn new(real: f64, imaginary: f64) -> Self

Create a new complex from its real and imaginary parts.

Source

pub const fn real(real: f64) -> Self

Convert a real to a complex.

Source

pub fn polar(theta: f64, radius: f64) -> Self

Create a new complex from its polar representation.

Source

pub const fn zero() -> Self

Complex zero.

Source

pub const fn one() -> Self

Complex one.

Source

pub const fn i() -> Self

The imaginary unit.

Source

pub fn mul_i(self) -> Complex

Optimized multiplication by the complex unit (i).

Source

pub fn magnitude(self) -> f64

The magnitude of the complex, also called its modulus.

Source

pub fn conjugate(self) -> Complex

The complex’s conjugate (a - bi)

Source

pub fn partial_mul(self, other: Complex) -> Complex

Multiply the complex’s parts by other complex’s parts (ab + cdi)

Source

pub fn partial_div(self, other: Complex) -> Complex

Divide the complex’s parts by other complex’s parts (a/b + (c/d)i)

Source

pub fn arg(self) -> f64

Compute the complex’s argument

Source

pub fn normalize(self) -> Complex

Normalize the complex by dividing it by its own magnitude.

Source

pub fn len_squared(self) -> f64

Number-theoretical norm. Simply a^2 + b^2 with self = a + bi

Source

pub fn sqrt(self) -> Complex

A square root. Chooses the one with non-negative imaginary part.

Source

pub fn sqrt_norm(self) -> Complex

Same as sqrt, but returns a normalized result.

Source

pub fn inverse(self) -> Self

Inverse of the number.

Trait Implementations§

Source§

impl Add<f64> for Complex

Source§

type Output = Complex

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Add for Complex

Source§

type Output = Complex

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl AddAssign for Complex

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl Clone for Complex

Source§

fn clone(&self) -> Complex

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

Source§

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

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

impl Default for Complex

Source§

fn default() -> Self

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

impl Display for Complex

Source§

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

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

impl Div<f64> for Complex

Source§

type Output = Complex

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl Div for Complex

Source§

type Output = Complex

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl From<Complex> for Complex

Source§

fn from(value: Complex) -> Self

Converts to this type from the input type.
Source§

impl From<Complex> for Position

Source§

fn from(value: Complex) -> Self

Converts to this type from the input type.
Source§

impl From<Position> for Complex

Source§

fn from(value: Position) -> Self

Converts to this type from the input type.
Source§

impl Mul<Complex> for f64

Source§

type Output = Complex

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<f64> for Complex

Source§

type Output = Complex

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul for Complex

Source§

type Output = Complex

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl MulAssign<f64> for Complex

Source§

fn mul_assign(&mut self, rhs: f64)

Performs the *= operation. Read more
Source§

impl MulAssign for Complex

Source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
Source§

impl Neg for Complex

Source§

type Output = Complex

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl Product for Complex

Source§

fn product<I: Iterator<Item = Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by multiplying the items.
Source§

impl Serialize for Complex

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Sub<f64> for Complex

Source§

type Output = Complex

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Sub for Complex

Source§

type Output = Complex

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl SubAssign for Complex

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

impl Sum for Complex

Source§

fn sum<I: Iterator<Item = Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl Copy 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: 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> CloneWithNode for T
where T: Clone,

Source§

fn clone_with_node(&mut self) -> T

Clone self and take its node.
Source§

fn clone_without_node(&self) -> T

Clone self without taking its node.
Source§

impl<T> Convert for T

Source§

fn convert<U>(self, context: &CompileContext) -> Expr<U>
where U: ConvertFrom<T>,

Convert self into a specific type. Read more
Source§

fn can_convert<U>(&self) -> bool
where U: ConvertFrom<T>,

Check if self can be converted into a specific type. 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.