File tree 1 file changed +31
-3
lines changed
1 file changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -98,10 +98,38 @@ void loop( void ) ;
98
98
#ifdef abs
99
99
#undef abs
100
100
#endif // abs
101
+ // undefine stdlib's abs if encountered
102
+ #ifdef abs
103
+ #undef abs
104
+ #endif // abs
105
+
106
+ #ifdef __cplusplus
107
+ template <class T , class L >
108
+ auto min (const T& a, const L& b) -> decltype((b < a) ? b : a)
109
+ {
110
+ return (b < a) ? b : a;
111
+ }
112
+
113
+ template <class T , class L >
114
+ auto max (const T& a, const L& b) -> decltype((b < a) ? b : a)
115
+ {
116
+ return (a < b) ? b : a;
117
+ }
118
+ #else
119
+ #ifndef min
120
+ #define min (a,b ) \
121
+ ({ __typeof__ (a) _a = (a); \
122
+ __typeof__ (b) _b = (b); \
123
+ _a < _b ? _a : _b; })
124
+ #endif
125
+ #ifndef max
126
+ #define max (a,b ) \
127
+ ({ __typeof__ (a) _a = (a); \
128
+ __typeof__ (b) _b = (b); \
129
+ _a > _b ? _a : _b; })
130
+ #endif
131
+ #endif
101
132
102
- /// conflict with STL min/max
103
- #define min (a ,b ) ((a)<(b)?(a):(b))
104
- #define max (a ,b ) ((a)>(b)?(a):(b))
105
133
#define abs (x ) ((x)>0 ?(x):-(x))
106
134
#define constrain (amt,low,high ) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
107
135
#define round (x ) ((x)>=0 ?(long )((x)+0.5 ):(long )((x)-0.5 ))
You can’t perform that action at this time.
0 commit comments