Skip to content

franziskuskiefer/wrapping-arithmetic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This crate provides a proc macro that rewrites arithemtic operators +,-,* into their wrapping equivalents wrapping_add, wrapping_sub, wrapping_mul as well as their assigning versions +=,-=,*=.

The following function for example

#[wrappit]
fn mix(a: u32, b: u32, c: &[u32]) -> u32 {
    let mut r = a + b;
    for u in c {
        r *= u;
    }
    r
}

is rewritten to

fn mix(a: u32, b: u32, c: &[u32]) -> u32 {
    let mut r = a.wrapping_add(b);
    for u in c {
        r = r.wrapping_mul(u);
    }
    r
}

About

Rust proc macro to make arithmetic in functions wrapping

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages