@@ -37,20 +37,82 @@ typedef enum {
37
37
#define SERIAL 0x0
38
38
#define DISPLAY 0x1
39
39
40
- #ifndef constrain
41
- # define constrain ( amt,low,high ) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
40
+ #ifdef __cplusplus
41
+ } // extern "C"
42
42
#endif
43
43
44
- #ifndef radians
45
- #define radians (deg ) ((deg)*DEG_TO_RAD)
46
- #endif
44
+ #ifdef __cplusplus
45
+
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 >
60
+ auto constrain (const T& amt, const U& low, const V& high) -> decltype((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
61
+ {
62
+ return (amt)<(low)?(low):((amt)>(high)?(high):(amt));
63
+ }
64
+
65
+ template <class T >
66
+ auto radians (const T& deg) -> decltype(deg * DEG_TO_RAD)
67
+ {
68
+ return deg * DEG_TO_RAD;
69
+ }
70
+
71
+ template <class T >
72
+ auto degrees (const T& rad) -> decltype(rad * RAD_TO_DEG)
73
+ {
74
+ return rad * RAD_TO_DEG;
75
+ }
47
76
48
- #ifndef degrees
49
- #define degrees (rad ) ((rad)*RAD_TO_DEG)
77
+ template <class T >
78
+ auto sq (const T& x) -> decltype(x*x)
79
+ {
80
+ return x*x;
81
+ }
82
+ #else
83
+ #ifndef constrain
84
+ #define constrain (amt,low,high ) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
85
+ #endif
86
+
87
+ #ifndef radians
88
+ #define radians (deg ) ((deg)*DEG_TO_RAD)
89
+ #endif
90
+
91
+ #ifndef degrees
92
+ #define degrees (rad ) ((rad)*RAD_TO_DEG)
93
+ #endif
94
+
95
+ #ifndef sq
96
+ #define sq (x ) ((x)*(x))
97
+ #endif
98
+
99
+ #ifndef min
100
+ #define min (a,b ) \
101
+ ({ __typeof__ (a) _a = (a); \
102
+ __typeof__ (b) _b = (b); \
103
+ _a < _b ? _a : _b; })
104
+ #endif
105
+
106
+ #ifndef max
107
+ #define max (a,b ) \
108
+ ({ __typeof__ (a) _a = (a); \
109
+ __typeof__ (b) _b = (b); \
110
+ _a > _b ? _a : _b; })
111
+ #endif
50
112
#endif
51
113
52
- #ifndef sq
53
- # define sq ( x ) ((x)*(x))
114
+ #ifdef __cplusplus
115
+ extern " C " {
54
116
#endif
55
117
56
118
typedef void (*voidFuncPtr)(void );
@@ -119,32 +181,6 @@ void loop(void);
119
181
} // extern "C"
120
182
#endif
121
183
122
- #ifdef __cplusplus
123
- template <class T , class L >
124
- auto min (const T& a, const L& b) -> decltype((b < a) ? b : a)
125
- {
126
- return (b < a) ? b : a;
127
- }
128
-
129
- template <class T , class L >
130
- auto max (const T& a, const L& b) -> decltype((b < a) ? b : a)
131
- {
132
- return (a < b) ? b : a;
133
- }
134
- #else
135
- #ifndef min
136
- #define min (a,b ) \
137
- ({ __typeof__ (a) _a = (a); \
138
- __typeof__ (b) _b = (b); \
139
- _a < _b ? _a : _b; })
140
- #endif
141
- #ifndef max
142
- #define max (a,b ) \
143
- ({ __typeof__ (a) _a = (a); \
144
- __typeof__ (b) _b = (b); \
145
- _a > _b ? _a : _b; })
146
- #endif
147
- #endif
148
184
149
185
#ifdef __cplusplus
150
186
0 commit comments