Complex

Struct Complex 

Source
pub struct Complex<T> { /* private fields */ }

Implementations§

Source§

impl<T> Complex<T>

Source

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

creates new complex number from real and imaginary parts

§Example
let z = Complex::new(3.0, 4.0); // 3 + 4i

basic constructor for complex numbers

Source§

impl<T: Copy> Complex<T>

Source

pub fn re(&self) -> T

Source

pub fn im(&self) -> T

Source§

impl Complex<f64>

Source

pub fn modulus(&self) -> f64

calculates absolute value (modulus) of complex number

§Example
let z = Complex::new(3.0, 4.0);
assert_eq!(z.modulus(), 5.0);

computes √(re² + im²)

Source

pub fn argument(&self) -> f64

calculates argument (phase) of complex number

§Example
let z = Complex::new(1.0, 1.0);
assert_eq!(z.argument(), std::f64::consts::PI/4.0);

returns angle in radians from positive real axis

Source

pub fn conjugate(&self) -> Self

returns complex conjugate

§Example
let z = Complex::new(3.0, 4.0);
let conj = z.conjugate(); // 3 - 4i

negates imaginary part while keeping real part

Source

pub fn exp(&self) -> Self

computes exponential of complex number

§Example
let z = Complex::I * std::f64::consts::PI;
let exp_z = z.exp(); // ≈ -1 + 0i

uses euler’s formula: e^(a+bi) = e^a(cos(b) + i*sin(b))

Source

pub fn ln(&self) -> Self

computes natural logarithm of complex number

§Example
let z = Complex::new(1.0, 0.0);
let ln_z = z.ln(); // 0 + 0i

returns ln|z| + i*arg(z)

Source

pub fn pow(&self, n: f64) -> Self

raises complex number to real power

§Example
let z = Complex::new(1.0, 1.0);
let z_squared = z.pow(2.0);

uses polar form for computation

Source

pub fn sqrt(&self) -> Self

calculates square root of complex number

§Example
let z = Complex::new(-1.0, 0.0);
let sqrt_z = z.sqrt(); // 0 + 1i

returns principal square root

Source

pub fn sin(&self) -> Self

Source

pub fn cos(&self) -> Self

Source

pub fn tan(&self) -> Self

Source

pub fn sinh(&self) -> Self

Source

pub fn cosh(&self) -> Self

Source

pub fn tanh(&self) -> Self

Source§

impl Complex<f64>

Source

pub const I: Complex<f64>

Source

pub const ONE: Complex<f64>

Source

pub const ZERO: Complex<f64>

Source§

impl Complex<f64>

Source

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

creates complex number from polar coordinates

§Example
let z = Complex::from_polar(2.0, std::f64::consts::PI/4.0);

converts (r,θ) to x + yi form

Source

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

converts to polar coordinates

§Example
let z = Complex::new(1.0, 1.0);
let (r, theta) = z.to_polar();

returns tuple of (modulus, argument)

Trait Implementations§

Source§

impl<T: Copy + Add<Output = T>> Add for Complex<T>

Source§

type Output = Complex<T>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

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

Source§

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
Source§

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

Source§

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

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

impl<T: Display> Display for Complex<T>

Source§

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

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

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

Source§

type Output = Complex<T>

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl From<f64> for Complex<f64>

Source§

fn from(x: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Complex<f64>

Source§

fn from(x: i32) -> Self

Converts to this type from the input type.
Source§

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

Source§

type Output = Complex<T>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

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

Source§

type Output = Complex<T>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

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

Source§

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.
Source§

impl<T: Copy + Sub<Output = T>> Sub for Complex<T>

Source§

type Output = Complex<T>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

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

Source§

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