1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# lower

lowers expressions to their "desugared" form.

e.g

`a * b + c` => `(a.mul(b)).add(c)`

note that it is _extremely pervasive_, so

```rust
lower::math! { fn main() -> u8 {
    const X: u8 = 31 * 2;
    return 2 * X + 2;
} }
```

expands to

```rust
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

```rs
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

```rs
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

```rs
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.