diff --git a/fixed_wide/Cargo.lock b/fixed_wide/Cargo.lock index c65cd17..e51beec 100644 --- a/fixed_wide/Cargo.lock +++ b/fixed_wide/Cargo.lock @@ -2,17 +2,63 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "az" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b7e4c2464d97fe331d41de9d5db0def0a96f4d823b8b32a2efd503578988973" + [[package]] name = "bnum" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e31ea183f6ee62ac8b8a8cf7feddd766317adfb13ff469de57ce033efd6a790" +[[package]] +name = "bytemuck" +version = "1.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773d90827bc3feecfb67fab12e24de0749aad83c74b9504ecde46237b5cd24e2" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cordic" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ed0a176c0b8c5c95fa0523177530364c5b68a8895d9745730dbfa692a7412d0" +dependencies = [ + "fixed", +] + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "fixed" +version = "1.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85c6e0b89bf864acd20590dbdbad56f69aeb898abfc9443008fd7bd48b2cc85a" +dependencies = [ + "az", + "bytemuck", + "half", + "typenum", +] + [[package]] name = "fixed_wide" version = "0.1.0" dependencies = [ "bnum", + "cordic", "fixed_wide_traits", "typenum", ] @@ -21,6 +67,16 @@ dependencies = [ name = "fixed_wide_traits" version = "0.1.0" +[[package]] +name = "half" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888" +dependencies = [ + "cfg-if", + "crunchy", +] + [[package]] name = "typenum" version = "1.17.0" diff --git a/fixed_wide/Cargo.toml b/fixed_wide/Cargo.toml index 84206fd..9e81dd2 100644 --- a/fixed_wide/Cargo.toml +++ b/fixed_wide/Cargo.toml @@ -6,8 +6,10 @@ edition = "2021" [features] default=["fixed_wide_traits"] fixed_wide_traits=["dep:fixed_wide_traits"] +cordic=["dep:cordic"] [dependencies] bnum = "0.11.0" typenum = "1.17.0" fixed_wide_traits = { version = "0.1.0", path = "../fixed_wide_traits", optional = true } +cordic = { version = "0.1.5", optional = true } diff --git a/fixed_wide/src/cordic.rs b/fixed_wide/src/cordic.rs new file mode 100644 index 0000000..80745da --- /dev/null +++ b/fixed_wide/src/cordic.rs @@ -0,0 +1,33 @@ +use bnum::BInt; +use typenum::Unsigned; +use crate::fixed::Fixed; +use std::marker::PhantomData; + +impl cordic::CordicNumber for Fixed{ + fn floor(self)->Self{ + Self{ + bits:self.bits.bitand(BInt::::ONE.shl(Frac::U32).sub(BInt::::ONE).not()), + frac:PhantomData, + } + } + + fn zero()->Self{ + Self::ZERO + } + + fn one()->Self{ + Self::ONE + } + + fn from_u0f64(val:U0F64)->Self{ + val + } + + fn num_fract_bits()->u8{ + Frac::U8 + } + + fn num_bits()->u8{ + CHUNKS as u8*64 + } +} diff --git a/fixed_wide/src/lib.rs b/fixed_wide/src/lib.rs index 4d35f29..8176867 100644 --- a/fixed_wide/src/lib.rs +++ b/fixed_wide/src/lib.rs @@ -9,3 +9,6 @@ pub mod typenum{ mod fixed_wide_traits; #[cfg(feature="fixed_wide_traits")] pub use ::fixed_wide_traits::wide; + +#[cfg(feature="cordic")] +mod cordic;