Macro fdec::fdec8[][src]

macro_rules! fdec8 {
    (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 u8’s as building blocks.

Examples

fdec8! {              // Use 8-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 7,         // 56-bit number (7 * 8-bit units)
    scale 8           // 8 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:

fdec8! {          // Use 8-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 10     // 80-bit number (10 * 8-bit units)
}