Skip to content

Commit 18f5095

Browse files
committed
minimize diff; fix missing paren
1 parent be460bc commit 18f5095

File tree

1 file changed

+46
-50
lines changed

1 file changed

+46
-50
lines changed

api/Common.h

Lines changed: 46 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -37,92 +37,63 @@ typedef enum {
3737
#define SERIAL 0x0
3838
#define DISPLAY 0x1
3939

40-
#ifdef __cplusplus
41-
} // extern "C"
42-
#endif
4340

4441
#ifdef __cplusplus
42+
} // extern "C"
4543

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>
6045
auto constrain(const T& amt, const U& low, const V& high) -> decltype(amt < low ? low : (amt > high ? high : amt))
6146
{
6247
return amt < low ? low : (amt > high ? high : amt);
6348
}
64-
65-
template<class T>
49+
50+
template<class T>
6651
auto radians(const T& deg) -> decltype(deg * DEG_TO_RAD)
6752
{
6853
return deg * DEG_TO_RAD;
6954
}
7055

71-
template<class T>
56+
template<class T>
7257
auto degrees(const T& rad) -> decltype(rad * RAD_TO_DEG)
7358
{
7459
return rad * RAD_TO_DEG;
7560
}
7661

77-
template<class T>
62+
template<class T>
7863
auto sq(const T& x) -> decltype(x*x)
7964
{
8065
return x*x;
8166
}
8267
#else
8368
#ifndef constrain
8469
#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); })
8974
#endif
90-
75+
9176
#ifndef radians
9277
#define radians(deg) \
93-
({ __typeof__ (deg) _deg = deg; \
94-
_deg * DEG_TO_RAD; })
78+
({ __typeof__ (deg) _deg = deg; \
79+
_deg * DEG_TO_RAD; })
9580
#endif
96-
81+
9782
#ifndef degrees
9883
#define degrees(rad) \
99-
({ __typeof__ (rad) _rad = rad; \
100-
_rad * RAD_TO_DEG; })
84+
({ __typeof__ (rad) _rad = rad; \
85+
_rad * RAD_TO_DEG; })
10186
#endif
102-
87+
10388
#ifndef sq
10489
#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; })
12192
#endif
12293
#endif
12394

12495
#ifdef __cplusplus
125-
extern "C"{
96+
extern "C" {
12697
#endif
12798

12899
typedef void (*voidFuncPtr)(void);
@@ -189,8 +160,32 @@ void loop(void);
189160

190161
#ifdef __cplusplus
191162
} // extern "C"
192-
#endif
193163

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
194189

195190
#ifdef __cplusplus
196191

@@ -213,3 +208,4 @@ void randomSeed(unsigned long);
213208
long map(long, long, long, long, long);
214209

215210
#endif // __cplusplus
211+

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy