pub struct ComplexF64 {
pub re: f64,
pub im: f64,
}Expand description
A complex number with f64 real and imaginary parts.
Arithmetic follows the fixed-sequence protocol to prevent FMA drift.
Fields§
§re: f64§im: f64Implementations§
Source§impl ComplexF64
impl ComplexF64
Sourcepub const ZERO: ComplexF64
pub const ZERO: ComplexF64
Zero.
Sourcepub const ONE: ComplexF64
pub const ONE: ComplexF64
One.
Sourcepub const I: ComplexF64
pub const I: ComplexF64
Imaginary unit.
Sourcepub fn mul_fixed(self, rhs: Self) -> Self
pub fn mul_fixed(self, rhs: Self) -> Self
Fixed-Sequence Complex Multiplication.
Explicitly computes four multiplications and two additions in a deterministic order, preventing FMA contraction:
t1 = a.re * b.re
t2 = a.im * b.im
t3 = a.re * b.im
t4 = a.im * b.re
result.re = t1 - t2
result.im = t3 + t4§FMA Prevention
By storing intermediates in local variables and computing each step explicitly, we prevent LLVM from fusing operations into FMA instructions, which would cause different rounding on platforms with/without hardware FMA support.
Sourcepub fn div_fixed(self, rhs: Self) -> Self
pub fn div_fixed(self, rhs: Self) -> Self
Fixed-Sequence Complex Division.
Computes (a+bi) / (c+di) using a fixed sequence:
denom = c*c + d*d (two muls, one add — ordered)
re = (a*c + b*d) / denom (two muls, one add, one div)
im = (b*c - a*d) / denom (two muls, one sub, one div)Division by zero (0+0i) produces NaN/Inf stably (no panic).
Trait Implementations§
Source§impl Clone for ComplexF64
impl Clone for ComplexF64
Source§fn clone(&self) -> ComplexF64
fn clone(&self) -> ComplexF64
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ComplexF64
impl Debug for ComplexF64
Source§impl Display for ComplexF64
impl Display for ComplexF64
Source§impl PartialEq for ComplexF64
impl PartialEq for ComplexF64
impl Copy for ComplexF64
impl StructuralPartialEq for ComplexF64
Auto Trait Implementations§
impl Freeze for ComplexF64
impl RefUnwindSafe for ComplexF64
impl Send for ComplexF64
impl Sync for ComplexF64
impl Unpin for ComplexF64
impl UnsafeUnpin for ComplexF64
impl UnwindSafe for ComplexF64
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more