@@ -44,22 +44,22 @@ typedef enum {
44
44
#ifdef __cplusplus
45
45
46
46
template <class T , class L >
47
- auto min (const T& a, const L& b) -> decltype(( b < a) ? b : a)
47
+ auto min (const T& a, const L& b) -> decltype(b < a ? b : a)
48
48
{
49
49
return (b < a) ? b : a;
50
50
}
51
51
52
52
template <class T , class L >
53
- auto max (const T& a, const L& b) -> decltype(( b < a) ? b : a)
53
+ auto max (const T& a, const L& b) -> decltype(b < a ? b : a)
54
54
{
55
55
return (a < b) ? b : a;
56
56
}
57
57
58
58
59
59
template <class T , class U , class V >
60
- auto constrain (const T& amt, const U& low, const V& high) -> decltype(( amt)<( low)?( low):(( amt)>( high)?( high):( amt) ))
60
+ auto constrain (const T& amt, const U& low, const V& high) -> decltype(amt < low ? low : ( amt > high ? high : amt))
61
61
{
62
- return ( amt)<( low)?( low):(( amt)>( high)?( high):( amt) );
62
+ return amt < low ? low : ( amt > high ? high : amt);
63
63
}
64
64
65
65
template <class T >
@@ -81,19 +81,29 @@ typedef enum {
81
81
}
82
82
#else
83
83
#ifndef constrain
84
- #define constrain (amt,low,high ) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
84
+ #define constrain (amt,low,high ) \
85
+ ({ __typeof__ (amt) _amt = (amt); \
86
+ __typeof__ (low) _low = (low); \
87
+ __typeof__ (high) _high = (high); \
88
+ _amt < _low ? _low : (_amt > _high ? _high :_amt); }
85
89
#endif
86
90
87
91
#ifndef radians
88
- #define radians (deg ) ((deg)*DEG_TO_RAD)
92
+ #define radians (deg ) \
93
+ ({ __typeof__ (deg) _deg = deg; \
94
+ _deg * DEG_TO_RAD; })
89
95
#endif
90
96
91
97
#ifndef degrees
92
- #define degrees (rad ) ((rad)*RAD_TO_DEG)
98
+ #define degrees (rad ) \
99
+ ({ __typeof__ (rad) _rad = rad; \
100
+ _rad * RAD_TO_DEG; })
93
101
#endif
94
102
95
103
#ifndef sq
96
- #define sq (x ) ((x)*(x))
104
+ #define sq (x ) \
105
+ ({ __typeof__ (x) _x = x; \
106
+ _x * _x; })
97
107
#endif
98
108
99
109
#ifndef min
0 commit comments