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 28
28
#undef abs
29
29
#endif // abs
30
30
31
- #define min (a , b ) ((a) < (b) ? (a) : (b))
32
- #define max (a , b ) ((a) > (b) ? (a) : (b))
31
+ #ifdef __cplusplus
32
+ template <class T , class L >
33
+ auto min (const T& a, const L& b) -> decltype((b < a) ? b : a)
34
+ {
35
+ return (b < a) ? b : a;
36
+ }
37
+
38
+ template <class T , class L >
39
+ auto max (const T& a, const L& b) -> decltype((b < a) ? b : a)
40
+ {
41
+ return (a < b) ? b : a;
42
+ }
43
+ #else
44
+ #ifndef min
45
+ #define min (a,b ) \
46
+ ({ __typeof__ (a) _a = (a); \
47
+ __typeof__ (b) _b = (b); \
48
+ _a < _b ? _a : _b; })
49
+ #endif
50
+ #ifndef max
51
+ #define max (a,b ) \
52
+ ({ __typeof__ (a) _a = (a); \
53
+ __typeof__ (b) _b = (b); \
54
+ _a > _b ? _a : _b; })
55
+ #endif
56
+ #endif
57
+
33
58
#define abs (x ) ((x) > 0 ? (x) : -(x))
34
59
#define constrain (amt, low, high ) ((amt) < (low) ? (low) : ((amt) > (high) ? (high) : (amt)))
35
60
#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