ruint/
cmp.rs

1use crate::Uint;
2use core::cmp::Ordering;
3
4impl<const BITS: usize, const LIMBS: usize> PartialOrd for Uint<BITS, LIMBS> {
5    #[inline]
6    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
7        Some(self.cmp(other))
8    }
9}
10
11impl<const BITS: usize, const LIMBS: usize> Ord for Uint<BITS, LIMBS> {
12    #[inline]
13    fn cmp(&self, rhs: &Self) -> Ordering {
14        crate::algorithms::cmp(self.as_limbs(), rhs.as_limbs())
15    }
16}
17
18impl<const BITS: usize, const LIMBS: usize> Uint<BITS, LIMBS> {
19    /// Returns true if the value is zero.
20    #[inline]
21    #[must_use]
22    pub fn is_zero(&self) -> bool {
23        *self == Self::ZERO
24    }
25}
26
27#[cfg(test)]
28mod tests {
29    use crate::Uint;
30
31    #[test]
32    fn test_is_zero() {
33        assert!(Uint::<0, 0>::ZERO.is_zero());
34        assert!(Uint::<1, 1>::ZERO.is_zero());
35        assert!(Uint::<7, 1>::ZERO.is_zero());
36        assert!(Uint::<64, 1>::ZERO.is_zero());
37
38        assert!(!Uint::<1, 1>::from_limbs([1]).is_zero());
39        assert!(!Uint::<7, 1>::from_limbs([1]).is_zero());
40        assert!(!Uint::<64, 1>::from_limbs([1]).is_zero());
41    }
42}