1 /*
2  * Copyright 2018 Oticon A/S
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef _BS_UTIL_UTILS_H
8 #define _BS_UTIL_UTILS_H
9 
10 #include "bs_types.h"
11 
12 #ifndef STR
13 #define __STR_2(a) #a
14 #define STR(a) __STR_2(a)
15 #endif
16 
17 //MIN and MAX macros similar to the definition in sys/param.h
18 //see for example http://stackoverflow.com/questions/3437404/min-and-max-in-c for a long discussion about a trivial piece of code
19 //Note that the solution with the compound statement is not necessarily portable to other compilers
20 #ifndef BS_MAX
21 #define BS_MAX( x, y ) ( ( (x) > (y) ) ? (x) : (y) ) //Safe'ish MAX macro (be careful that a and b are evaluated twice)
22 #endif
23 
24 #ifndef BS_MIN
25 #define BS_MIN( x, y ) ( ( (x) < (y) ) ? (x) : (y) ) //Safe'ish MIN macro (be careful that a and b are evaluated twice)
26 #endif
27 
28 #ifndef BS_MOD
29 #define BS_MOD( x ,y ) ( ( ( (x) % (y) ) + (y) ) % (y) ) //Use this instead of just % to avoid problems with rem( % in C99 ) != mod
30 #endif
31 
32 #endif
33