 |
libdragon
|
Loading...
Searching...
No Matches
Go to the documentation of this file.
6#ifndef __LIBDRAGON_UTILS_H
7#define __LIBDRAGON_UTILS_H
12#define SWAP(a, b) ({ typeof(a) t = a; a = b; b = t; })
15#define MAX(a,b) ({ typeof(a) _a = a; typeof(b) _b = b; _a > _b ? _a : _b; })
17#define MIN(a,b) ({ typeof(a) _a = a; typeof(b) _b = b; _a < _b ? _a : _b; })
19#define CLAMP(x, min, max) (MIN(MAX((x), (min)), (max)))
22#define ROUND_UP(n, d) ({ \
23 typeof(n) _n = n; typeof(d) _d = d; \
24 (((_n) + (_d) - 1) / (_d) * (_d)); \
28#define ROUND_DOWN(n, d) ({ \
29 typeof(n) _n = n; typeof(d) _d = d; \
30 ((_n >= 0) ? ((_n) / (_d) * (_d)) : -(((-_n + (_d) - 1) / (_d)) * (_d))); \
34#define DIVIDE_CEIL(n, d) ({ \
35 typeof(n) _n = n; typeof(d) _d = d; \
36 ((_n) + (_d) - 1) / (_d); \
42 (_x < 0 ? -_x : _x); \
46#define F2I(f) ({ uint32_t __i; memcpy(&__i, &(f), 4); __i; })
49#define I2F(i) ({ float __f; memcpy(&__f, &(i), 4); __f; })
52#define LIKELY(cond) __builtin_expect(!!(cond), 1)
54#define UNLIKELY(cond) __builtin_expect(!!(cond), 0)