complex: implement add/sub_assign directly

This commit is contained in:
Josh Stone 2017-07-12 13:59:30 -07:00
parent 055c6693b1
commit d57c0c2879
1 changed files with 4 additions and 2 deletions

View File

@ -527,13 +527,15 @@ mod opassign {
impl<T: Clone + NumAssign> AddAssign for Complex<T> { impl<T: Clone + NumAssign> AddAssign for Complex<T> {
fn add_assign(&mut self, other: Complex<T>) { fn add_assign(&mut self, other: Complex<T>) {
*self = self.clone() + other; self.re += other.re;
self.im += other.im;
} }
} }
impl<T: Clone + NumAssign> SubAssign for Complex<T> { impl<T: Clone + NumAssign> SubAssign for Complex<T> {
fn sub_assign(&mut self, other: Complex<T>) { fn sub_assign(&mut self, other: Complex<T>) {
*self = self.clone() - other; self.re -= other.re;
self.im -= other.im;
} }
} }