PaulStoffregen 7 years ago
parent
commit
771ce665a0
1 changed files with 26 additions and 13 deletions
  1. +26
    -13
      teensy3/wiring.h

+ 26
- 13
teensy3/wiring.h View File

{ {
return (x - (T)in_min) * ((T)out_max - (T)out_min) / ((T)in_max - (T)in_min) + (T)out_min; return (x - (T)in_min) * ((T)out_max - (T)out_min) / ((T)in_max - (T)in_min) + (T)out_min;
} }
#include <algorithm> // c++ min, max
#include <utility>
// https://forum.pjrc.com/threads/44596-Teensyduino-1-37-Beta-2-(Arduino-1-8-3-support)?p=145150&viewfull=1#post145150
template<class A, class B>
constexpr auto min(A&& a, B&& b) -> decltype(a < b ? std::forward<A>(a) : std::forward<B>(b)) {
return a < b ? std::forward<A>(a) : std::forward<B>(b);
}
template<class A, class B>
constexpr auto max(A&& a, B&& b) -> decltype(a < b ? std::forward<A>(a) : std::forward<B>(b)) {
return a >= b ? std::forward<A>(a) : std::forward<B>(b);
}
#else // not C++
#define min(a, b) ({ \
typeof(a) _a = (a); \
typeof(b) _b = (b); \
(_a < _b) ? _a : _b; \
})
#define max(a, b) ({ \
typeof(a) _a = (a); \
typeof(b) _b = (b); \
(_a > _b) ? _a : _b; \
})
#endif #endif


#ifdef __cplusplus
extern "C"{
#endif


#ifdef PI #ifdef PI
#undef PI #undef PI
#define typeof(a) decltype(a) #define typeof(a) decltype(a)
#endif #endif


#define min(a, b) ({ \
typeof(a) _a = (a); \
typeof(b) _b = (b); \
(_a < _b) ? _a : _b; \
})
#define max(a, b) ({ \
typeof(a) _a = (a); \
typeof(b) _b = (b); \
(_a > _b) ? _a : _b; \
})
#define abs(x) ({ \ #define abs(x) ({ \
typeof(x) _x = (x); \ typeof(x) _x = (x); \
(_x > 0) ? _x : -_x; \ (_x > 0) ? _x : -_x; \
_x * _x; \ _x * _x; \
}) })


#ifdef __cplusplus
extern "C"{
#endif

extern double exp10(double x); extern double exp10(double x);
extern float exp10f(float x); extern float exp10f(float x);
extern long double exp10l(long double x); extern long double exp10l(long double x);

Loading…
Cancel
Save