//! FFT and RDFT implementation.
use std::f32::{self, consts};
-use std::ops::{Not, Neg, Add, AddAssign, Sub, SubAssign, Mul, MulAssign};
+use std::ops::{Not, Neg, Add, AddAssign, Sub, SubAssign, Mul, MulAssign, Div};
use std::fmt;
/// Complex number.
pub fn scale(self, scale: f32) -> Self {
FFTComplex { re: self.re * scale, im: self.im * scale }
}
+ /// Returns squared modulus value of the complex number.
+ pub fn sq_modulus(self) -> f32 {
+ self.re * self.re + self.im * self.im
+ }
+ /// Returns reciprocal of the complex number.
+ pub fn reciprocal(self) -> Self {
+ !self.scale(self.sq_modulus())
+ }
}
impl Neg for FFTComplex {
}
}
+impl Div for FFTComplex {
+ type Output = FFTComplex;
+ fn div(self, other: Self) -> Self::Output {
+ self * other.reciprocal()
+ }
+}
+
impl fmt::Display for FFTComplex {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "({}, {})", self.re, self.im)