tasm_lib/arithmetic/
u160.rs

1pub mod div_mod;
2pub mod lt;
3pub mod overflowing_add;
4pub mod safe_add;
5pub mod safe_mul;
6
7/// Convert a `u128` to a u160 representation with the same value.
8#[cfg(test)]
9pub(super) fn u128_to_u160(x: u128) -> [u32; 5] {
10    [
11        (x & (u32::MAX as u128)) as u32,
12        ((x >> 32) & (u32::MAX as u128)) as u32,
13        ((x >> 64) & (u32::MAX as u128)) as u32,
14        ((x >> 96) & (u32::MAX as u128)) as u32,
15        0,
16    ]
17}
18
19/// Convert a `u128` to a u160 representation of $2^{32}$ times the input.
20#[cfg(test)]
21pub(super) fn u128_to_u160_shl_32(x: u128) -> [u32; 5] {
22    [
23        0,
24        (x & (u32::MAX as u128)) as u32,
25        ((x >> 32) & (u32::MAX as u128)) as u32,
26        ((x >> 64) & (u32::MAX as u128)) as u32,
27        ((x >> 96) & (u32::MAX as u128)) as u32,
28    ]
29}
30
31/// Convert a `u128` to a u160 representation of $x * 2^{32} + 2^{32} - 1$.
32#[cfg(test)]
33pub(super) fn u128_to_u160_shl_32_lower_limb_filled(x: u128) -> [u32; 5] {
34    [
35        u32::MAX,
36        (x & (u32::MAX as u128)) as u32,
37        ((x >> 32) & (u32::MAX as u128)) as u32,
38        ((x >> 64) & (u32::MAX as u128)) as u32,
39        ((x >> 96) & (u32::MAX as u128)) as u32,
40    ]
41}