4 /* Tools for counting fixed-point numbers. */
6 /* We implement a simple fixed-point number type, with fixed number of
7 * fractional binary digits after the radix point. */
11 typedef uint_fast32_t fixp_t
;
13 /* We should accomodate at least 0..131072 (17bits) in the whole number
14 * portion; assuming at least 32bit integer, that leaves us with 15-bit
15 * fractional part. Thankfully, we need only unsigned values. */
18 #define FIXP_SCALE (1<<FIXP_BITS)
20 #define double_to_fixp(n) ((fixp_t) ((n) * (FIXP_SCALE)))
21 #define fixp_to_double(n) ((double) (n) / FIXP_SCALE)