20 lines
461 B
C
20 lines
461 B
C
#pragma once
|
|
|
|
#include <limits.h>
|
|
|
|
#define min(x, y) ((x < y) ? (x) : (y))
|
|
#define max(x, y) ((x > y) ? (x) : (y))
|
|
|
|
/* Human-readable sizes */
|
|
#define KIB 1024
|
|
#define MIB (1024 * KIB)
|
|
#define GIB (1024 * GIB)
|
|
|
|
/* Rounding */
|
|
#define IS_ROUND(x, k) (!((x) & ((k) - 1)))
|
|
#define ROUND_DOWN(x, k) ((x) & ~((k) - 1))
|
|
#define ROUND_UP(x, k) (((x) + (k) - 1) & ~((k) - 1))
|
|
|
|
/* Bit manipulation */
|
|
#define BIT_SIZE(t) (CHAR_BIT * sizeof(t))
|
|
#define BIT(n) (1 << (n))
|