#[repr(C)]pub struct Complex<T> {
pub re: T,
pub im: T,
}
Expand description
A complex number in Cartesian form.
§Representation and Foreign Function Interface Compatibility
Complex<T>
is memory layout compatible with an array [T; 2]
.
Note that Complex<F>
where F is a floating point type is only memory
layout compatible with C’s complex types, not necessarily calling
convention compatible. This means that for FFI you can only pass
Complex<F>
behind a pointer, not as a value.
§Examples
Example of extern function declaration.
use num_complex::Complex;
use std::os::raw::c_int;
extern "C" {
fn zaxpy_(n: *const c_int, alpha: *const Complex<f64>,
x: *const Complex<f64>, incx: *const c_int,
y: *mut Complex<f64>, incy: *const c_int);
}
Fields§
§re: T
Real portion of the complex number
im: T
Imaginary portion of the complex number
Implementations§
Source§impl<T: Clone + Num> Complex<T>
impl<T: Clone + Num> Complex<T>
Source§impl<T: Clone + Float> Complex<T>
impl<T: Clone + Float> Complex<T>
Sourcepub fn to_polar(&self) -> (T, T)
pub fn to_polar(&self) -> (T, T)
Convert to polar form (r, theta), such that
self = r * exp(i * theta)
Sourcepub fn from_polar(r: &T, theta: &T) -> Complex<T>
pub fn from_polar(r: &T, theta: &T) -> Complex<T>
Convert a polar representation into a complex number.
Sourcepub fn exp(&self) -> Complex<T>
pub fn exp(&self) -> Complex<T>
Computes e^(self)
, where e
is the base of the natural logarithm.
Sourcepub fn ln(&self) -> Complex<T>
pub fn ln(&self) -> Complex<T>
Computes the principal value of natural logarithm of self
.
This function has one branch cut:
(-∞, 0]
, continuous from above.
The branch satisfies -π ≤ arg(ln(z)) ≤ π
.
Sourcepub fn sqrt(&self) -> Complex<T>
pub fn sqrt(&self) -> Complex<T>
Computes the principal value of the square root of self
.
This function has one branch cut:
(-∞, 0)
, continuous from above.
The branch satisfies -π/2 ≤ arg(sqrt(z)) ≤ π/2
.
Sourcepub fn log(&self, base: T) -> Complex<T>
pub fn log(&self, base: T) -> Complex<T>
Returns the logarithm of self
with respect to an arbitrary base.
Sourcepub fn expf(&self, base: T) -> Complex<T>
pub fn expf(&self, base: T) -> Complex<T>
Raises a floating point number to the complex power self
.
Sourcepub fn asin(&self) -> Complex<T>
pub fn asin(&self) -> Complex<T>
Computes the principal value of the inverse sine of self
.
This function has two branch cuts:
(-∞, -1)
, continuous from above.(1, ∞)
, continuous from below.
The branch satisfies -π/2 ≤ Re(asin(z)) ≤ π/2
.
Sourcepub fn acos(&self) -> Complex<T>
pub fn acos(&self) -> Complex<T>
Computes the principal value of the inverse cosine of self
.
This function has two branch cuts:
(-∞, -1)
, continuous from above.(1, ∞)
, continuous from below.
The branch satisfies 0 ≤ Re(acos(z)) ≤ π
.
Sourcepub fn atan(&self) -> Complex<T>
pub fn atan(&self) -> Complex<T>
Computes the principal value of the inverse tangent of self
.
This function has two branch cuts:
(-∞i, -i]
, continuous from the left.[i, ∞i)
, continuous from the right.
The branch satisfies -π/2 ≤ Re(atan(z)) ≤ π/2
.
Sourcepub fn asinh(&self) -> Complex<T>
pub fn asinh(&self) -> Complex<T>
Computes the principal value of inverse hyperbolic sine of self
.
This function has two branch cuts:
(-∞i, -i)
, continuous from the left.(i, ∞i)
, continuous from the right.
The branch satisfies -π/2 ≤ Im(asinh(z)) ≤ π/2
.
Sourcepub fn acosh(&self) -> Complex<T>
pub fn acosh(&self) -> Complex<T>
Computes the principal value of inverse hyperbolic cosine of self
.
This function has one branch cut:
(-∞, 1)
, continuous from above.
The branch satisfies -π ≤ Im(acosh(z)) ≤ π
and 0 ≤ Re(acosh(z)) < ∞
.
Sourcepub fn atanh(&self) -> Complex<T>
pub fn atanh(&self) -> Complex<T>
Computes the principal value of inverse hyperbolic tangent of self
.
This function has two branch cuts:
(-∞, -1]
, continuous from above.[1, ∞)
, continuous from below.
The branch satisfies -π/2 ≤ Im(atanh(z)) ≤ π/2
.
Sourcepub fn is_infinite(self) -> bool
pub fn is_infinite(self) -> bool
Checks if the given complex number is infinite
Trait Implementations§
Source§impl<'a, T: Clone + NumAssign> AddAssign<&'a Complex<T>> for Complex<T>
impl<'a, T: Clone + NumAssign> AddAssign<&'a Complex<T>> for Complex<T>
Source§fn add_assign(&mut self, other: &Complex<T>)
fn add_assign(&mut self, other: &Complex<T>)
+=
operation. Read moreSource§impl<'a, T: Clone + NumAssign> AddAssign<&'a T> for Complex<T>
impl<'a, T: Clone + NumAssign> AddAssign<&'a T> for Complex<T>
Source§fn add_assign(&mut self, other: &T)
fn add_assign(&mut self, other: &T)
+=
operation. Read moreSource§impl<T: Clone + NumAssign> AddAssign<T> for Complex<T>
impl<T: Clone + NumAssign> AddAssign<T> for Complex<T>
Source§fn add_assign(&mut self, other: T)
fn add_assign(&mut self, other: T)
+=
operation. Read moreSource§impl<T: Clone + NumAssign> AddAssign for Complex<T>
impl<T: Clone + NumAssign> AddAssign for Complex<T>
Source§fn add_assign(&mut self, other: Complex<T>)
fn add_assign(&mut self, other: Complex<T>)
+=
operation. Read moreSource§impl<'a, T: Clone + NumAssign> DivAssign<&'a Complex<T>> for Complex<T>
impl<'a, T: Clone + NumAssign> DivAssign<&'a Complex<T>> for Complex<T>
Source§fn div_assign(&mut self, other: &Complex<T>)
fn div_assign(&mut self, other: &Complex<T>)
/=
operation. Read moreSource§impl<'a, T: Clone + NumAssign> DivAssign<&'a T> for Complex<T>
impl<'a, T: Clone + NumAssign> DivAssign<&'a T> for Complex<T>
Source§fn div_assign(&mut self, other: &T)
fn div_assign(&mut self, other: &T)
/=
operation. Read moreSource§impl<T: Clone + NumAssign> DivAssign<T> for Complex<T>
impl<T: Clone + NumAssign> DivAssign<T> for Complex<T>
Source§fn div_assign(&mut self, other: T)
fn div_assign(&mut self, other: T)
/=
operation. Read moreSource§impl<T: Clone + NumAssign> DivAssign for Complex<T>
impl<T: Clone + NumAssign> DivAssign for Complex<T>
Source§fn div_assign(&mut self, other: Complex<T>)
fn div_assign(&mut self, other: Complex<T>)
/=
operation. Read moreSource§impl<'a, T: Clone + NumAssign> MulAssign<&'a Complex<T>> for Complex<T>
impl<'a, T: Clone + NumAssign> MulAssign<&'a Complex<T>> for Complex<T>
Source§fn mul_assign(&mut self, other: &Complex<T>)
fn mul_assign(&mut self, other: &Complex<T>)
*=
operation. Read moreSource§impl<'a, T: Clone + NumAssign> MulAssign<&'a T> for Complex<T>
impl<'a, T: Clone + NumAssign> MulAssign<&'a T> for Complex<T>
Source§fn mul_assign(&mut self, other: &T)
fn mul_assign(&mut self, other: &T)
*=
operation. Read moreSource§impl<T: Clone + NumAssign> MulAssign<T> for Complex<T>
impl<T: Clone + NumAssign> MulAssign<T> for Complex<T>
Source§fn mul_assign(&mut self, other: T)
fn mul_assign(&mut self, other: T)
*=
operation. Read moreSource§impl<T: Clone + NumAssign> MulAssign for Complex<T>
impl<T: Clone + NumAssign> MulAssign for Complex<T>
Source§fn mul_assign(&mut self, other: Complex<T>)
fn mul_assign(&mut self, other: Complex<T>)
*=
operation. Read moreSource§impl<T: Num + Clone> Num for Complex<T>
impl<T: Num + Clone> Num for Complex<T>
Source§fn from_str_radix(s: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr>
fn from_str_radix(s: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr>
Parses a +/- bi
; ai +/- b
; a
; or bi
where a
and b
are of type T
type FromStrRadixErr = ParseComplexError<<T as Num>::FromStrRadixErr>
Source§impl<'a, T: Clone + NumAssign> RemAssign<&'a Complex<T>> for Complex<T>
impl<'a, T: Clone + NumAssign> RemAssign<&'a Complex<T>> for Complex<T>
Source§fn rem_assign(&mut self, other: &Complex<T>)
fn rem_assign(&mut self, other: &Complex<T>)
%=
operation. Read moreSource§impl<'a, T: Clone + NumAssign> RemAssign<&'a T> for Complex<T>
impl<'a, T: Clone + NumAssign> RemAssign<&'a T> for Complex<T>
Source§fn rem_assign(&mut self, other: &T)
fn rem_assign(&mut self, other: &T)
%=
operation. Read moreSource§impl<T: Clone + NumAssign> RemAssign<T> for Complex<T>
impl<T: Clone + NumAssign> RemAssign<T> for Complex<T>
Source§fn rem_assign(&mut self, other: T)
fn rem_assign(&mut self, other: T)
%=
operation. Read moreSource§impl<T: Clone + NumAssign> RemAssign for Complex<T>
impl<T: Clone + NumAssign> RemAssign for Complex<T>
Source§fn rem_assign(&mut self, other: Complex<T>)
fn rem_assign(&mut self, other: Complex<T>)
%=
operation. Read moreSource§impl<'a, T: Clone + NumAssign> SubAssign<&'a Complex<T>> for Complex<T>
impl<'a, T: Clone + NumAssign> SubAssign<&'a Complex<T>> for Complex<T>
Source§fn sub_assign(&mut self, other: &Complex<T>)
fn sub_assign(&mut self, other: &Complex<T>)
-=
operation. Read moreSource§impl<'a, T: Clone + NumAssign> SubAssign<&'a T> for Complex<T>
impl<'a, T: Clone + NumAssign> SubAssign<&'a T> for Complex<T>
Source§fn sub_assign(&mut self, other: &T)
fn sub_assign(&mut self, other: &T)
-=
operation. Read moreSource§impl<T: Clone + NumAssign> SubAssign<T> for Complex<T>
impl<T: Clone + NumAssign> SubAssign<T> for Complex<T>
Source§fn sub_assign(&mut self, other: T)
fn sub_assign(&mut self, other: T)
-=
operation. Read moreSource§impl<T: Clone + NumAssign> SubAssign for Complex<T>
impl<T: Clone + NumAssign> SubAssign for Complex<T>
Source§fn sub_assign(&mut self, other: Complex<T>)
fn sub_assign(&mut self, other: Complex<T>)
-=
operation. Read more