From 713b68adef9a7c8dbce04d820d6e86f2d68b2d30 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Fri, 23 Aug 2024 13:00:22 -0700 Subject: [PATCH] Initial commit --- .gitignore | 1 + Cargo.lock | 77 ++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 8 +++++ fixed_wide/Cargo.lock | 69 +++++++++++++++++++++++++++++++++++++ fixed_wide/Cargo.toml | 8 +++++ fixed_wide/src/lib.rs | 1 + fixed_wide/src/wide.rs | 4 +++ src/lib.rs | 37 ++++++++++++++++++++ 8 files changed, 205 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 fixed_wide/Cargo.lock create mode 100644 fixed_wide/Cargo.toml create mode 100644 fixed_wide/src/lib.rs create mode 100644 fixed_wide/src/wide.rs create mode 100644 src/lib.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..b0d4fcb --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,77 @@ +# This file is automatically @generated by Cargo. +# 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.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fd4c6dcc3b0aea2f5c0b4b82c2b15fe39ddbc76041a310848f4706edf76bb31" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[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_linear_algebra" +version = "0.1.0" +dependencies = [ + "fixed", + "fixed_wide", +] + +[[package]] +name = "fixed_wide" +version = "0.1.0" +dependencies = [ + "bnum", + "fixed", +] + +[[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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..b9efe84 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "fixed_linear_algebra" +version = "0.1.0" +edition = "2021" + +[dependencies] +fixed = "1.28.0" +fixed_wide = { version = "0.1.0", path = "fixed_wide" } diff --git a/fixed_wide/Cargo.lock b/fixed_wide/Cargo.lock new file mode 100644 index 0000000..6e5c37e --- /dev/null +++ b/fixed_wide/Cargo.lock @@ -0,0 +1,69 @@ +# This file is automatically @generated by Cargo. +# 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.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fd4c6dcc3b0aea2f5c0b4b82c2b15fe39ddbc76041a310848f4706edf76bb31" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[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", + "fixed", +] + +[[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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" diff --git a/fixed_wide/Cargo.toml b/fixed_wide/Cargo.toml new file mode 100644 index 0000000..89be919 --- /dev/null +++ b/fixed_wide/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "fixed_wide" +version = "0.1.0" +edition = "2021" + +[dependencies] +bnum = "0.11.0" +fixed = "1.28.0" diff --git a/fixed_wide/src/lib.rs b/fixed_wide/src/lib.rs new file mode 100644 index 0000000..4472d7e --- /dev/null +++ b/fixed_wide/src/lib.rs @@ -0,0 +1 @@ +pub mod wide; diff --git a/fixed_wide/src/wide.rs b/fixed_wide/src/wide.rs new file mode 100644 index 0000000..98ab750 --- /dev/null +++ b/fixed_wide/src/wide.rs @@ -0,0 +1,4 @@ +pub struct Fixed{ + bits:I, + phantom:std::marker::PhantomData, +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..d1507fe --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,37 @@ +use bnum::cast::As; + +type Planar64=fixed::types::I32F32; +type Planar64Wide1=fixed::types::I64F64; +type Planar64Wide2=bnum::types::I256; +type Planar64Wide3=bnum::types::I512; +//wouldn't that be nice +//type Planar64Wide2=fixed::FixedI256; +//type Planar64Wide3=fixed::FixedI512; + +pub fn wide_mul(left: Planar64, right: Planar64) -> Planar64Wide1 { + left.wide_mul(right) +} +pub fn wide_mul_2(left: Planar64Wide1, right: Planar64Wide1) -> Planar64Wide2 { + Planar64Wide2::from(left.to_bits())*Planar64Wide2::from(right.to_bits()) +} +pub fn wide_mul_3(left: Planar64Wide2, right: Planar64Wide2) -> Planar64Wide3 { + left.as_::()*right.as_::() +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() { + let result = add(2.into(), 2.into()); + assert_eq!(result, 4); + } + + #[test] + pub fn main(){ + let a=6f128; + let max=i32::MAX as i64; + println!("{} {}",max*max,i64::MAX); + } +}