1 #ifndef __SDR_MATH_HH__
2 #define __SDR_MATH_HH__
9 template <
class iScalar,
class oScalar> oScalar fast_atan2(iScalar a, iScalar b);
12 template <>
inline int16_t fast_atan2<int8_t, int16_t>(int8_t a, int8_t b) {
13 const int32_t pi4 = (1<<12);
14 const int32_t pi34 = 3*(1<<12);
16 if ((0 == a) && (0 == b)) {
return 0; }
17 aabs = (a >= 0) ? a : -a;
18 if (b >= 0) { angle = pi4 - pi4*(b-aabs) / (b+aabs); }
19 else { angle = pi34 - pi4*(b+aabs) / (aabs-b); }
20 return (a >= 0) ? angle : -angle;
24 template <>
inline int16_t fast_atan2<uint8_t, int16_t>(uint8_t ua, uint8_t ub) {
25 int8_t a = (int16_t(ua)-(1<<7));
26 int8_t b = (int16_t(ub)-(1<<7));
27 return fast_atan2<int8_t, int16_t>(a,b);
31 template <>
inline int16_t fast_atan2<int16_t, int16_t>(int16_t a, int16_t b) {
33 const int32_t pi4 = (1<<12);
34 const int32_t pi34 = 3*(1<<12);
36 if ((0 == a) && (0 == b)) {
return 0; }
37 aabs = (a >= 0) ? a : -a;
38 if (b >= 0) { angle = pi4 - pi4*(b-aabs) / (b+aabs); }
39 else { angle = pi34 - pi4*(b+aabs) / (aabs-b); }
40 return (a >= 0) ? angle : -angle;
Definition: autocast.hh:8