[−]Struct lumol::Complex
Complex number, with double precision real and imaginary parts.
Complex
implements all the usual arithmetic operations:
let w = Complex::cartesian(-1.0, 0.5); let z = Complex::cartesian(4.0, 2.0); // Addition let c = w + z; assert_eq!(c, Complex::cartesian(3.0, 2.5)); // Subtraction let c = w - z; assert_eq!(c, Complex::cartesian(-5.0, -1.5)); // Multiplication let c = w * z; assert_eq!(c, Complex::cartesian(-5.0, 0.0)); let c = 42.0 * w; assert_eq!(c, Complex::cartesian(-42.0, 21.0)); // Division let c = z / 2.0; assert_eq!(c, Complex::cartesian(2.0, 1.0));
Implementations
impl Complex
pub fn polar(r: f64, phi: f64) -> Complex
Create a new Complex
from a norm r
and a phase phi
in radians.
Examples
let z = Complex::polar(3.0, f64::consts::PI); assert_eq!(z.norm(), 3.0);
pub fn cartesian(x: f64, y: f64) -> Complex
Create a complex from Cartesian coordinates
Examples
let z = Complex::cartesian(3.0, -2.0); assert_eq!(z.real(), 3.0); assert_eq!(z.imag(), -2.0);
pub fn zero() -> Complex
Create a new Complex
with both cartesian coordinate set to 0.
Examples
let z = Complex::zero(); assert_eq!(z.norm(), 0.0);
pub fn real(&self) -> f64
Get the real part of the complex
Examples
let z = Complex::cartesian(3.0, -2.0); assert_eq!(z.real(), 3.0);
pub fn imag(&self) -> f64
Get the imaginary part of the complex
Examples
let z = Complex::cartesian(3.0, -2.0); assert_eq!(z.imag(), -2.0);
pub fn phase(&self) -> f64
Get the phase of the complex in the [-π, π) interval
Examples
let z = Complex::polar(2.0, 0.3); assert_eq!(z.phase(), 0.3);
pub fn norm(&self) -> f64
Get the norm of the complex
Examples
let z = Complex::polar(2.0, 0.3); assert_eq!(z.norm(), 2.0); let z = Complex::cartesian(2.0, 1.0); assert_eq!(z.norm(), f64::sqrt(5.0));
pub fn norm2(&self) -> f64
Get the square of the norm if this complex
Examples
let z = Complex::cartesian(2.0, 1.0); assert_eq!(z.norm2(), 5.0);
pub fn conj(&self) -> Complex
Get the conjugate of the complex
Examples
let z = Complex::cartesian(2.0, 1.0); assert_eq!(z.conj(), Complex::cartesian(2.0, -1.0));
Trait Implementations
impl Add<Complex> for Complex
type Output = Complex
The resulting type after applying the +
operator.
pub fn add(self, other: Complex) -> Complex
impl AddAssign<Complex> for Complex
pub fn add_assign(&mut self, other: Complex)
impl Clone for Complex
pub fn clone(&self) -> Complex
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Copy for Complex
impl Debug for Complex
impl Default for Complex
impl Div<Complex> for Complex
type Output = Complex
The resulting type after applying the /
operator.
pub fn div(self, other: Complex) -> Complex
impl Div<f64> for Complex
type Output = Complex
The resulting type after applying the /
operator.
pub fn div(self, other: f64) -> Complex
impl DivAssign<Complex> for Complex
pub fn div_assign(&mut self, other: Complex)
impl DivAssign<f64> for Complex
pub fn div_assign(&mut self, other: f64)
impl Mul<Complex> for Complex
type Output = Complex
The resulting type after applying the *
operator.
pub fn mul(self, other: Complex) -> Complex
impl Mul<f64> for Complex
type Output = Complex
The resulting type after applying the *
operator.
pub fn mul(self, other: f64) -> Complex
impl MulAssign<Complex> for Complex
pub fn mul_assign(&mut self, other: Complex)
impl MulAssign<f64> for Complex
pub fn mul_assign(&mut self, other: f64)
impl Neg for Complex
impl One for Complex
pub fn one() -> Complex
fn set_one(&mut self)
[src]
fn is_one(&self) -> bool where
Self: PartialEq<Self>,
[src]
Self: PartialEq<Self>,
impl PartialEq<Complex> for Complex
impl StructuralPartialEq for Complex
impl Sub<Complex> for Complex
type Output = Complex
The resulting type after applying the -
operator.
pub fn sub(self, other: Complex) -> Complex
impl SubAssign<Complex> for Complex
pub fn sub_assign(&mut self, other: Complex)
impl Zero for Complex
Auto Trait Implementations
impl RefUnwindSafe for Complex
impl Send for Complex
impl Sync for Complex
impl Unpin for Complex
impl UnwindSafe for Complex
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> LinalgScalar for T where
T: One<Output = T> + Add<T, Output = T> + Sub<T, Output = T> + 'static + Mul<T> + Copy + Div<T, Output = T> + Zero,
[src]
T: One<Output = T> + Add<T, Output = T> + Sub<T, Output = T> + 'static + Mul<T> + Copy + Div<T, Output = T> + Zero,
impl<T> Pointable for T
pub const ALIGN: usize
type Init = T
The type for initializers.
pub unsafe fn init(init: <T as Pointable>::Init) -> usize
pub unsafe fn deref<'a>(ptr: usize) -> &'a T
pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
pub unsafe fn drop(ptr: usize)
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,