![]() |
libdragon
|
Misc utilities functions and macros. More...
Go to the source code of this file.
Macros | |
| #define | SWAP(a, b) ({ typeof(a) t = a; a = b; b = t; }) |
| Swap two values. | |
| #define | MAX(a, b) ({ typeof(a) _a = a; typeof(b) _b = b; _a > _b ? _a : _b; }) |
| Return the maximum of two values. | |
| #define | MIN(a, b) ({ typeof(a) _a = a; typeof(b) _b = b; _a < _b ? _a : _b; }) |
| Return the minimum of two values. | |
| #define | CLAMP(x, min, max) (MIN(MAX((x), (min)), (max))) |
| Clamp a value between min and max. | |
| #define | ROUND_UP(n, d) |
| Round n up to the next multiple of d. | |
| #define | ROUND_DOWN(n, d) |
| Round n down to the previous multiple of d. | |
| #define | DIVIDE_CEIL(n, d) |
| Return the ceil of n/d. | |
| #define | ABS(x) |
| Absolute number. | |
| #define | F2I(f) ({ uint32_t __i; memcpy(&__i, &(f), 4); __i; }) |
| Type-safe bitcast from float to integer. | |
| #define | I2F(i) ({ float __f; memcpy(&__f, &(i), 4); __f; }) |
| Type-safe bitcast from integer to float. | |
| #define | LIKELY(cond) __builtin_expect(!!(cond), 1) |
| Hint for the compiler that the condition is likely to happen. | |
| #define | UNLIKELY(cond) __builtin_expect(!!(cond), 0) |
| Hint for the compiler that the condition is unlikely to happen. | |
Functions | |
| uint32_t | __utf8_decode (const char **str) |
| UTF-8 decoding. | |
Misc utilities functions and macros.
| #define ROUND_UP | ( | n, | |
| d | |||
| ) |
Round n up to the next multiple of d.
| #define ROUND_DOWN | ( | n, | |
| d | |||
| ) |
Round n down to the previous multiple of d.
| #define DIVIDE_CEIL | ( | n, | |
| d | |||
| ) |
Return the ceil of n/d.
| #define ABS | ( | x | ) |
Absolute number.