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
//! Conversion from [`U320`] into a `[u64; 5]` big-endian limb array.
use super::U320;
/// Converts a [`U320`] into its five `u64` limbs in big-endian order:
/// `[w0, w1, w2, w3, w4]` where `w0` is the most significant.
///
/// This is the inverse of `From<[u64; 5]> for U320` and equivalent to
/// calling [`U320::to_be_limbs`].
///
/// # Examples
///
/// ```
/// use cnfy_uint::u320::U320;
///
/// let v = U320::from_be_limbs([1, 2, 3, 4, 5]);
/// let arr: [u64; 5] = v.into();
/// assert_eq!(arr, [1, 2, 3, 4, 5]);
/// ```
impl From<U320> for [u64; 5] {
#[inline]
fn from(value: U320) -> Self {
[value.0[4], value.0[3], value.0[2], value.0[1], value.0[0]]
}
}
#[cfg(test)]
mod ai_tests {
use super::*;
/// Round-trip from limbs through U320 back to limbs.
#[test]
fn round_trip() {
let arr = [0xA, 0xB, 0xC, 0xD, 0xE];
let v = U320::from_be_limbs(arr);
let back: [u64; 5] = v.into();
assert_eq!(back, arr);
}
/// Zero converts to all-zero limbs.
#[test]
fn zero() {
let arr: [u64; 5] = U320::from_be_limbs([0; 5]).into();
assert_eq!(arr, [0; 5]);
}
/// All-max converts to all-max limbs.
#[test]
fn max() {
let arr: [u64; 5] = U320::from_be_limbs([u64::MAX; 5]).into();
assert_eq!(arr, [u64::MAX; 5]);
}
}