Fractional integer operations

This header provides some functions for scaling integers by fractions, while preserving as many bits as possible. More...

This header provides some functions for scaling integers by fractions, while preserving as many bits as possible.

The implementation requires that frac_t is initialized properly, either by calling frac_init, which will compute the algorithm parameters at runtime, or via a precomputed initializer.

Precomputing the frac_t values can be done via the application found in `tests/frac-config`

in the RIOT tree.

The algorithm will under certain circumstances give an incorrectly rounded result, more precisely, the result may sometimes be rounded up instead of rounded down when the product in the numerator, $p = x * num$, would result in $p >= 2^{31}$. Fortunately, the relative error of this rounding mistake is small.

This tradeoff is a design choice to make the algorithm faster.

- See also
- Libdivide homepage: http://libdivide.com/