Skip to main content

Module complex

Module complex 

Source
Expand description

Complex numbers: a Complex<T> is re + im·i with parts of the Float type T, f32 or f64.

They add with + and +=, subtract with - and -=, multiply with * and *= and divide with / and /=, each operand owned or borrowed, and take a float of their own type as an operand on either side. They negate with -, compare with ==, add up with Sum and multiply with Product, and are written as 1+2i by Display.

Complex::abs and Complex::arg give the polar form, Complex::from_polar builds a number from it, and Complex::conj, Complex::norm_sqr and Complex::recip the rest of the arithmetic. Complex::exp, Complex::ln, Complex::sqrt, Complex::powi, Complex::powf and Complex::powc are the principal values, with the branch cut of the logarithm and the square root along the negative real axis, where the sign of a zero imaginary part picks the side, as in C99’s <complex.h>.

Structs§

Complex
The complex number re + im·i.

Traits§

Float
f32 or f64: the type of the parts of a Complex, and of the real numbers a matrix of either gives, such as its norms and singular values. The methods are those of the two types, for code generic over both. The trait is sealed.