cmath.h: convert AVR min/max/abs into templates
At least for min/max this will ensure types for both arguments are the same. This should be a little bit closer to the <cmath> definition that simply overloads these functions instead.pull/47/head
parent
98845008aa
commit
fcb1b0c85d
17
src/cmath.h
17
src/cmath.h
|
|
@ -10,8 +10,19 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
// Use builtin functions for min/max/abs
|
// Use builtin functions for min/max/abs
|
||||||
#define min(a, b) __builtin_min((a, b))
|
template <typename T>
|
||||||
#define max(a, b) __builtin_max((a, b))
|
static inline const T min(T a, T b) {
|
||||||
#define abs(n) __builtin_abs((n))
|
return __builtin_min((a, b));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
static inline const T max(T a, T b) {
|
||||||
|
return __builtin_max((a, b));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
static inline const T abs(T n) {
|
||||||
|
return __builtin_abs((n));
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue