cnfy-uint 0.2.3

Zero-dependency 256-bit unsigned integer arithmetic for cryptographic applications
Documentation
//! Extraction of the high 128 bits from a [`U256`].
use super::U256;

impl U256 {
    /// Returns the high (most significant) 128-bit value, reconstructed from
    /// the two most significant 64-bit limbs (`w0` and `w1`).
    ///
    /// # Examples
    ///
    /// ```
    /// use cnfy_uint::u256::U256;
    ///
    /// let v = U256::from_be_limbs([0, 42, 0, 7]);
    /// assert_eq!(v.high_u128(), 42);
    /// ```
    #[inline]
    pub const fn high_u128(&self) -> u128 {
        (self.0[3] as u128) << 64 | self.0[2] as u128
    }
}

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

    /// High value is reconstructed from limbs w0 and w1.
    #[test]
    fn returns_high() {
        let v = U256::from_be_limbs([0, 0xAB, 0, 0xCD]);
        assert_eq!(v.high_u128(), 0xAB);
    }
}