cctools
macros.h
1/*
2Copyright (C) 2003-2004 Douglas Thain and the University of Wisconsin
3Copyright (C) 2022 The University of Notre Dame
4This software is distributed under the GNU General Public License.
5See the file COPYING for details.
6*/
7
8#ifndef MACROS_H
9#define MACROS_H
10
11#ifndef MAX
12#define MAX(a,b) ( ((a)>(b)) ? (a) : (b) )
13#endif
14
15#ifndef MIN
16#define MIN(a,b) ( ((a)<(b)) ? (a) : (b) )
17#endif
18
19/* treat negative numbers as 'nulls' */
20#ifndef MIN_POS
21#define MIN_POS(a,b) ((a) < 0 ? (b) : ((b) < 0 ? (a) : MIN((a), (b))))
22#endif
23
24#ifndef ABS
25#define ABS(x) ( ((x)>=0) ? (x) : (-(x)) )
26#endif
27
28#define DIV_INT_ROUND_UP(a, b) ((__typeof__(a)) ((int64_t) (((((double) (a)) + ((double) (b)) - 1) / (b)))))
29
30#define KILO 1024
31#define MEGA (KILO*KILO)
32#define GIGA (KILO*MEGA)
33#define TERA (KILO*GIGA)
34#define PETA (KILO*TERA)
35
36#define KILOBYTE KILO
37#define MEGABYTE MEGA
38#define GIGABYTE GIGA
39#define TERABYTE TERA
40#define PETABYTE PETA
41
42#define USECOND 1000000
43
44#endif