#[allow(unused_imports)]
use super::functions::*;
use std::ops::{Add, Div, Mul, Neg, Sub};
use super::types::Complex;
impl Add for Complex {
type Output = Self;
fn add(self, rhs: Self) -> Self {
Self::new(self.re + rhs.re, self.im + rhs.im)
}
}
impl Sub for Complex {
type Output = Self;
fn sub(self, rhs: Self) -> Self {
Self::new(self.re - rhs.re, self.im - rhs.im)
}
}
impl Mul for Complex {
type Output = Self;
fn mul(self, rhs: Self) -> Self {
Self::new(
self.re * rhs.re - self.im * rhs.im,
self.re * rhs.im + self.im * rhs.re,
)
}
}
impl Div for Complex {
type Output = Self;
fn div(self, rhs: Self) -> Self {
let denom = rhs.norm_sq();
Self::new(
(self.re * rhs.re + self.im * rhs.im) / denom,
(self.im * rhs.re - self.re * rhs.im) / denom,
)
}
}
impl Neg for Complex {
type Output = Self;
fn neg(self) -> Self {
Self::new(-self.re, -self.im)
}
}