Macro fixed::const_fixed_from_int
source · macro_rules! const_fixed_from_int { ($($vis:vis const $NAME:ident: $Fixed:ty = $int:expr;)*) => { ... }; }
👎Deprecated since 1.20.0: use the
const_from_int
method insteadExpand description
Defines constant fixed-point numbers from integer expressions.
This macro was useful because from_num
cannot be
used in constant expressions. Now constant fixed-point numbers can be
created using the const_from_int
method or the
lit
method, so this macro is deprecated.
§Examples
use fixed::{const_fixed_from_int, types::I16F16};
const_fixed_from_int! {
// define a constant using an integer
const FIVE: I16F16 = 5;
// define a constant using an integer expression
const SUM: I16F16 = 3 + 2;
}
assert_eq!(FIVE, 5);
assert_eq!(SUM, 5);
This can now be rewritten as
use fixed::types::I16F16;
const FIVE: I16F16 = I16F16::const_from_int(5);
const SUM: I16F16 = I16F16::const_from_int(3 + 2);
assert_eq!(FIVE, 5);
assert_eq!(SUM, 5);