Macro fdec::fdec16[][src]

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

Examples

fdec16! {             // Use 16-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 6,         // 96-bit number (6 * 16-bit units)
    scale 12          // 12 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:

fdec16! {         // Use 16-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      // 80-bit number (5 * 16-bit units)
}