pub struct Cordic32 { /* private fields */ }Expand description
A 32-bit CORDIC rotator: u32 binary angles (2^32 per turn) and i32 Q1.30 results.
Accurate to about 1e-8 (a dozen least-significant bits) at 30 iterations.
Implementations§
Source§impl Cordic32
impl Cordic32
Sourcepub const FRACTIONAL_BITS: u32 = 30
pub const FRACTIONAL_BITS: u32 = 30
Number of fractional bits in the signed results.
Sourcepub const MAX_ITERATIONS: u32 = 30
pub const MAX_ITERATIONS: u32 = 30
The maximum number of micro-rotations.
Sourcepub const DEFAULT_ITERATIONS: u32 = 30
pub const DEFAULT_ITERATIONS: u32 = 30
A good default iteration count (about the accuracy floor of the word size).
Sourcepub fn new(iterations: u32) -> Result<Cordic32, ErrorsJSL>
pub fn new(iterations: u32) -> Result<Cordic32, ErrorsJSL>
Creates a rotator with iterations micro-rotations (1 to Self::MAX_ITERATIONS).
pub fn iterations(&self) -> u32
Sourcepub fn gain(&self) -> f64
pub fn gain(&self) -> f64
The gain K = Π sqrt(1 + 2^-2i) that the micro-rotations add (about 1.6468), which
the rotator compensates for by starting from 1/K.
Sourcepub fn sin_cos_fixed(&self, angle: u32) -> (i32, i32)
pub fn sin_cos_fixed(&self, angle: u32) -> (i32, i32)
Returns (sin, cos) of a binary angle as signed fixed-point values with
Self::FRACTIONAL_BITS fractional bits, using integer arithmetic only.
Sourcepub fn sin_cos(&self, radians: f64) -> (f64, f64)
pub fn sin_cos(&self, radians: f64) -> (f64, f64)
Floating-point convenience: (sin, cos) of an angle in radians (any real value).
The angle is first quantized to a binary angle.
Sourcepub fn angle_from_turns(turns: f64) -> u32
pub fn angle_from_turns(turns: f64) -> u32
Converts an angle in turns to a binary angle (modulo one turn).
Sourcepub fn angle_from_radians(radians: f64) -> u32
pub fn angle_from_radians(radians: f64) -> u32
Converts an angle in radians to a binary angle (modulo one turn).
Sourcepub fn angle_to_radians(angle: u32) -> f64
pub fn angle_to_radians(angle: u32) -> f64
Converts a binary angle to radians in [0, 2*pi).