6 releases
Uses new Rust 2024
| 0.2.1 | Nov 7, 2025 |
|---|---|
| 0.2.0 | Feb 3, 2025 |
| 0.1.4 | Feb 2, 2025 |
| 0.1.3 | Jan 27, 2025 |
| 0.1.1 | Feb 18, 2024 |
#476 in Math
Used in 5 crates
(2 directly)
6KB
lower
lowers expressions to their "desugared" form.
e.g
a * b + c => (a.mul(b)).add(c)
note that it is extremely pervasive, so
lower::math! { fn main() -> u8 {
const X: u8 = 31 * 2;
return 2 * X + 2;
} }
expands to
fn main() -> u8 {
const X: u8 = 31.mul(2);
return (2.mul(X)).add(2);
}
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
rust added an amazing feature called algebraic math (thanks orlp), allowing us to use f*_algebraic. however, dont you hate it when your
fn madd<const N: usize>(x: [[f32; 3]; N]) -> [f32; N] {
x.map(|[a, b, c]| a * b + c) // not optimized! cant use `(v)fmadd`
}
turns into
fn madd<const N: usize>(x: [[f32; 3]; N]) -> [f32; N] {
x.map(|[a, b, c]| core::intrinsics::fadd_algebraic(core::intrinsics::fmul_algebraic(a, b), c)) // readability in shambles
}
this crate allows you to
fn madd<const N: usize>(x: [[f32; 3]; N]) -> [f32; N] {
// wow! such readability! ultimate simd!
lower::algebraic! { x.map(|[a, b, c]| a * b + c) }
}
this is also great for wrapping/saturating math.
Dependencies
~135–530KB
~13K SLoC