update
| -rw-r--r-- | Cargo.lock | 24 | ||||
| -rw-r--r-- | Cargo.toml | 8 | ||||
| -rw-r--r-- | README.md | 3 | ||||
| -rw-r--r-- | src/lib.rs | 28 |
4 files changed, 42 insertions, 21 deletions
@@ -1,19 +1,19 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "lower" -version = "0.2.0" +version = "0.2.1" dependencies = [ "lower-macros", ] [[package]] name = "lower-macros" -version = "0.2.0" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0b43ed50f1f56bf1dedc1c8977b61394c9a970db3707c8b8b8ff81ac1b46d83" +checksum = "a2996a18b899178abb5e49750d670a908ffb67b13f15b95e4fc5c40a1dffbd76" dependencies = [ "proc-macro2", "quote", @@ -22,27 +22,27 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.93" +version = "1.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99" +checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.38" +version = "1.0.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" +checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f" dependencies = [ "proc-macro2", ] [[package]] name = "syn" -version = "2.0.98" +version = "2.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36147f1a48ae0ec2b5b3bc5b537d267457555a10dc06f3dbc8cb11ba3006d3b1" +checksum = "2f17c7e013e88258aa9543dcbe81aca68a667a9ac37cd69c9fbc07858bfe0e2f" dependencies = [ "proc-macro2", "quote", @@ -51,6 +51,6 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.16" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a210d160f08b701c8721ba1c726c11662f877ea6b7094007e1ca9a1041945034" +checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" @@ -1,13 +1,13 @@ [package] name = "lower" -version = "0.2.0" +version = "0.2.1" authors = ["bend-n <[email protected]>"] description = "desugar math where the compiler wont" -edition = "2021" +edition = "2024" repository = "https://github.com/bend-n/lower-plus.git" license = "MIT" -keywrords = ["fast", "math", "float"] +keywords = ["fast", "math", "float"] categories = ["hardware-support", "mathematics"] [dependencies] -lower-macros = "0.2" +lower-macros = "0.2.10" @@ -27,6 +27,7 @@ fn main() -> u8 { it should work for most expressions. also implements some modules that let it work with some core intrinsics (`f*_fast`, `f*_algebraic`). (nightly only!) +and also for `saturating` math and `wrapping` math. ## why @@ -54,3 +55,5 @@ fn madd<const N: usize>(x: [[f32; 3]; N]) -> [f32; N] { lower::algebraic! { x.map(|[a, b, c]| a * b + c) } } ``` + +this is also great for wrapping/saturating math. @@ -1,8 +1,9 @@ //! a lil macro crate. //! -//! provides a handy macro for converting `a + b` to `a.add(b)` for when you cant easily overload the `Add` trait, -//! and some traits that provide [`f*_algebraic`](algebraic::math) and [`f*_fast`](fast::math) implementations. (requires nightly) -/// Provides the algebraic math trait and macro. +//! provides a handy macro for converting `a + b` to `a.add(b)` for when you cant easily overload the [`Add`](core::ops::Add) trait, +//! and some macros that provide [`f*_algebraic`](algebraic::math) (requires nightly), [`f*_fast`](fast::math) (requires nightly), [`saturating_*`](u8::saturating_add), and [`wrapping_*`](u8::wrapping_sub) implementations. +#![no_std] +/// Provides the algebraic math macro. pub mod algebraic { /// Changes all the math to algebraic float math. See [`fadd_algebraic`](core::intrinsics::fadd_algebraic). /// @@ -11,7 +12,8 @@ pub mod algebraic { /// This would lower `a + b + c + d` to `alge_add(alge_add(alge_add(a, b), c), d)` (which could be organized by the compiler into `(a + b) + (c + d)` if it chooses) pub use lower_macros::algebraic as math; } -/// Provides the fast math trait and macro. See terms and conditions[^1]. +/// Provides the fast math macro. See terms and conditions[^1]. +/// Prefer [`algebraic`] in most cases. /// /// [^1]: <https://simonbyrne.github.io/notes/fastmath> pub mod fast { @@ -23,8 +25,24 @@ pub mod fast { pub use lower_macros::fast as math; } +/// Provides the saturating math macro. +pub mod saturating { + /// Changes all the math to saturating math. See [`core::num::Saturating`] + /// + /// This would lower `a * b + c` to `((a).saturating_mul(b)).saturating_add(c)`. + pub use lower_macros::saturating as math; +} + +/// Provides the wrapping math macro. +pub mod wrapping { + /// Changes all the math to saturating math. See [`core::num::Wrapping`] + /// + /// This would lower `a * b + c` to `((a).wrapping_mul(b)).wrapping_add(c)`. + pub use lower_macros::wrapping as math; +} + /// Applys the macro to your stmts. -/// Argument can be `algebraic` | `fast` | `basic` | none +/// Argument can be `algebraic` | `fast` | `basic` | `wrapping` | `saturating` | none /// ``` /// # #![feature(core_intrinsics)] /// #[lower::apply(algebraic)] |