upcast-arithmetic

Crates.ioupcast-arithmetic
lib.rsupcast-arithmetic
version0.1.2
sourcesrc
created_at2022-07-10 19:57:42.528405
updated_at2022-08-13 10:31:07.381065
descriptionArithmetic that is upcasted on overflow
homepage
repositoryhttps://github.com/umgefahren/upcast-arithmetic
max_upload_size
id623286
size24,506
Hannes (umgefahren)

documentation

README

upcast-arithmetic

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

Examples

Without upcast_arithmetic

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);

License: MIT

Commit count: 17

cargo fmt