File tree 1 file changed +27
-2
lines changed
1 file changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -85,8 +85,33 @@ void suspendLoop(void);
85
85
#undef abs
86
86
#endif // abs
87
87
88
- #define min (a ,b ) ((a)<(b)?(a):(b))
89
- #define max (a ,b ) ((a)>(b)?(a):(b))
88
+ #ifdef __cplusplus
89
+ template <class T , class L >
90
+ auto min (const T& a, const L& b) -> decltype((b < a) ? b : a)
91
+ {
92
+ return (b < a) ? b : a;
93
+ }
94
+
95
+ template <class T , class L >
96
+ auto max (const T& a, const L& b) -> decltype((b < a) ? b : a)
97
+ {
98
+ return (a < b) ? b : a;
99
+ }
100
+ #else
101
+ #ifndef min
102
+ #define min (a,b ) \
103
+ ({ __typeof__ (a) _a = (a); \
104
+ __typeof__ (b) _b = (b); \
105
+ _a < _b ? _a : _b; })
106
+ #endif
107
+ #ifndef max
108
+ #define max (a,b ) \
109
+ ({ __typeof__ (a) _a = (a); \
110
+ __typeof__ (b) _b = (b); \
111
+ _a > _b ? _a : _b; })
112
+ #endif
113
+ #endif
114
+
90
115
#define abs (x ) ((x)>0 ?(x):-(x))
91
116
#define constrain (amt,low,high ) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
92
117
#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