1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//! # 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));
//!
//! ```
pub use *;
use Sub;
/// Takes a real and transforms it to a number of type `c`.
/// Corresponds to the embedding of a real number into a complex.
///
/// ```
/// use complex_algebra::{c, re};
/// assert_eq!(re(3), c(3, 0))
/// ```