@@ -37,92 +37,63 @@ typedef enum {
37
37
#define SERIAL 0x0
38
38
#define DISPLAY 0x1
39
39
40
- #ifdef __cplusplus
41
- } // extern "C"
42
- #endif
43
40
44
41
#ifdef __cplusplus
42
+ } // extern "C"
45
43
46
- template <class T , class L >
47
- auto min (const T& a, const L& b) -> decltype(b < a ? b : a)
48
- {
49
- return (b < a) ? b : a;
50
- }
51
-
52
- template <class T , class L >
53
- auto max (const T& a, const L& b) -> decltype(b < a ? b : a)
54
- {
55
- return (a < b) ? b : a;
56
- }
57
-
58
-
59
- template <class T , class U , class V >
44
+ template <class T , class U , class V >
60
45
auto constrain (const T& amt, const U& low, const V& high) -> decltype(amt < low ? low : (amt > high ? high : amt))
61
46
{
62
47
return amt < low ? low : (amt > high ? high : amt);
63
48
}
64
-
65
- template <class T >
49
+
50
+ template <class T >
66
51
auto radians (const T& deg) -> decltype(deg * DEG_TO_RAD)
67
52
{
68
53
return deg * DEG_TO_RAD;
69
54
}
70
55
71
- template <class T >
56
+ template <class T >
72
57
auto degrees (const T& rad) -> decltype(rad * RAD_TO_DEG)
73
58
{
74
59
return rad * RAD_TO_DEG;
75
60
}
76
61
77
- template <class T >
62
+ template <class T >
78
63
auto sq (const T& x) -> decltype(x*x)
79
64
{
80
65
return x*x;
81
66
}
82
67
#else
83
68
#ifndef constrain
84
69
#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); }
70
+ ({ __typeof__ (amt) _amt = (amt); \
71
+ __typeof__ (low) _low = (low); \
72
+ __typeof__ (high) _high = (high); \
73
+ _amt < _low ? _low : (_amt > _high ? _high :_amt); })
89
74
#endif
90
-
75
+
91
76
#ifndef radians
92
77
#define radians (deg ) \
93
- ({ __typeof__ (deg) _deg = deg; \
94
- _deg * DEG_TO_RAD; })
78
+ ({ __typeof__ (deg) _deg = deg; \
79
+ _deg * DEG_TO_RAD; })
95
80
#endif
96
-
81
+
97
82
#ifndef degrees
98
83
#define degrees (rad ) \
99
- ({ __typeof__ (rad) _rad = rad; \
100
- _rad * RAD_TO_DEG; })
84
+ ({ __typeof__ (rad) _rad = rad; \
85
+ _rad * RAD_TO_DEG; })
101
86
#endif
102
-
87
+
103
88
#ifndef sq
104
89
#define sq (x ) \
105
- ({ __typeof__ (x) _x = x; \
106
- _x * _x; })
107
- #endif
108
-
109
- #ifndef min
110
- #define min (a,b ) \
111
- ({ __typeof__ (a) _a = (a); \
112
- __typeof__ (b) _b = (b); \
113
- _a < _b ? _a : _b; })
114
- #endif
115
-
116
- #ifndef max
117
- #define max (a,b ) \
118
- ({ __typeof__ (a) _a = (a); \
119
- __typeof__ (b) _b = (b); \
120
- _a > _b ? _a : _b; })
90
+ ({ __typeof__ (x) _x = x; \
91
+ _x * _x; })
121
92
#endif
122
93
#endif
123
94
124
95
#ifdef __cplusplus
125
- extern " C" {
96
+ extern " C" {
126
97
#endif
127
98
128
99
typedef void (*voidFuncPtr)(void );
@@ -189,8 +160,32 @@ void loop(void);
189
160
190
161
#ifdef __cplusplus
191
162
} // extern "C"
192
- #endif
193
163
164
+ template <class T , class L >
165
+ auto min (const T& a, const L& b) -> decltype((b < a) ? b : a)
166
+ {
167
+ return (b < a) ? b : a;
168
+ }
169
+
170
+ template <class T , class L >
171
+ auto max (const T& a, const L& b) -> decltype((b < a) ? b : a)
172
+ {
173
+ return (a < b) ? b : a;
174
+ }
175
+ #else
176
+ #ifndef min
177
+ #define min (a,b ) \
178
+ ({ __typeof__ (a) _a = (a); \
179
+ __typeof__ (b) _b = (b); \
180
+ _a < _b ? _a : _b; })
181
+ #endif
182
+ #ifndef max
183
+ #define max (a,b ) \
184
+ ({ __typeof__ (a) _a = (a); \
185
+ __typeof__ (b) _b = (b); \
186
+ _a > _b ? _a : _b; })
187
+ #endif
188
+ #endif
194
189
195
190
#ifdef __cplusplus
196
191
@@ -213,3 +208,4 @@ void randomSeed(unsigned long);
213
208
long map (long , long , long , long , long );
214
209
215
210
#endif // __cplusplus
211
+
0 commit comments