pub trait TypedMul<N: IsInteger> {
    type Output: IsInteger;
    type Overflow: IsInteger;
}
Expand description

A multiplication of 32 bit number and 32 bit number can be stored safely in a 64 bit number. We represent them as lower 32 bits and upper 32 bits

Example

use const_arithmetic::*;
let a = parse_integer!(6);
let b = parse_integer!(4);
let c = parse_integer!(24);
 
// This verifies that 6 * 4 = 24
fn example<P, Q, R>(_p: P, _q: Q, _r: R) where
P: IsInteger,
Q: IsInteger,
R: IsInteger,
P: TypedMul<Q, Output = R>
{}
 
example(a, b, c);
 
// If we are handling really big integers we can get the overflowed bits as follows
// 1234567890 * 987654321 = 1219326311126352690 = 283896529 * (2**32) + 3623437106
let a = parse_integer!(1234567890);
let b = parse_integer!(987654321);
let overflow = parse_integer!(283896529);
let result = parse_integer!(3623437106);
 
// This verifies that 7 - 4 = 3
fn example2<P, Q, R, S>(_p: P, _q: Q, _r: R, _s: S) where
P: IsInteger,
Q: IsInteger,
R: IsInteger,
S: IsInteger,
P: TypedMul<Q, Output = R, Overflow = S>
{}
 
example2(a, b, result, overflow);

Required Associated Types§

Implementors§

source§

impl<N: IsInteger, H0: Hex, H1: Hex, H2: Hex, H3: Hex, H4: Hex, H5: Hex, H6: Hex, H7: Hex, N0: IsInteger, N1: IsInteger, N2: IsInteger, N3: IsInteger, R4: Hex, R5: Hex, R6: Hex, R7: Hex, R8: Hex, R9: Hex, R10: Hex, R11: Hex, R12: Hex, C4: Hex, C5: Hex, C6: Hex, C7: Hex, C8: Hex, C9: Hex, C10: Hex, C11: Hex, C_> TypedMul<N> for TypedInteger<H0, H1, H2, H3, H4, H5, H6, H7>where TypedInteger<N::Hex0, N::Hex1, N::Hex2, N::Hex3, H0, H1, H2, H3>: FoldMul<Output = N0>, TypedInteger<N::Hex0, N::Hex1, N::Hex2, N::Hex3, H4, H5, H6, H7>: FoldMul<Output = N1>, TypedInteger<N::Hex4, N::Hex5, N::Hex6, N::Hex7, H0, H1, H2, H3>: FoldMul<Output = N2>, TypedInteger<N::Hex4, N::Hex5, N::Hex6, N::Hex7, H4, H5, H6, H7>: FoldMul<Output = N3>, N0::Hex4: HexAdd3<N1::Hex0, N2::Hex0, Output = R4, Carry = C4>, N0::Hex5: HexAdd4<N1::Hex1, N2::Hex1, C4, Output = R5, Carry = C5>, N0::Hex6: HexAdd4<N1::Hex2, N2::Hex2, C5, Output = R6, Carry = C6>, N0::Hex7: HexAdd4<N1::Hex3, N2::Hex3, C6, Output = R7, Carry = C7>, N3::Hex0: HexAdd4<N1::Hex4, N2::Hex4, C7, Output = R8, Carry = C8>, N3::Hex1: HexAdd4<N1::Hex5, N2::Hex5, C8, Output = R9, Carry = C9>, N3::Hex2: HexAdd4<N1::Hex6, N2::Hex6, C9, Output = R10, Carry = C10>, N3::Hex3: HexAdd4<N1::Hex7, N2::Hex7, C10, Output = R11, Carry = C11>, N3::Hex4: HexAdd<C11, Output = R12, Carry = C_>, C_: HexAssertEqual<_0> + Hex,

§

type Output = TypedInteger<<N0 as IsInteger>::Hex0, <N0 as IsInteger>::Hex1, <N0 as IsInteger>::Hex2, <N0 as IsInteger>::Hex3, R4, R5, R6, R7>

§

type Overflow = TypedInteger<R8, R9, R10, R11, R12, <N3 as IsInteger>::Hex5, <N3 as IsInteger>::Hex6, <N3 as IsInteger>::Hex7>