Skip to main content

fastnum/bint/
macros.rs

1macro_rules! macro_impl {
2    ($d:tt, $INT: ident, $bits: literal, $sign: ident, $name: ident) => {
3        #[macro_export]
4        #[doc = concat!("A macro to construct ", $bits, "-bit [`", stringify!($INT), "`](crate::", stringify!($INT), ") ", stringify!($sign), " integer from literals.")]
5        ///
6        ///
7        /// # Examples:
8        ///
9        /// ```
10        #[doc = concat!("use fastnum::{", stringify!($name), ", ", stringify!($INT), "};")]
11        ///
12        #[doc = concat!("const N: ", stringify!($INT), " = ", stringify!($name), "!(100);")]
13        #[doc = concat!("let x = ", stringify!($name), "!(1);")]
14        #[doc = concat!("assert!(", stringify!($name), "!(0).is_zero());")]
15        /// println!("{x}");
16        /// ```
17        ///
18        macro_rules! $name {
19            ($d($d body:tt)*) => {{
20                const __INT: $crate::$INT = $crate::$INT::parse_str(concat!($d(stringify!($d body)),*));
21                __INT
22            }};
23        }
24    };
25}
26
27macro_impl!($, U64, 64, unsigned, u64);
28macro_impl!($, U128, 128, unsigned, u128);
29macro_impl!($, U256, 256, unsigned, u256);
30macro_impl!($, U512, 512, unsigned, u512);
31macro_impl!($, U1024, 1024, unsigned, u1024);
32// macro_impl!($, U2048, 2048, unsigned, u2048);
33// macro_impl!($, U4096, 4096, unsigned, u4096);
34// macro_impl!($, U8192, 8192, unsigned, u8192);
35
36macro_impl!($, I64, 64, signed, i64);
37macro_impl!($, I128, 128, signed, i128);
38macro_impl!($, I256, 256, signed, i256);
39macro_impl!($, I512, 512, signed, i512);
40macro_impl!($, I1024, 1024, signed, i1024);
41// macro_impl!($, I2048, 2048, signed, i2048);
42// macro_impl!($, I4096, 4096, signed, i4096);
43// macro_impl!($, I8192, 8192, signed, i8192);