Crate staticfraction [] [src]

Static fractions are generalized fixed-point numbers. They can scale a compactly stored (eg. u8 typed) mantissa to any fractional range expressible by a fraction of a more expressive (eg. u32) fraction.

They are useful not only for accessing stored sensor data without manually following the operations to convert them into a standard unit, but should also be usable in APIs of embedded systems, especially where measurements are post-processed in a fashion known at compile time, which can then be simplified by the compiler.

For example, when a check like

if get_system_voltage() < 3.1 { prinln!("Undervoltage warning!"); }

should finally be optimizable at compile time into an integer comparison against the value read from a hardware device without the user of the API having to know the constants involved explicitly.

A note on generic names: The S parameter always indicates with which data type the numerator is *s*tored. The C parameter always indicates with which data type *c*alculations happen, which is also the type of the stored denominator. The D parameter indicates the StaticFractionDescription that holds the numerator scaling and the denominator.



Stored numeric datum that is, for all mathematical operations, seen under the transformation described by D.



Description of transformation parameters