fastnum/decimal/macros/
dec.rs1macro_rules! macro_impl {
2 ($d:tt, $DEC: ident, $bits: literal, $sign: ident, $name: ident) => {
3 #[macro_export]
4 #[doc = concat!("A macro to construct ", $bits, "-bit ", stringify!($sign), " [`", stringify!($DEC), "`](crate::", stringify!($DEC), ") decimal from literals in compile time.")]
5 #[doc = concat!("const N: ", stringify!($DEC), " = ", stringify!($name), "!(1.23456789);")]
16 #[doc = concat!("let num = ", stringify!($name), "!(0);")]
19 #[doc = concat!("const A: ", stringify!($DEC), " = ", stringify!($name), "!(5);")]
22 #[doc = concat!("const B: ", stringify!($DEC), " = ", stringify!($name), "!(1_000);")]
23 #[doc = concat!("const C: ", stringify!($DEC), " = A.div(B);")]
24 #[doc = concat!("assert_eq!(C, ", stringify!($name), "!(0.005));")]
26 #[doc = concat!("use fastnum::{", stringify!($name), ", ", stringify!($DEC), "}")]
34 #[doc = concat!("const N: ", stringify!($DEC), " = ", stringify!($name), "!(A1.23456789);")]
38 macro_rules! $name {
44 ($d($d body:tt)*) => {{
45 const __CTX: $crate::decimal::Context = $crate::decimal::Context::default();
46 const __DECIMAL: $crate::$DEC = $crate::$DEC::parse_str(concat!($d(stringify!($d body)),*), __CTX);
47 __DECIMAL
48 }};
49 }
50 };
51}
52
53macro_impl!($, UD64, 64, unsigned, udec64);
54macro_impl!($, UD128, 128, unsigned, udec128);
55macro_impl!($, UD256, 256, unsigned, udec256);
56macro_impl!($, UD512, 512, unsigned, udec512);
57macro_impl!($, UD1024, 1024, unsigned, udec1024);
58macro_impl!($, D64, 64, signed, dec64);
63macro_impl!($, D128, 128, signed, dec128);
64macro_impl!($, D256, 256, signed, dec256);
65macro_impl!($, D512, 512, signed, dec512);
66macro_impl!($, D1024, 1024, signed, dec1024);
67