Expand description
Basic unsigned fixed-point arithmetic.
This module provides a Copy
type that holds arbitrary precision for
fractional values, performs additions and subtractions, and can be
compared and sorted efficiently.
The internal representation uses 64 bits, and will adapt to the
requested precision by reducing the integer range, so keep this in
mind when increasing precision but still requiring big values, as
compilation will fail if there’s not enough bit space for at least
FixedP::<P>::MIN_UNIT_SCALE
integer values.
Enable the serde
feature flag to have serialization and
deserialization capabilities for this type.
Macros§
- const_
assert - Assert a boolean condition in constant contexts. Signal a fatal error on failure.
- const_
int_ as - Cast a given integer type to another one in constant contexts. Signal a fatal error if the cast target can’t fit the source integer type.
- const_
option_ unwrap - Unwrap an Option
in constant contexts. Signal a fatal error on None. - const_
panic - Signal a fatal error when evaluating a constant context.
- const_
result_ unwrap - Unwrap a Result<T, E> in constant contexts. Signal a fatal error on Err.
Structs§
- FixedP
- A
Copy
type representing an unsigned, fixed point value, supporting const context evaluation.
Enums§
- Error
- An error type covering the cases where units or fractional values are out of range, when a conversion error happens (ie. trying to convert from a negative or too big value), or when parsing fails.
Type Aliases§
- Precision
- Type describing the precision required for the fractional part of a fixed-point value.