Skip to main content

Complex

Struct Complex 

Source
pub struct Complex {
    pub re: f64,
    pub im: f64,
}
Expand description

A complex number z = re + im·i.

Fields§

§re: f64

Real part of the complex number.

§im: f64

Imaginary part of the complex number.

Implementations§

Source§

impl Complex

Source

pub fn acos(self) -> Option<Self>

Inverse cosine: arccos(z) = -i * log(z + i*sqrt(1 - z^2)).

Source§

impl Complex

Source

pub fn approx_eq(self, other: Self, eps: f64) -> bool

Is z approximately equal to w?

Source§

impl Complex

Source

pub fn arg(self) -> f64

Argument: arg(z) ∈ (-π, π].

Source

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

Convert to polar form (r, θ).

Source§

impl Complex

Source

pub fn asin(self) -> Option<Self>

Inverse sine: arcsin(z) = -i * log(iz + sqrt(1 - z^2)).

Source§

impl Complex

Source

pub fn atan(self) -> Option<Self>

Inverse tangent: arctan(z) = (i/2) * log((i+z)/(i-z)).

Source§

impl Complex

Source

pub fn cos(self) -> Self

Complex cosine: cos(z) = (e^(iz) + e^(-iz)) / 2.

Source

pub fn tan(self) -> Option<Self>

Complex tangent: tan(z) = sin(z)/cos(z).

Source§

impl Complex

Source

pub fn cosh(self) -> Self

Hyperbolic cosine: cosh(z) = (e^z + e^(-z)) / 2.

Source§

impl Complex

Source

pub fn im(self) -> f64

Imaginary part.

Source§

impl Complex

Source

pub fn new(re: f64, im: f64) -> Self

Create a new complex number.

Source

pub fn zero() -> Self

Zero.

Source

pub fn one() -> Self

One.

Source

pub fn i() -> Self

Imaginary unit i.

Source

pub fn conj(self) -> Self

Complex conjugate: a + bi → a - bi.

Source

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

Addition.

Source

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

Subtraction.

Source

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

Multiplication: (a+bi)(c+di) = (ac-bd) + (ad+bc)i.

Source

pub fn scale(self, s: f64) -> Self

Scalar multiplication.

Source

pub fn neg(self) -> Self

Negation.

Source

pub fn exp(self) -> Self

Complex exponential: exp(a+bi) = e^a * (cos b + i sin b).

Source

pub fn log(self) -> Option<Self>

Principal complex logarithm: log(z) = ln|z| + i·arg(z).

Source

pub fn sqrt(self) -> Self

Principal square root.

Source

pub fn sin(self) -> Self

Complex sine: sin(z) = (e^(iz) - e^(-iz)) / (2i).

Source

pub fn from_polar(r: f64, theta: f64) -> Self

Polar form: (r, θ) → r·(cos θ + i·sin θ).

Source§

impl Complex

Source

pub fn norm_sq(self) -> f64

Modulus squared: |z|² = re² + im².

Source

pub fn abs(self) -> f64

Modulus: |z|.

Source

pub fn div(self, other: Self) -> Option<Self>

Division: z/w = z * conj(w) / |w|².

Source§

impl Complex

Source

pub fn nth_roots(self, n: u32) -> Vec<Self>

n-th roots of z: returns all n roots.

Source§

impl Complex

Source

pub fn powc(self, w: Self) -> Option<Self>

Complex power z^w = exp(w * log(z)).

Source§

impl Complex

Source

pub fn powi(self, n: i32) -> Self

Complex power z^n for integer n (fast exponentiation).

Source§

impl Complex

Source

pub fn re(self) -> f64

Real part.

Source§

impl Complex

Source

pub fn roots_of_unity(n: u32) -> Vec<Self>

n-th roots of unity: e^(2πi·k/n) for k = 0..n-1.

Source§

impl Complex

Source

pub fn sinh(self) -> Self

Hyperbolic sine: sinh(z) = (e^z - e^(-z)) / 2.

Source

pub fn tanh(self) -> Option<Self>

Hyperbolic tangent: tanh(z) = sinh(z)/cosh(z).

Trait Implementations§

Source§

impl Add for Complex

Source§

type Output = Complex

The resulting type after applying the + operator.
Source§

fn add(self, other: Self) -> 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 Display for Complex

Source§

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

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

impl Mul for Complex

Source§

type Output = Complex

The resulting type after applying the * operator.
Source§

fn mul(self, other: Self) -> 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

Performs the unary - operation. Read more
Source§

impl PartialEq for Complex

Source§

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

Source§

type Output = Complex

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
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: 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> Setoid for T
where T: PartialEq,

Source§

fn equiv(&self, other: &T) -> bool

The equivalence relation.
Source§

fn refl(&self) -> bool

Reflexivity of the equivalence.
Source§

fn symm(&self, other: &Self) -> bool

Symmetry: if self ~ other then other ~ self.
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.