Crate complex_algebra

Source
Expand description

§complex_algebra

This crate intends to support complex numbers and its standard algebraic operations. To construct a complex number with real part u and imaginary part v you can do

use complex_algebra::c;
let u = 2.0;
let v = 3.0;
let z = c(u, v);

u, v can be any types like i32, u32, f64, … that implement at the very minimum the traits Copy and PartialEq.

Depending on the chosen type and its support for various algebraic operators, the following binary and unary functions are implemented:

z1 + z2

z1 - z2

z1 * z2

z1 / z2

-z

Moreover, all these binary operations do work when the r.h.s is being replaced with a ‘real’ number.

§Example:

use complex_algebra::c;
let z1 = c(2, 3);
let z2 = c(1, 1);

assert_eq!(&z1 + &z2, c(3, 4));
assert_eq!(z1 * 2, c(4, 6));

Macros§

cos_macro
cosh_macro
exp_macro
pow_macro
pow_macro_single_non_neg
pow_non_neg_macro
sin_macro
sinh_macro

Structs§

c

Traits§

Cos
Cosh
Exp
Pow
Sin
Sinh

Functions§

re
Takes a real and transforms it to a number of type c. Corresponds to the embedding of a real number into a complex.