Expand description
§fixp: a fixed-point library for rust
This crate contains the FixedPoint type, which takes two generic arguments:
The underlying type, and the number of bits to use for the fractional part.
The underlying type can be any primitive rust integer type. The number of
fractional bits can be from 0 up to the number of bits in the underlying type,
inclusive (for a fixed point with no integer part).
You can use the fixp! macro to create fixed-point numbers of any type.
let dec: FixedPoint<u32, 16> = fixp!("8.25");
let hex = fixp!("0x08.4");
let oct = fixp!("0o10.20");
let bin = fixp!("0b1_000.01");
assert_eq!(dec, hex);
assert_eq!(oct, bin);
assert_eq!(dec, bin);
assert_eq!(f32::from(dec), 8.25);
assert_eq!(f64::from(dec), 8.25);
assert_eq!(FixedPoint::try_from(8.25_f32), Ok(dec));
assert_eq!(FixedPoint::try_from(8.25_f64), Ok(dec));Macros§
- fixp
- Parse a string to
FixedPointat compile time. This is equivalent to callingFixedPoint::from_strand unwrapping the result in a const block. On error, it will panic at compile time. - fixp_
exact - Parse a string to
FixedPointat compile time, and reject numbers that can’t be represented exactly. This is equivalent to callingFixedPoint::from_str_exactand unwrapping the result in a const block. On error, it will panic at compile time.
Structs§
- Fixed
Point - A fixed point number. The generic argument
Tis the underlying primitive Rust integer type, andFRACT_BITSis the number of bits to use for the fractional part.FRACT_BITScan be in range0..=T::BITS.
Enums§
- Parse
Error - Fixed point parse error.