30 any_type
max(any_type a, any_type b);
40 any_type
min(any_type a, any_type b);
54 any_type
constrain(any_type x, any_type lo, any_type hi);
64 any_type
absdiff(any_type a, any_type b);
74 any_type
absall(any_type x);
90 #error GCC statement expressions will only work with gcc compiler!
97 ({ __typeof__ (a) _a = (a); \
98 __typeof__ (b) _b = (b); \
100 #define max3(a,b,c) max(max(a,b),c)
101 #define max4(a,b,c,d) max(max(a,b),max(c,d))
107 ({ __typeof__ (a) _a = (a); \
108 __typeof__ (b) _b = (b); \
109 _a < _b ? _a : _b; })
110 #define min3(a,b,c) min(min(a,b),c)
111 #define min4(a,b,c,d) min(min(a,b),min(c,d))
115 #define constrain(x,a,b) \
116 ({ __typeof__ (x) _x = (x); \
117 __typeof__ (a) _a = (a); \
118 __typeof__ (b) _b = (b); \
119 _x < _a ? _a : (_x > _b ? _b : _x); })
123 #define max3(a,b,c) max(max(a,b),c)
124 #define max4(a,b,c,d) max(max(a,b),max(c,d))
125 #define min3(a,b,c) min(min(a,b),c)
126 #define min4(a,b,c,d) min(min(a,b),min(c,d))
130 #define absdiff(a,b) \
131 ({ __typeof__ (a) _a = (a); \
132 __typeof__ (b) _b = (b); \
133 (_a < _b) ? (_b-_a) : (_a-_b); })
137 ({ __typeof__ (a) _a = (a); \
138 (_a < 0) ? (-_a) : (_a); })
144 template <
typename T>
145 inline static T
max(T a, T b) {
146 return a > b ? a : b;
149 template <
typename T>
150 inline static T
max(T a, T b, T c) {
154 template <
typename T>
155 inline static T
max(T a, T b, T c, T d) {
162 template <
typename T>
163 inline static T
min(T a, T b) {
164 return a < b ? a : b;
167 template <
typename T>
168 inline static T
min(T a, T b, T c) {
172 template <
typename T>
173 inline static T
min(T a, T b, T c, T d) {
180 template <
typename T>
181 inline static T
constrain(T x, T a, T b) {
182 return x < a ? a : (x > b ? b : x);
187 #define max3(a,b,c) max(max(a,b),c)
188 #define max4(a,b,c,d) max(max(a,b),max(c,d))
189 #define min3(a,b,c) min(min(a,b),c)
190 #define min4(a,b,c,d) min(min(a,b),min(c,d))
194 template <
typename T>
195 inline static T
absall(T x) {
196 return (x < 0) ? -x : x;
199 template <
typename T>
200 inline static T
absdiff(T a, T b) {
201 return (a < b) ? (b-a) : (a-b);
205 #endif // __cplusplus
209 #endif // _NIBO_UTILS_H_
any_type min(any_type a, any_type b)
Minimum von zwei Werten.
any_type absdiff(any_type a, any_type b)
Absolute (positive) Differenz von zwei Werten.
any_type constrain(any_type x, any_type lo, any_type hi)
Beschränkt den Wert x auf das Interval [lo,hi].
any_type absall(any_type x)
Absolutwert (Wert ohne Vorzeichen).
any_type max(any_type a, any_type b)
Maximum von zwei Werten.