Macro fdec::fdec64[][src]

macro_rules! fdec64 {
    (module $modname : ident, name $name : ident, length $mlen : expr) => { ... };
    (module $modname : ident, name $name : ident, length $mlen : expr, scale
 $scale : expr) => { ... };
}
Expand description

Generates a fixed-size fixed-point numeric type that uses u64’s as building blocks.

Examples

fdec64! {             // Use 64-bit units as building blocks
    module decimal,   // Name of the module that will contain all the generated code
    name Dec,         // Name of the numeric type to be generated
    length 15,        // 960-bit number (15 * 64-bit units)
    scale 100         // 100 decimal places
}

use std::str::FromStr;
use decimal::*;

let a = Dec::from(13);
let b = Dec::from_str("2.47").unwrap();
assert_eq!(a + b, Dec::with_scale(1547, 2));

The scale parameter can be omitted. In this case, the generated type represents integer numbers:

fdec64! {         // Use 64-bit units as building blocks
    module int,   // Name of the module that will contain all the generated code
    name Int,     // Name of the numeric type to be generated
    length 5      // 320-bit number (5 * 64-bit units)
}