Crates.io | upcast-arithmetic |
lib.rs | upcast-arithmetic |
version | 0.1.2 |
source | src |
created_at | 2022-07-10 19:57:42.528405 |
updated_at | 2022-08-13 10:31:07.381065 |
description | Arithmetic that is upcasted on overflow |
homepage | |
repository | https://github.com/umgefahren/upcast-arithmetic |
max_upload_size | |
id | 623286 |
size | 24,506 |
Utility library for dealing with arithmetic on type limits by upcasting into types with higher limits.
upcast_arithmetic
let a = u8::MAX;
let b = 2u8;
let modulo = u8::MAX;
let res = (a + b) % modulo;
assert_eq!(res, 2);
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