xref: /aosp_15_r20/external/ltp/include/tst_minmax.h (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker /* SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) 2017 Cyril Hrubis <[email protected]>
3*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) Linux Test Project, 2020-2023
4*49cdfc7eSAndroid Build Coastguard Worker  */
5*49cdfc7eSAndroid Build Coastguard Worker 
6*49cdfc7eSAndroid Build Coastguard Worker #ifndef TST_MINMAX_H__
7*49cdfc7eSAndroid Build Coastguard Worker #define TST_MINMAX_H__
8*49cdfc7eSAndroid Build Coastguard Worker 
9*49cdfc7eSAndroid Build Coastguard Worker #include <sys/param.h>
10*49cdfc7eSAndroid Build Coastguard Worker 
11*49cdfc7eSAndroid Build Coastguard Worker #ifndef MIN
12*49cdfc7eSAndroid Build Coastguard Worker # define MIN(a, b) ({ \
13*49cdfc7eSAndroid Build Coastguard Worker 	typeof(a) _a = (a); \
14*49cdfc7eSAndroid Build Coastguard Worker 	typeof(b) _b = (b); \
15*49cdfc7eSAndroid Build Coastguard Worker 	(void) (&_a == &_b); \
16*49cdfc7eSAndroid Build Coastguard Worker 	_a < _b ? _a : _b; \
17*49cdfc7eSAndroid Build Coastguard Worker })
18*49cdfc7eSAndroid Build Coastguard Worker #endif /* MIN */
19*49cdfc7eSAndroid Build Coastguard Worker 
20*49cdfc7eSAndroid Build Coastguard Worker #ifndef MAX
21*49cdfc7eSAndroid Build Coastguard Worker # define MAX(a, b) ({ \
22*49cdfc7eSAndroid Build Coastguard Worker 	typeof(a) _a = (a); \
23*49cdfc7eSAndroid Build Coastguard Worker 	typeof(b) _b = (b); \
24*49cdfc7eSAndroid Build Coastguard Worker 	(void) (&_a == &_b); \
25*49cdfc7eSAndroid Build Coastguard Worker 	_a > _b ? _a : _b; \
26*49cdfc7eSAndroid Build Coastguard Worker })
27*49cdfc7eSAndroid Build Coastguard Worker #endif /* MAX */
28*49cdfc7eSAndroid Build Coastguard Worker 
29*49cdfc7eSAndroid Build Coastguard Worker #endif	/* TST_MINMAX_H__ */
30