malachite_base/num/arithmetic/
mod_power_of_2_is_reduced.rs

1// Copyright © 2025 Mikhail Hogrefe
2//
3// This file is part of Malachite.
4//
5// Malachite is free software: you can redistribute it and/or modify it under the terms of the GNU
6// Lesser General Public License (LGPL) as published by the Free Software Foundation; either version
7// 3 of the License, or (at your option) any later version. See <https://www.gnu.org/licenses/>.
8
9use crate::num::arithmetic::traits::ModPowerOf2IsReduced;
10use crate::num::logic::traits::SignificantBits;
11
12macro_rules! impl_mod_power_of_2_is_reduced {
13    ($t:ident) => {
14        impl ModPowerOf2IsReduced for $t {
15            /// Returns whether a number is reduced modulo another number $2^k$; in other words,
16            /// whether it has no more than $k$ significant bits.
17            ///
18            /// $f(x, k) = (x < 2^k)$.
19            ///
20            /// # Worst-case complexity
21            /// Constant time and additional memory.
22            ///
23            /// # Examples
24            /// See [here](super::mod_power_of_2_is_reduced#mod_power_of_2_is_reduced).
25            #[inline]
26            fn mod_power_of_2_is_reduced(&self, pow: u64) -> bool {
27                self.significant_bits() <= pow
28            }
29        }
30    };
31}
32apply_to_unsigneds!(impl_mod_power_of_2_is_reduced);