#complex-numbers #algebra #operations #real-number #supporting

complex_algebra

A crate supporting complex number algebra

9 releases

0.1.8 Oct 14, 2022
0.1.7 Oct 14, 2022
0.1.3 Mar 28, 2022

#1063 in Math

MIT license

16KB
528 lines

complex-algebra

This repository contains the source code for the Rust crate 'complex_algebra'.

Detailed documentation can be found here:

https://docs.rs/complex_algebra/0.1.2/complex_algebra/


lib.rs:

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));

No runtime deps