macro_rules! udec1024 {
($($body:tt)*) => { ... };
}Expand description
A macro to construct 1024-bit unsigned UD1024 decimal from literals in compile time.
Const-evaluated in compile time macro-helper can be used for definitions of constants or variables whose value is known in compile time.
§Examples:
Basic usage:
use fastnum::*;
const N: UD1024 = udec1024!(1.23456789);
assert!(!N.is_zero());
let num = udec1024!(0);
assert!(num.is_zero());
const A: UD1024 = udec1024!(5);
const B: UD1024 = udec1024!(1_000);
const C: UD1024 = A.div(B);
assert_eq!(C, udec1024!(0.005));
§Static assertions:
ⓘ
// The below example will fail to compile, as the function will panic at compile time:
use fastnum::{udec1024, UD1024}
// Gives a compile error of "error[E0080]: evaluation of constant value failed...
// the evaluated program panicked at 'attempt to parse decimal from string containing invalid digit'",
const N: UD1024 = udec1024!(A1.23456789);This allows you to perform all the necessary checks such as potentialy overflow or calculation accuracy loss and others at the compile time. Protect from unexpected errors in runtime.