Skip to main content

Module complex

Module complex 

Source
Expand description

Complex BLAS — ComplexF64 with Fixed-Sequence Arithmetic.

§Design

Complex multiplication is lowered to a fixed-sequence of four multiplications and two additions, explicitly ordered to prevent cross-architecture FMA drift. This ensures bit-parity between x86 and ARM platforms.

Complex reductions (dot products, sums) feed real and imaginary parts separately into BinnedAccumulators for deterministic results.

§Fixed-Sequence Complex Multiply

(a + bi)(c + di) = (ac - bd) + (ad + bc)i

The four multiplications are computed first, then the two additions:

t1 = a * c   (mul #1)
t2 = b * d   (mul #2)
t3 = a * d   (mul #3)
t4 = b * c   (mul #4)
re = t1 - t2 (sub #1)
im = t3 + t4 (add #1)

This explicit ordering prevents the compiler from fusing a*c - b*d into an FMA (which would change the rounding behavior).

Structs§

ComplexF64
A complex number with f64 real and imaginary parts.

Functions§

complex_dot
Complex dot product using BinnedAccumulator for deterministic results.
complex_matmul
Complex matrix multiply: C[m,n] = A[m,k] × B[k,n] (fixed-sequence).
complex_sum
Complex sum using BinnedAccumulator for deterministic results.