cnfy-uint 0.2.3

Zero-dependency 256-bit unsigned integer arithmetic for cryptographic applications
Documentation
//! Odd-value predicate for [`U384`].
use super::U384;

impl U384 {
    /// Returns `true` if the value is odd (least significant bit is 1).
    ///
    /// Checks the LSB of limb `[0]` (the least significant limb).
    ///
    /// # Examples
    ///
    /// ```
    /// use cnfy_uint::u384::U384;
    ///
    /// assert!(U384::ONE.is_odd());
    /// assert!(!U384::ZERO.is_odd());
    /// ```
    #[inline]
    pub fn is_odd(&self) -> bool {
        self.0[0] & 1 == 1
    }
}

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

    /// Zero is not odd.
    #[test]
    fn zero() {
        assert!(!U384::ZERO.is_odd());
    }

    /// One is odd.
    #[test]
    fn one() {
        assert!(U384::ONE.is_odd());
    }

    /// Two is not odd.
    #[test]
    fn two() {
        assert!(!U384::from_be_limbs([0, 0, 0, 0, 0, 2]).is_odd());
    }

    /// MAX (all bits set) is odd.
    #[test]
    fn max() {
        assert!(U384::MAX.is_odd());
    }

    /// is_odd is the complement of is_even.
    #[test]
    fn complement_of_is_even() {
        let values = [U384::ZERO, U384::ONE, U384::MAX, U384::from_be_limbs([1, 0, 0, 0, 0, 3])];
        for v in &values {
            assert_eq!(v.is_odd(), !v.is_even());
        }
    }
}