1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//! Conversion from [`U320`] into [`U384`].
use super::U384;
use crate::u320::U320;
/// Creates a [`U384`] from a [`U320`] value by embedding it in the lower
/// five limbs (`[1..5]`), with the uppermost limb set to zero.
///
/// # Examples
///
/// ```
/// use cnfy_uint::u320::U320;
/// use cnfy_uint::u384::U384;
///
/// let v = U320::from_be_limbs([1, 2, 3, 4, 5]);
/// let wide = U384::from(v);
/// assert_eq!(wide, U384::from_be_limbs([0, 1, 2, 3, 4, 5]));
/// ```
impl From<U320> for U384 {
#[inline]
fn from(v: U320) -> Self {
U384([v.0[0], v.0[1], v.0[2], v.0[3], v.0[4], 0])
}
}
#[cfg(test)]
mod ai_tests {
use super::*;
/// Zero U320 produces zero U384.
#[test]
fn zero() {
assert_eq!(U384::from(U320::from_be_limbs([0, 0, 0, 0, 0])), U384::ZERO);
}
/// One U320 produces one U384.
#[test]
fn one() {
assert_eq!(
U384::from(U320::from_be_limbs([0, 0, 0, 0, 1])),
U384::ONE,
);
}
/// All limbs are placed in the correct positions.
#[test]
fn all_limbs() {
let v = U320::from_be_limbs([0xA, 0xB, 0xC, 0xD, 0xE]);
let wide = U384::from(v);
assert_eq!(wide.to_be_limbs(), [0, 0xA, 0xB, 0xC, 0xD, 0xE]);
}
/// U320 with max limbs maps correctly.
#[test]
fn max_u320() {
let wide = U384::from(U320::from_be_limbs([u64::MAX; 5]));
assert_eq!(
wide,
U384::from_be_limbs([0, u64::MAX, u64::MAX, u64::MAX, u64::MAX, u64::MAX]),
);
}
}