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
//! Conversion from `u64` into [`U384`].
use super::U384;
/// Creates a [`U384`] from a `u64` value, placing it in the least
/// significant limb with the upper five limbs set to zero.
///
/// # Examples
///
/// ```
/// use cnfy_uint::u384::U384;
///
/// let v = U384::from(42u64);
/// assert_eq!(v, U384::from_be_limbs([0, 0, 0, 0, 0, 42]));
/// ```
impl From<u64> for U384 {
#[inline]
fn from(value: u64) -> Self {
Self::from_be_limbs([0, 0, 0, 0, 0, value])
}
}
#[cfg(test)]
mod ai_tests {
use super::*;
/// Converting zero produces U384::ZERO.
#[test]
fn zero() {
assert_eq!(U384::from(0u64), U384::ZERO);
}
/// Converting one produces U384::ONE.
#[test]
fn one() {
assert_eq!(U384::from(1u64), U384::ONE);
}
/// Converting u64::MAX fills only the lowest limb.
#[test]
fn max_u64() {
assert_eq!(
U384::from(u64::MAX),
U384::from_be_limbs([0, 0, 0, 0, 0, u64::MAX]),
);
}
/// Arbitrary value round-trips through to_be_limbs.
#[test]
fn round_trip() {
let v = U384::from(0xDEADBEEFu64);
assert_eq!(v.to_be_limbs(), [0, 0, 0, 0, 0, 0xDEADBEEF]);
}
}