use mathverse_complex::{Complex, C32};
fn main() {
let z = Complex::new(3.0, 4.0);
let w = Complex::polar(2.0, std::f64::consts::FRAC_PI_2); println!("z = {z}, |z| = {}, arg(z) = {}", z.norm(), z.arg());
println!("w = {w}, conj(w) = {}", w.conjugate());
let sum = z + w;
let prod = z * w;
let quot = z / w;
println!("z + w = {sum}");
println!("z * w = {prod}");
println!("z / w = {quot}");
let roundtrip = z.ln().exp();
println!("exp(ln z) = {roundtrip} (should be ≈ {z})");
assert!((roundtrip - z).norm() < 1e-12);
let s = z.sqrt();
println!("sqrt(z) = {s}, and s² = {}", s * s);
println!("z^3 = {}", z.pow(Complex::real(3.0)));
let z32: C32 = Complex::new(1.0f32, -1.0);
println!("f32: |{z32}| = {}, arg = {} rad", z32.norm(), z32.arg());
println!("phase(z) = {} (same as arg)", z.phase());
let (r, theta) = z.to_polar();
println!(
"polar(z) = ({r}, {theta}); rect back = {}",
Complex::rect(r, theta)
);
assert!(z.is_close(&Complex::rect(r, theta), 1e-12, 1e-12));
}