Struct idsp::Complex [−][src]
#[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
Returns the square of the norm (since T
doesn’t necessarily
have a sqrt function), i.e. re^2 + im^2
.
Returns the L1 norm |re| + |im|
– the Manhattan distance from the origin.
Checks if the given complex number is infinite
Trait Implementations
Performs the +=
operation. Read more
Performs the +=
operation. Read more
Performs the +=
operation. Read more
Performs the +=
operation. Read more
Return a Complex on the unit circle given an angle.
Example:
use idsp::{Complex, ComplexExt};
Complex::<i32>::from_angle(0);
Complex::<i32>::from_angle(1 << 30); // pi/2
Complex::<i32>::from_angle(-1 << 30); // -pi/2
Return the absolute square (the squared magnitude).
Note: Normalization is 1 << 32
, i.e. U0.32.
Note(panic): This will panic for Complex(i32::MIN, i32::MIN)
Example:
use idsp::{Complex, ComplexExt};
assert_eq!(Complex::new(i32::MIN, 0).abs_sqr(), 1 << 31);
assert_eq!(Complex::new(i32::MAX, i32::MAX).abs_sqr(), u32::MAX - 3);
log2(power) re full scale approximation
TODO: scale up, interpolate
Panic:
This will panic for Complex(i32::MIN, i32::MIN)
Example:
use idsp::{Complex, ComplexExt};
assert_eq!(Complex::new(i32::MAX, i32::MAX).log2(), -1);
assert_eq!(Complex::new(i32::MAX, 0).log2(), -2);
assert_eq!(Complex::new(1, 0).log2(), -63);
assert_eq!(Complex::new(0, 0).log2(), -64);
Return the angle.
Note: Normalization is 1 << 31 == pi
.
Example:
use idsp::{Complex, ComplexExt};
assert_eq!(Complex::new(1, 0).arg(), 0);
assert_eq!(Complex::new(-i32::MAX, 1).arg(), i32::MAX);
assert_eq!(Complex::new(-i32::MAX, -1).arg(), -i32::MAX);
assert_eq!(Complex::new(0, -1).arg(), -i32::MAX >> 1);
assert_eq!(Complex::new(0, 1).arg(), (i32::MAX >> 1) + 1);
assert_eq!(Complex::new(1, 1).arg(), (i32::MAX >> 2) + 1);
pub fn deserialize<D>(
deserializer: D
) -> Result<Complex<T>, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
pub fn deserialize<D>(
deserializer: D
) -> Result<Complex<T>, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Performs the /=
operation. Read more
Performs the /=
operation. Read more
Performs the /=
operation. Read more
Performs the /=
operation. Read more
Converts a usize
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read more
Converts an isize
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read more
Converts an u8
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read more
Converts an u16
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read more
Converts an u32
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read more
Converts an u64
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read more
Converts an i8
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read more
Converts an i16
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read more
Converts an i32
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read more
Converts an i64
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read more
Converts an u128
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read more
Converts an i128
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read more
Converts a f32
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read more
impl<'a, 'b, T> MulAddAssign<&'a Complex<T>, &'b Complex<T>> for Complex<T> where
T: Clone + NumAssign + MulAddAssign<T, T>,
impl<'a, 'b, T> MulAddAssign<&'a Complex<T>, &'b Complex<T>> for Complex<T> where
T: Clone + NumAssign + MulAddAssign<T, T>,
Performs the fused multiply-add operation.
impl<T> MulAddAssign<Complex<T>, Complex<T>> for Complex<T> where
T: Clone + NumAssign + MulAddAssign<T, T>,
impl<T> MulAddAssign<Complex<T>, Complex<T>> for Complex<T> where
T: Clone + NumAssign + MulAddAssign<T, T>,
Performs the fused multiply-add operation.
Performs the *=
operation. Read more
Performs the *=
operation. Read more
Performs the *=
operation. Read more
Performs the *=
operation. Read more
pub fn from_str_radix(
s: &str,
radix: u32
) -> Result<Complex<T>, <Complex<T> as Num>::FromStrRadixErr>
pub fn from_str_radix(
s: &str,
radix: u32
) -> Result<Complex<T>, <Complex<T> as Num>::FromStrRadixErr>
Parses a +/- bi
; ai +/- b
; a
; or bi
where a
and b
are of type T
type FromStrRadixErr = ParseComplexError<<T as Num>::FromStrRadixErr>
Performs the %=
operation. Read more
Performs the %=
operation. Read more
Performs the %=
operation. Read more
Performs the %=
operation. Read more
pub fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,
pub fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,
Serialize this value into the given Serde serializer. Read more
Performs the -=
operation. Read more
Performs the -=
operation. Read more
Performs the -=
operation. Read more
Performs the -=
operation. Read more
Converts the value of self
to a usize
. If the value cannot be
represented by a usize
, then None
is returned. Read more
Converts the value of self
to an isize
. If the value cannot be
represented by an isize
, then None
is returned. Read more
Converts the value of self
to a u8
. If the value cannot be
represented by a u8
, then None
is returned. Read more
Converts the value of self
to a u16
. If the value cannot be
represented by a u16
, then None
is returned. Read more
Converts the value of self
to a u32
. If the value cannot be
represented by a u32
, then None
is returned. Read more
Converts the value of self
to a u64
. If the value cannot be
represented by a u64
, then None
is returned. Read more
Converts the value of self
to an i8
. If the value cannot be
represented by an i8
, then None
is returned. Read more
Converts the value of self
to an i16
. If the value cannot be
represented by an i16
, then None
is returned. Read more
Converts the value of self
to an i32
. If the value cannot be
represented by an i32
, then None
is returned. Read more
Converts the value of self
to an i64
. If the value cannot be
represented by an i64
, then None
is returned. Read more
Converts the value of self
to a u128
. If the value cannot be
represented by a u128
(u64
under the default implementation), then
None
is returned. Read more
Converts the value of self
to an i128
. If the value cannot be
represented by an i128
(i64
under the default implementation), then
None
is returned. Read more
Converts the value of self
to an f32
. Overflows may map to positive
or negative inifinity, otherwise None
is returned if the value cannot
be represented by an f32
. Read more
Auto Trait Implementations
impl<T> RefUnwindSafe for Complex<T> where
T: RefUnwindSafe,
impl<T> UnwindSafe for Complex<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more