macro_rules! sane_arithmetic {
($($guard:ident),+ ; $expr:expr) => { ... };
}Expand description
Guards one or more usize variables and evaluates an arithmetic expression using
checked arithmetic via Sane.
Each guard variable is shadowed as a Sane newtype whose +, -, *, /
operators use checked_* internally, panicking via
detected_computable_would_exhaust_memory! on overflow. The result is unwrapped
back to usize and checked against MAX_COMPUTATION_BITS.
§Syntax
sane_arithmetic!(var1, var2, ...; expression)Guards must be identifiers (not arbitrary expressions).
§Example
use computable::sane_arithmetic;
let num_terms: usize = 10;
let exponent = sane_arithmetic!(num_terms; 2 * num_terms + 1);
assert_eq!(exponent, 21);