reweb3_num/bint/
consts.rs

1macro_rules! pos_const {
2    ($BUint: ident; $($name: ident $num: literal), *) => {
3        $(
4            #[doc = doc::consts::value_desc!($num)]
5            pub const $name: Self = Self::from_bits($BUint::$name);
6        )*
7    }
8}
9
10macro_rules! neg_const {
11    ($BUint: ident; $($name: ident $num: literal), *) => {
12        $(
13            #[doc = doc::consts::value_desc!("-" $num)]
14            pub const $name: Self = {
15                let mut u = $BUint::MAX;
16                u.digits[0] -= ($num - 1);
17                Self::from_bits(u)
18            };
19        )*
20    }
21}
22
23use crate::doc;
24use crate::ExpType;
25
26macro_rules! consts {
27    ($BUint: ident, $BInt: ident, $Digit: ident) => {
28        #[doc = doc::consts::impl_desc!()]
29        impl<const N: usize> $BInt<N> {
30            #[doc = doc::consts::min!(I 512)]
31            pub const MIN: Self = {
32                let mut digits = [0; N];
33                digits[N - 1] = 1 << ($Digit::BITS - 1);
34                Self::from_bits($BUint::from_digits(digits))
35            };
36
37            #[doc = doc::consts::max!(I 512)]
38            pub const MAX: Self = {
39                let mut digits = [$Digit::MAX; N];
40                digits[N - 1] >>= 1;
41                Self::from_bits($BUint::from_digits(digits))
42            };
43
44            #[doc = doc::consts::bits!(I 512, 512)]
45            pub const BITS: ExpType = $BUint::<N>::BITS;
46
47            #[doc = doc::consts::bytes!(I 512, 512)]
48            pub const BYTES: ExpType = $BUint::<N>::BYTES;
49
50            #[doc = doc::consts::zero!(I 512)]
51            pub const ZERO: Self = Self::from_bits($BUint::ZERO);
52
53            #[doc = doc::consts::one!(I 512)]
54            pub const ONE: Self = Self::from_bits($BUint::ONE);
55
56            pos_const!($BUint; TWO 2, THREE 3, FOUR 4, FIVE 5, SIX 6, SEVEN 7, EIGHT 8, NINE 9, TEN 10);
57
58            neg_const!($BUint; NEG_ONE 1, NEG_TWO 2, NEG_THREE 3, NEG_FOUR 4, NEG_FIVE 5, NEG_SIX 6, NEG_SEVEN 7, NEG_EIGHT 8, NEG_NINE 9, NEG_TEN 10);
59
60            pub(crate) const N_MINUS_1: usize = N - 1;
61        }
62    }
63}
64
65crate::macro_impl!(consts);