Trait TypedDiv

Source
pub trait TypedDiv<K: IsInteger> {
    type Output: IsInteger;
    type Remainder: IsInteger;
}
Expand description

Returns the Quotient of H/K for H: Div<K, Output: …>

Note about implementation detail: This is an expanded version of long division - it takes O(1) steps but the constant is quite big unfortunately (to be precise its 32 multiplications plus a negligible amount of addition and subtraction and other stuff) If there were many divisions, the compile time increases quite a bit

Example

// (This doc test takes about 5 seconds to complete on my computer)
use const_arithmetic::*;
let a = parse_integer!(25);
let b = parse_integer!(4);
let quotient = parse_integer!(6);
let modulus = parse_integer!(1);
 
// This verifies that 25/4 = 6 ... 1
fn example<P, Q, R, S>(_p: P, _q: Q, _r: R, _s: S) where
P: IsInteger,
Q: IsInteger,
R: IsInteger,
S: IsInteger,
P: TypedDiv<Q, Output = R, Remainder = S>
{}
 
example(a, b, quotient, modulus);

Required Associated Types§

Implementors§

Source§

impl<N: IsInteger, H0: Hex, H1: Hex, H2: Hex, H3: Hex, H4: Hex, H5: Hex, H6: Hex, H7: Hex, R: IsInteger, O: IsInteger> TypedDiv<N> for TypedInteger<H0, H1, H2, H3, H4, H5, H6, H7>
where TypedInteger<H0, H1, H2, H3, H4, H5, H6, H7>: _Div<N, Output = R, Remainder = O>,