Crate const_fixedp

Source
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.