Allow double for all floating point values in large configurations.
[pachi/ann.git] / util.h
blob7e531dfbcc4948e36aab068cd33a4907a597b1ea
1 #ifndef ZZGO_UTIL_H
2 #define ZZGO_UTIL_H
4 #include <stdlib.h>
6 /* Misc. definitions. */
8 /* Use make -Dfloating_t=double in large configurations with counts > 1M,
9 * where 24 bits of floating_t mantissa become insufficient. */
10 #ifndef floating_t
11 # define floating_t float
12 #endif
14 #define likely(x) __builtin_expect(!!(x), 1)
15 #define unlikely(x) __builtin_expect((x), 0)
17 static inline void *
18 checked_malloc(size_t size, char *filename, unsigned int line, const char *func)
20 void *p = malloc(size);
21 if (!p) {
22 fprintf(stderr, "%s:%u: %s: OUT OF MEMORY malloc(%zu)\n",
23 filename, line, func, size);
24 exit(1);
26 return p;
29 static inline void *
30 checked_calloc(size_t nmemb, size_t size, char *filename, unsigned int line, const char *func)
32 void *p = calloc(nmemb, size);
33 if (!p) {
34 fprintf(stderr, "%s:%u: %s: OUT OF MEMORY calloc(%zu, %zu)\n",
35 filename, line, func, nmemb, size);
36 exit(1);
38 return p;
41 #define malloc2(size) checked_malloc((size), __FILE__, __LINE__, __func__)
42 #define calloc2(nmemb, size) checked_calloc((nmemb), (size), __FILE__, __LINE__, __func__)
44 #endif