complex/cossin: decouple modules
This commit is contained in:
parent
2d43b8970b
commit
0fd4b167b4
@ -1,7 +1,6 @@
|
|||||||
use super::{atan2, cossin};
|
use super::{atan2, cossin};
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Default, PartialEq, Debug, Deserialize, Serialize)]
|
#[derive(Copy, Clone, Default, PartialEq, Debug)]
|
||||||
pub struct Complex<T>(pub T, pub T);
|
pub struct Complex<T>(pub T, pub T);
|
||||||
|
|
||||||
impl Complex<i32> {
|
impl Complex<i32> {
|
||||||
@ -17,7 +16,8 @@ impl Complex<i32> {
|
|||||||
/// ```
|
/// ```
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn from_angle(angle: i32) -> Complex<i32> {
|
pub fn from_angle(angle: i32) -> Complex<i32> {
|
||||||
cossin(angle)
|
let (c, s) = cossin(angle);
|
||||||
|
Complex(c, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the absolute square (the squared magnitude).
|
/// Return the absolute square (the squared magnitude).
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
use super::Complex;
|
|
||||||
use core::f64::consts::PI;
|
use core::f64::consts::PI;
|
||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/cossin_table.rs"));
|
include!(concat!(env!("OUT_DIR"), "/cossin_table.rs"));
|
||||||
@ -11,10 +10,10 @@ include!(concat!(env!("OUT_DIR"), "/cossin_table.rs"));
|
|||||||
/// * `phase` - 32-bit phase.
|
/// * `phase` - 32-bit phase.
|
||||||
///
|
///
|
||||||
/// # Returns
|
/// # Returns
|
||||||
/// The cos and sin values of the provided phase as a `Complex<i32>`
|
/// The cos and sin values of the provided phase as a `(i32, i32)`
|
||||||
/// value. With a 7-bit deep LUT there is 1e-5 max and 6e-8 RMS error
|
/// tuple. With a 7-bit deep LUT there is 1e-5 max and 6e-8 RMS error
|
||||||
/// in each quadrature over 20 bit phase.
|
/// in each quadrature over 20 bit phase.
|
||||||
pub fn cossin(phase: i32) -> Complex<i32> {
|
pub fn cossin(phase: i32) -> (i32, i32) {
|
||||||
// Phase bits excluding the three highes MSB
|
// Phase bits excluding the three highes MSB
|
||||||
const OCTANT_BITS: usize = 32 - 3;
|
const OCTANT_BITS: usize = 32 - 3;
|
||||||
|
|
||||||
@ -69,12 +68,13 @@ pub fn cossin(phase: i32) -> Complex<i32> {
|
|||||||
sin *= -1;
|
sin *= -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Complex(cos, sin)
|
(cos, sin)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::Complex;
|
||||||
use core::f64::consts::PI;
|
use core::f64::consts::PI;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
Reference in New Issue
Block a user