pub struct Complex { /* private fields */ }Expand description
An exact complex number re + im·i, each part a Rational. Because the parts
are exact, i·i == −1 and (1+i)(1−i) == 2 hold with no floating error, and the
Gaussian rationals are closed under + − × ÷ (every nonzero value has an exact
inverse). The magnitude √(re²+im²) is irrational in general — request it as an
f64 view via Complex::abs_f64 rather than forcing the exact value inexact.
Complex numbers are NOT ordered, so there is deliberately no Ord/PartialOrd.
Implementations§
Source§impl Complex
impl Complex
pub fn new(re: Rational, im: Rational) -> Complex
Sourcepub fn from_rational(re: Rational) -> Complex
pub fn from_rational(re: Rational) -> Complex
A real number as re + 0i.
pub fn from_i64(x: i64) -> Complex
pub fn zero() -> Complex
pub fn one() -> Complex
pub fn re(&self) -> &Rational
pub fn im(&self) -> &Rational
pub fn is_zero(&self) -> bool
Sourcepub fn is_real(&self) -> bool
pub fn is_real(&self) -> bool
True when the imaginary part is zero (the value is a plain real).
Sourcepub fn norm_sqr(&self) -> Rational
pub fn norm_sqr(&self) -> Rational
re² + im² — the squared magnitude, exact (a nonnegative Rational).
Sourcepub fn abs_f64(&self) -> f64
pub fn abs_f64(&self) -> f64
The magnitude √(re²+im²) as an f64 (lossy by nature — the exact value is
generally irrational). The components stay exact; this is a view.
pub fn negated(&self) -> Complex
pub fn add(&self, other: &Complex) -> Complex
pub fn sub(&self, other: &Complex) -> Complex
Sourcepub fn recip(&self) -> Option<Complex>
pub fn recip(&self) -> Option<Complex>
1/self via the conjugate over the squared magnitude — None only for zero.