cnfy-uint 0.2.3

Zero-dependency 256-bit unsigned integer arithmetic for cryptographic applications
Documentation
//! Returns the four `u64` limbs in little-endian order.
use super::U256;

impl U256 {
    /// Returns the four `u64` limbs in little-endian order.
    ///
    /// The returned array is `[w3, w2, w1, w0]` where the first element
    /// is the least significant limb and the last element is the most
    /// significant limb.
    ///
    /// # Examples
    ///
    /// ```
    /// use cnfy_uint::u256::U256;
    ///
    /// let v = U256::from_be_limbs([1, 2, 3, 4]);
    /// assert_eq!(v.to_le_limbs(), [4, 3, 2, 1]);
    /// ```
    #[inline]
    pub const fn to_le_limbs(&self) -> [u64; 4] {
        self.0
    }
}

#[cfg(test)]
mod ai_tests {
    use super::*;

    /// to_le_limbs reverses the big-endian order.
    #[test]
    fn le_limbs_reverses() {
        let v = U256::from_be_limbs([1, 2, 3, 4]);
        assert_eq!(v.to_le_limbs(), [4, 3, 2, 1]);
    }

    /// Zero in little-endian is still all zeros.
    #[test]
    fn le_limbs_zero() {
        assert_eq!(U256::ZERO.to_le_limbs(), [0; 4]);
    }

    /// Max value in little-endian is still all MAX.
    #[test]
    fn le_limbs_max() {
        let v = U256::from_be_limbs([u64::MAX; 4]);
        assert_eq!(v.to_le_limbs(), [u64::MAX; 4]);
    }
}