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