Skip to content

umgefahren/upcast-arithmetic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

upcast-arithmetic

Crates.io docs.rs GitHub license Rust

Utility library for dealing with arithmetic on type limits by upcasting into types with higher limits.

Examples

Without upcast_arithmetic (panics)

let a = u8::MAX;
let b = 2u8;

let modulo = u8::MAX;

let res = (a + b) % modulo;
assert_eq!(res, 2);

With upcast_arithmetic

use upcast_arithmetic::*;

let a = u8::MAX;
let b = 2u8;

let modulo = u8::MAX;

let res = a.upcast_add_mod(b, modulo);
assert_eq!(res, 2);

Performance

The performance overhead is very small. In benchmarks it seems like there is only a neglegible performance penelty, compared to assuming no overflow occurs.

no_std

The crate is fully #![no_std] compatible.

Unsafe

There is no unsafe code and the flag #![deny(unsafe_code)] is set.

License: MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages