#[repr(C)]pub struct Complex<T> {
pub re: T,
pub im: T,
}Expand description
The complex number re + im·i.
§Examples
use a::math::complex::Complex;
let z = Complex::new(3.0, 4.0);
assert_eq!(z.abs(), 5.0);
assert_eq!(z * z.conj(), Complex::new(25.0, 0.0));
assert_eq!(Complex::new(-4.0, 0.0).sqrt(), Complex::new(0.0, 2.0));
assert_eq!(format!("{}", z - 2.0 * Complex::I), "3+2i");Fields§
§re: TThe real part.
im: TThe imaginary part.
Implementations§
Source§impl<T: Float> Complex<T>
impl<T: Float> Complex<T>
Sourcepub fn from_polar(r: T, theta: T) -> Self
pub fn from_polar(r: T, theta: T) -> Self
The number with the absolute value r and the argument theta: r·e^(i·theta).
Sourcepub fn abs(self) -> T
pub fn abs(self) -> T
The absolute value √(re² + im²), without an overflow or underflow in the squares.
Sourcepub fn norm_sqr(self) -> T
pub fn norm_sqr(self) -> T
The square of the absolute value, re² + im²: cheaper than abs, but it overflows and
underflows where the squares do.
Sourcepub fn arg(self) -> T
pub fn arg(self) -> T
The argument, the angle from the positive real axis, in (-π, π]; -π for a negative
real number with a negative zero imaginary part.
Sourcepub fn exp(self) -> Self
pub fn exp(self) -> Self
e^self: e^re·(cos im + i·sin im). A real number stays real, with the sign of its zero
imaginary part.
Sourcepub fn ln(self) -> Self
pub fn ln(self) -> Self
The principal natural logarithm, ln |self| + i·arg(self), whose imaginary part is in
(-π, π]. The logarithm of zero is -∞. Near the unit circle the real part is
ln(1 + (|self|² - 1)) / 2, so that it keeps its digits where ln |self| is small; where
|self| overflows, or is subnormal, it is ln(big) + ln(1 + (small/big)²) / 2 of the
larger and the smaller part, so that ln(MAX + MAX·i) is finite.
Sourcepub fn sqrt(self) -> Self
pub fn sqrt(self) -> Self
The principal square root, whose real part is not negative, by Kahan’s method, which
neither overflows nor cancels: for re ≥ 0, t = √((re + |self|) / 2) and the root
t + i·im / (2t), and the other way round for re < 0. Infinities and NaNs give what
C99’s csqrt gives.
Sourcepub fn powi(self, n: i32) -> Self
pub fn powi(self, n: i32) -> Self
self to the integer power n, by repeated squaring: exact as long as the products are.
A negative power is the power of the reciprocal, and 0^0 is 1.
Trait Implementations§
Source§impl<T: Float> AddAssign for Complex<T>
impl<T: Float> AddAssign for Complex<T>
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreSource§impl<T: Float> AddAssign<&Complex<T>> for Complex<T>
impl<T: Float> AddAssign<&Complex<T>> for Complex<T>
Source§fn add_assign(&mut self, rhs: &Self)
fn add_assign(&mut self, rhs: &Self)
+= operation. Read moreSource§impl<T: Float> AddAssign<&T> for Complex<T>
impl<T: Float> AddAssign<&T> for Complex<T>
Source§fn add_assign(&mut self, rhs: &T)
fn add_assign(&mut self, rhs: &T)
+= operation. Read moreSource§impl<T: Float> AddAssign<T> for Complex<T>
impl<T: Float> AddAssign<T> for Complex<T>
Source§fn add_assign(&mut self, rhs: T)
fn add_assign(&mut self, rhs: T)
+= operation. Read moreimpl<T: Copy> Copy for Complex<T>
Source§impl<T: Float> DivAssign for Complex<T>
impl<T: Float> DivAssign for Complex<T>
Source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
/= operation. Read moreSource§impl<T: Float> DivAssign<&Complex<T>> for Complex<T>
impl<T: Float> DivAssign<&Complex<T>> for Complex<T>
Source§fn div_assign(&mut self, rhs: &Self)
fn div_assign(&mut self, rhs: &Self)
/= operation. Read moreSource§impl<T: Float> DivAssign<&T> for Complex<T>
impl<T: Float> DivAssign<&T> for Complex<T>
Source§fn div_assign(&mut self, rhs: &T)
fn div_assign(&mut self, rhs: &T)
/= operation. Read moreSource§impl<T: Float> DivAssign<T> for Complex<T>
impl<T: Float> DivAssign<T> for Complex<T>
Source§fn div_assign(&mut self, rhs: T)
fn div_assign(&mut self, rhs: T)
/= operation. Read moreimpl Element for Complex<f32>
impl Element for Complex<f64>
Source§impl<T: Float> MulAssign for Complex<T>
impl<T: Float> MulAssign for Complex<T>
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*= operation. Read moreSource§impl<T: Float> MulAssign<&Complex<T>> for Complex<T>
impl<T: Float> MulAssign<&Complex<T>> for Complex<T>
Source§fn mul_assign(&mut self, rhs: &Self)
fn mul_assign(&mut self, rhs: &Self)
*= operation. Read moreSource§impl<T: Float> MulAssign<&T> for Complex<T>
impl<T: Float> MulAssign<&T> for Complex<T>
Source§fn mul_assign(&mut self, rhs: &T)
fn mul_assign(&mut self, rhs: &T)
*= operation. Read moreSource§impl<T: Float> MulAssign<T> for Complex<T>
impl<T: Float> MulAssign<T> for Complex<T>
Source§fn mul_assign(&mut self, rhs: T)
fn mul_assign(&mut self, rhs: T)
*= operation. Read moreimpl<T: PartialEq> StructuralPartialEq for Complex<T>
Source§impl<T: Float> SubAssign for Complex<T>
impl<T: Float> SubAssign for Complex<T>
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-= operation. Read moreSource§impl<T: Float> SubAssign<&Complex<T>> for Complex<T>
impl<T: Float> SubAssign<&Complex<T>> for Complex<T>
Source§fn sub_assign(&mut self, rhs: &Self)
fn sub_assign(&mut self, rhs: &Self)
-= operation. Read moreSource§impl<T: Float> SubAssign<&T> for Complex<T>
impl<T: Float> SubAssign<&T> for Complex<T>
Source§fn sub_assign(&mut self, rhs: &T)
fn sub_assign(&mut self, rhs: &T)
-= operation. Read moreSource§impl<T: Float> SubAssign<T> for Complex<T>
impl<T: Float> SubAssign<T> for Complex<T>
Source§fn sub_assign(&mut self, rhs: T)
fn sub_assign(&mut self, rhs: T)
-= operation. Read more