pattern_match_{capture,aescape}: Fix trapped to work the same as board safety check
[pachi.git] / fixp.h
blob0e275761026d7783bef42cdd6f089cd27456c69c
1 #ifndef ZZGO_FIXP_H
2 #define ZZGO_FIXP_H
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. */
9 #include <stdint.h>
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. */
16 #define FIXP_BITS 15
18 #define FIXP_SCALE (1<<FIXP_BITS)
20 #define double_to_fixp(n) (nearbyint((n) * (FIXP_SCALE)))
21 #define fixp_to_double(n) ((double) (n) / FIXP_SCALE)
23 #endif