â„–18929204[Quote]
poop
â„–18929221[Quote]
macro_rules! define_complex {
() => {
#[derive(Clone, Copy, Debug)]
struct Complex<T> {
/// Real portion of the complex number
re: T,
/// Imaginary portion of the complex number
im: T,
}
};
}
mod first_cut {
#[derive(Clone, Copy, Debug)]
struct Complex<T> {
/// Real portion of the complex number
re: T,
/// Imaginary portion of the complex number
im: T,
}
use stdopsAdd;
impl<T> Add for Complex<T>
where
T: Add<Output = T>,
{
type Output = Self;
fn add(self, rhs: Self) -> Self {
Complex {
re: self.re + rhs.re,
im: self.im + rhs.im,
}
}
}
use stdopsSub;
impl<T> Sub for Complex<T>
where
T: Sub<Output = T>,
{
type Output = Self;
fn sub(self, rhs: Self) -> Self {
Complex {
re: self.re - rhs.re,
im: self.im - rhs.im,
}
}
}
use stdopsMul;
impl<T> Mul for Complex<T>
where
T: Clone + Add<Output = T> + Sub<Output = T> + Mul<Output = T>,
{
type Output = Self;
fn mul(self, rhs: Self) -> Self {
Complex {
re: self.re.clone() * rhs.re.clone()
- (self.im.clone() * rhs.im.clone()),
im: self.im * rhs.re + self.re * rhs.im,
}
}
}