malachite_base/num/arithmetic/
mod_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::ModIsReduced;
10
11macro_rules! impl_mod_is_reduced {
12    ($t:ident) => {
13        impl ModIsReduced for $t {
14            /// Returns whether a number is reduced modulo another number $m$; in other words,
15            /// whether it is less than $m$. $m$ cannot be zero.
16            ///
17            /// $f(x, m) = (x < m)$.
18            ///
19            /// # Worst-case complexity
20            /// Constant time and additional memory.
21            ///
22            /// # Panics
23            /// Panics if $m$ is 0.
24            ///
25            /// # Examples
26            /// See [here](super::mod_is_reduced#mod_is_reduced).
27            #[inline]
28            fn mod_is_reduced(&self, m: &$t) -> bool {
29                assert_ne!(*m, 0);
30                self < m
31            }
32        }
33    };
34}
35apply_to_unsigneds!(impl_mod_is_reduced);