Macro fdec::fdec32[][src]

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

Examples

fdec32! {             // Use 32-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 4,         // 128-bit number (4 * 32-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:

fdec32! {         // Use 32-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 4      // 128-bit number (4 * 32-bit units)
}