diff --git a/Cargo.toml b/Cargo.toml index ea2cb64..9f1de5f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,8 +9,8 @@ license = "MIT OR Apache-2.0" repository = "https://github.com/quartiq/idsp.git" [workspace.dependencies] -dsp-process = { path = "dsp-process" } -dsp-fixedpoint = { path = "dsp-fixedpoint" } +dsp-process = { version = "0.1.0", path = "dsp-process" } +dsp-fixedpoint = { version = "0.1.0", path = "dsp-fixedpoint" } num-traits = { version = "0.2.14", features = [ "libm", ], default-features = false } @@ -23,7 +23,7 @@ missing_docs = "warn" [package] name = "idsp" -version = "0.19.0" +version = "0.20.0" edition.workspace = true authors.workspace = true license.workspace = true diff --git a/dsp-fixedpoint/Cargo.toml b/dsp-fixedpoint/Cargo.toml index 9d3c28d..3197a62 100644 --- a/dsp-fixedpoint/Cargo.toml +++ b/dsp-fixedpoint/Cargo.toml @@ -1,5 +1,6 @@ [package] name = "dsp-fixedpoint" +description = "Fixed point types for DSP" version = "0.1.0" edition.workspace = true authors.workspace = true diff --git a/dsp-fixedpoint/src/lib.rs b/dsp-fixedpoint/src/lib.rs index 6849346..6035694 100644 --- a/dsp-fixedpoint/src/lib.rs +++ b/dsp-fixedpoint/src/lib.rs @@ -224,6 +224,11 @@ impl Q { } /// Scale from integer base type + /// + /// ``` + /// # use dsp_fixedpoint::Q8; + /// assert_eq!(Q8::<4>::from_int(7).inner, 7 << 4); + /// ``` #[inline] pub fn from_int(value: T) -> Self { Self::new(value.shs(F)) @@ -232,6 +237,13 @@ impl Q { impl, const F: i8> Q { /// Scale from integer accu type + /// + /// + /// ``` + /// # use dsp_fixedpoint::Q8; + /// let q = Q8::<4>::from_f32(0.25); + /// assert_eq!((q * 7).quantize(), (7.0 * 0.25f32).floor() as _); + /// ``` #[inline] pub fn quantize(self) -> T { T::down(self.trunc()) @@ -239,6 +251,11 @@ impl, const F: i8> Q { } /// Lossy conversion from a dynamically scaled integer +/// +/// ``` +/// # use dsp_fixedpoint::Q8; +/// assert_eq!(Q8::<8>::from((1, 3)).inner, 1 << 5); +/// ``` impl + Shift, A, const F: i8> From<(T, i8)> for Q { fn from(value: (T, i8)) -> Self { Self::new(value.0.shs(F - value.1)) @@ -246,15 +263,22 @@ impl + Shift, A, const F: i8> From<(T, i8)> for Q { } /// Lossless conversion into a dynamically scaled integer +/// +/// ``` +/// # use dsp_fixedpoint::Q8; +/// let q: (i8, i8) = Q8::<8>::new(9).into(); +/// assert_eq!(q, (9, 8)); +/// ``` impl From> for (T, i8) { fn from(value: Q) -> Self { (value.inner, F) } } +/// Lossy conversion to and from float +/// /// ``` /// # use dsp_fixedpoint::Q8; -/// # use num_traits::AsPrimitive; /// assert_eq!(8 * Q8::<4>::from_f32(0.25), 2); /// assert_eq!(8 * Q8::<4>::from_f64(0.25), 2); /// assert_eq!(Q8::<4>::new(4).as_f32(), 0.25); @@ -269,7 +293,7 @@ macro_rules! impl_as_float { #[inline] fn as_(self) -> Q { Q::new( - (self * const { 1.0 / Q::::DELTA } as $ty) + (self * const { 1.0 / Q::::DELTA as $ty }) .round() .as_(), ) @@ -562,13 +586,6 @@ impl iter::Sum for Q { } } -impl iter::Product for Q { - #[inline] - fn product>(iter: I) -> Self { - Self::new(iter.map(|i| i.inner).product()) - } -} - /// ``` /// # use dsp_fixedpoint::Q8; /// let q = Q8::<4>::new(7); @@ -635,7 +652,7 @@ macro_rules! impl_q { } } - #[doc = concat!("Fixed point [`", stringify!($t), "`]")] + #[doc = concat!("Fixed point [`", stringify!($t), "`] with [`", stringify!($a), "`] accumulator")] pub type $alias = Q<$t, $a, F>; impl ConstOne for Q<$t, $a, F> {