fixed_bigint/heapless/parity.rs
1//! `const_num_traits::Parity` for `HeaplessBigInt`.
2//!
3//! Parity is a single-bit inspection of the lowest limb — no full-value
4//! scan. For `len == 0` (mathematical zero shape) the answer is
5//! deterministically even.
6
7use super::HeaplessBigInt;
8use crate::MachineWord;
9use const_num_traits::{Parity, Personality};
10
11impl<T, const CAP: usize, P: Personality> Parity for HeaplessBigInt<T, CAP, P>
12where
13 T: MachineWord + Parity,
14{
15 fn is_odd(self) -> bool {
16 if self.len == 0 {
17 false
18 } else {
19 self.limbs[0].is_odd()
20 }
21 }
22
23 fn is_even(self) -> bool {
24 !self.is_odd()
25 }
26}