diff --git a/Cargo.toml b/Cargo.toml index 5132f3a..8ca4d6e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,11 +3,14 @@ name = "fft" version = "0.0.1" authors = ["Ivan Ukhov "] license = "MIT" -repository = "https://github.com/hilbert-space/fft" -homepage = "https://github.com/hilbert-space/fft" +repository = "https://github.com/stainless-steel/fft" +homepage = "https://github.com/stainless-steel/fft" description = """ The package provides an algorithm to compute the discrete Fourier transform and its inverse.""" +[dependencies] +complex = "*" + [dev-dependencies] assert = "*" diff --git a/src/complex.rs b/src/complex.rs deleted file mode 100644 index 1e07b21..0000000 --- a/src/complex.rs +++ /dev/null @@ -1,42 +0,0 @@ -use std::ops::{Add, Mul, Sub}; - -/// A complex number. -#[allow(non_camel_case_types)] -#[derive(Clone, Copy, Debug)] -pub struct c64(pub f64, pub f64); - -impl Add for c64 { - type Output = Self; - - #[inline(always)] - fn add(self, rhs: c64) -> c64 { - c64(self.0 + rhs.0, self.1 + rhs.1) - } -} - -impl Mul for c64 { - type Output = Self; - - #[inline(always)] - fn mul(self, rhs: c64) -> c64 { - c64(self.0 * rhs.0 - self.1 * rhs.1, self.0 * rhs.1 + self.1 * rhs.0) - } -} - -impl Mul for c64 { - type Output = Self; - - #[inline(always)] - fn mul(self, rhs: f64) -> c64 { - c64(self.0 * rhs, self.1 * rhs) - } -} - -impl Sub for c64 { - type Output = Self; - - #[inline(always)] - fn sub(self, rhs: c64) -> c64 { - c64(self.0 - rhs.0, self.1 - rhs.1) - } -} diff --git a/src/lib.rs b/src/lib.rs index 7f57964..3014118 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,16 @@ -use std::slice; +//! [Algorithm][1] to compute the [discrete Fourier transform][2] and its +//! inverse. +//! +//! [1]: https://en.wikipedia.org/wiki/Fast_Fourier_transform +//! [2]: https://en.wikipedia.org/wiki/Discrete_Fourier_transform + +// The implementation is based on: +// http://www.librow.com/articles/article-10 -mod complex; -pub use complex::c64; +extern crate complex; + +use complex::c64; +use std::slice; /// A means of obtaining a slice of mutable complex numbers. pub trait AsMutComplex<'l> { @@ -125,15 +134,3 @@ fn scale(data: &mut [c64], n: usize) { data[position] = data[position] * factor; } } - -#[cfg(test)] -mod tests { - use c64; - use std::mem; - - #[test] - fn size_of() { - assert_eq!(mem::size_of::(), 2 * mem::size_of::()); - assert_eq!(mem::size_of::<[c64; 42]>(), 2 * mem::size_of::<[f64; 42]>()); - } -}