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);
85 #error GCC statement expressions will only work with gcc compiler!
92 ({ __typeof__ (a) _a = (a); \
93 __typeof__ (b) _b = (b); \
95 #define max3(a,b,c) max(max(a,b),c)
96 #define max4(a,b,c,d) max(max(a,b),max(c,d))
102 ({ __typeof__ (a) _a = (a); \
103 __typeof__ (b) _b = (b); \
104 _a < _b ? _a : _b; })
105 #define min3(a,b,c) min(min(a,b),c)
106 #define min4(a,b,c,d) min(min(a,b),min(c,d))
110 #define constrain(x,a,b) \
111 ({ __typeof__ (x) _x = (x); \
112 __typeof__ (a) _a = (a); \
113 __typeof__ (b) _b = (b); \
114 _x < _a ? _a : (_x > _b ? _b : _x); })
118 #define absdiff(a,b) \
119 ({ __typeof__ (a) _a = (a); \
120 __typeof__ (b) _b = (b); \
121 (_a < _b) ? (_b-_a) : (_a-_b); })
125 ({ __typeof__ (a) _a = (a); \
126 (_a < 0) ? (-_a) : (_a); })
132 template <
typename T>
133 inline static T
max(T a, T b) {
134 return a > b ? a : b;
137 template <
typename T>
138 inline static T
max(T a, T b, T c) {
142 template <
typename T>
143 inline static T
max(T a, T b, T c, T d) {
150 template <
typename T>
151 inline static T
min(T a, T b) {
152 return a < b ? a : b;
155 template <
typename T>
156 inline static T
min(T a, T b, T c) {
160 template <
typename T>
161 inline static T
min(T a, T b, T c, T d) {
165 template <
typename T>
166 inline static T
min(T a, T b, T c, T d) {
173 template <
typename T>
174 inline static T
constrain(T x, T a, T b) {
175 return x < a ? a : (x > b ? b : x);
180 template <
typename T>
181 inline static T
absall(T x) {
182 return (x < 0) ? -x : x;
185 template <
typename T>
186 inline static T
absdiff(T a, T b) {
187 return (a < b) ? (b-a) : (a-b);
191 #endif // __cplusplus
195 #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.