Skip to content

Commit

Permalink
Merge pull request serde-rs#77 from andersk/complex-neg
Browse files Browse the repository at this point in the history
Require Neg for Complex conj and inv
  • Loading branch information
alexcrichton committed Apr 3, 2015
2 parents 24b7793 + 7fb887b commit 80b6f92
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/complex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,21 @@ impl<T: Clone + Num> Complex<T> {
pub fn unscale(&self, t: T) -> Complex<T> {
Complex::new(self.re.clone() / t.clone(), self.im.clone() / t)
}
}

impl<T: Clone + Num + Neg<Output = T>> Complex<T> {
/// Returns the complex conjugate. i.e. `re - i im`
#[inline]
pub fn conj(&self) -> Complex<T> {
Complex::new(self.re.clone(), T::zero() - self.im.clone())
Complex::new(self.re.clone(), -self.im.clone())
}

/// Returns `1/self`
#[inline]
pub fn inv(&self) -> Complex<T> {
let norm_sqr = self.norm_sqr();
Complex::new(self.re.clone() / norm_sqr.clone(),
T::zero() - self.im.clone() / norm_sqr)
-self.im.clone() / norm_sqr)
}
}

Expand Down

0 comments on commit 80b6f92

Please sign in to comment.