CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Functions
approx_atan2.h File Reference
#include <cstdint>
#include <cmath>
#include <limits>
#include <algorithm>

Go to the source code of this file.

Functions

template<int DEGREE>
constexpr float approx_atan2f_P (float x)
 
template<>
constexpr float approx_atan2f_P< 11 > (float x)
 
template<>
constexpr float approx_atan2f_P< 13 > (float x)
 
template<>
constexpr float approx_atan2f_P< 15 > (float x)
 
template<>
constexpr float approx_atan2f_P< 3 > (float x)
 
template<>
constexpr float approx_atan2f_P< 5 > (float x)
 
template<>
constexpr float approx_atan2f_P< 7 > (float x)
 
template<>
constexpr float approx_atan2f_P< 9 > (float x)
 
template<int DEGREE>
constexpr float approx_atan2i_P (float x)
 
template<>
constexpr float approx_atan2i_P< 11 > (float x)
 
template<>
constexpr float approx_atan2i_P< 13 > (float x)
 
template<>
constexpr float approx_atan2i_P< 15 > (float x)
 
template<>
constexpr float approx_atan2i_P< 3 > (float x)
 
template<>
constexpr float approx_atan2i_P< 5 > (float x)
 
template<>
constexpr float approx_atan2i_P< 7 > (float x)
 
template<>
constexpr float approx_atan2i_P< 9 > (float x)
 
template<int DEGREE>
constexpr float approx_atan2s_P (float x)
 
template<>
constexpr float approx_atan2s_P< 3 > (float x)
 
template<>
constexpr float approx_atan2s_P< 5 > (float x)
 
template<>
constexpr float approx_atan2s_P< 7 > (float x)
 
template<>
constexpr float approx_atan2s_P< 9 > (float x)
 
constexpr double int2dphi (int x)
 
constexpr float int2phi (int x)
 
constexpr int phi2int (float x)
 
constexpr short phi2short (float x)
 
template<int DEGREE>
constexpr float safe_atan2f (float y, float x)
 
constexpr float short2phi (short x)
 
template<int DEGREE>
constexpr float unsafe_atan2f (float y, float x)
 
template<int DEGREE>
constexpr float unsafe_atan2f_impl (float y, float x)
 
template<int DEGREE>
constexpr int unsafe_atan2i (float y, float x)
 
template<int DEGREE>
constexpr int unsafe_atan2i_impl (float y, float x)
 
template<int DEGREE>
constexpr short unsafe_atan2s (float y, float x)
 
template<int DEGREE>
constexpr short unsafe_atan2s_impl (float y, float x)
 

Function Documentation

template<int DEGREE>
constexpr float approx_atan2f_P ( float  x)
template<>
constexpr float approx_atan2f_P< 11 > ( float  x)

Definition at line 71 of file approx_atan2.h.

References x, and detailsBasic3DVector::z.

71  {
72  auto z = x * x;
73  return x * (float(-0xf.ffe82p-4) +
74  z * (float(0x5.526c8p-4) +
75  z * (float(-0x3.18bea8p-4) +
76  z * (float(0x1.dce3bcp-4) + z * (float(-0xd.7a64ap-8) + z * float(0x3.000eap-8))))));
77 }
float float float z
float x
template<>
constexpr float approx_atan2f_P< 13 > ( float  x)

Definition at line 81 of file approx_atan2.h.

References x, and detailsBasic3DVector::z.

81  {
82  auto z = x * x;
83  return x * (float(-0xf.fffbep-4) +
84  z * (float(0x5.54adp-4) +
85  z * (float(-0x3.2b4df8p-4) +
86  z * (float(0x2.1df79p-4) +
87  z * (float(-0x1.46081p-4) + z * (float(0x8.99028p-8) + z * float(-0x1.be0bc4p-8)))))));
88 }
float float float z
float x
template<>
constexpr float approx_atan2f_P< 15 > ( float  x)

Definition at line 92 of file approx_atan2.h.

References x, and detailsBasic3DVector::z.

92  {
93  auto z = x * x;
94  return x * (float(-0xf.ffff4p-4) +
95  z * (float(0x5.552f9p-4 + z * (float(-0x3.30f728p-4) +
96  z * (float(0x2.39826p-4) +
97  z * (float(-0x1.8a880cp-4) +
98  z * (float(0xe.484d6p-8) +
99  z * (float(-0x5.93d5p-8) + z * float(0x1.0875dcp-8)))))))));
100 }
float float float z
float x
template<>
constexpr float approx_atan2f_P< 3 > ( float  x)

Definition at line 42 of file approx_atan2.h.

References x.

42  {
43  return x * (float(-0xf.8eed2p-4) + x * x * float(0x3.1238p-4));
44 }
float x
template<>
constexpr float approx_atan2f_P< 5 > ( float  x)

Definition at line 48 of file approx_atan2.h.

References x, and detailsBasic3DVector::z.

48  {
49  auto z = x * x;
50  return x * (float(-0xf.ecfc8p-4) + z * (float(0x4.9e79dp-4) + z * float(-0x1.44f924p-4)));
51 }
float float float z
float x
template<>
constexpr float approx_atan2f_P< 7 > ( float  x)

Definition at line 55 of file approx_atan2.h.

References x, and detailsBasic3DVector::z.

55  {
56  auto z = x * x;
57  return x * (float(-0xf.fcc7ap-4) + z * (float(0x5.23886p-4) + z * (float(-0x2.571968p-4) + z * float(0x9.fb05p-8))));
58 }
float float float z
float x
template<>
constexpr float approx_atan2f_P< 9 > ( float  x)

Definition at line 62 of file approx_atan2.h.

References x, and detailsBasic3DVector::z.

62  {
63  auto z = x * x;
64  return x * (float(-0xf.ff73ep-4) +
65  z * (float(0x5.48ee1p-4) +
66  z * (float(-0x2.e1efe8p-4) + z * (float(0x1.5cce54p-4) + z * float(-0x5.56245p-8)))));
67 }
float float float z
float x
template<int DEGREE>
constexpr float approx_atan2i_P ( float  x)
template<>
constexpr float approx_atan2i_P< 11 > ( float  x)

Definition at line 168 of file approx_atan2.h.

References x, and detailsBasic3DVector::z.

168  {
169  auto z = x * x;
170  return x *
171  (-683549696.f + z * (227369312.f + z * (-132297008.f + z * (79584144.f + z * (-35987016.f + z * 8010488.f)))));
172 }
float float float z
float x
template<>
constexpr float approx_atan2i_P< 13 > ( float  x)

Definition at line 176 of file approx_atan2.h.

References x, and detailsBasic3DVector::z.

176  {
177  auto z = x * x;
178  return x * (-683562624.f +
179  z * (227746080.f +
180  z * (-135400128.f + z * (90460848.f + z * (-54431464.f + z * (22973256.f + z * (-4657049.f)))))));
181 }
float float float z
float x
template<>
constexpr float approx_atan2i_P< 15 > ( float  x)

Definition at line 184 of file approx_atan2.h.

References x, and detailsBasic3DVector::z.

184  {
185  auto z = x * x;
186  return x * (-683562624.f +
187  z * (227746080.f +
188  z * (-135400128.f + z * (90460848.f + z * (-54431464.f + z * (22973256.f + z * (-4657049.f)))))));
189 }
float float float z
float x
template<>
constexpr float approx_atan2i_P< 3 > ( float  x)

Definition at line 140 of file approx_atan2.h.

References x, and detailsBasic3DVector::z.

140  {
141  auto z = x * x;
142  return x * (-664694912.f + z * 131209024.f);
143 }
float float float z
float x
template<>
constexpr float approx_atan2i_P< 5 > ( float  x)

Definition at line 147 of file approx_atan2.h.

References x, and detailsBasic3DVector::z.

147  {
148  auto z = x * x;
149  return x * (-680392064.f + z * (197338400.f + z * (-54233256.f)));
150 }
float float float z
float x
template<>
constexpr float approx_atan2i_P< 7 > ( float  x)

Definition at line 154 of file approx_atan2.h.

References x, and detailsBasic3DVector::z.

154  {
155  auto z = x * x;
156  return x * (-683027840.f + z * (219543904.f + z * (-99981040.f + z * 26649684.f)));
157 }
float float float z
float x
template<>
constexpr float approx_atan2i_P< 9 > ( float  x)

Definition at line 161 of file approx_atan2.h.

References x, and detailsBasic3DVector::z.

161  {
162  auto z = x * x;
163  return x * (-683473920.f + z * (225785056.f + z * (-123151184.f + z * (58210592.f + z * (-14249276.f)))));
164 }
float float float z
float x
template<int DEGREE>
constexpr float approx_atan2s_P ( float  x)
template<>
constexpr float approx_atan2s_P< 3 > ( float  x)

Definition at line 220 of file approx_atan2.h.

References validate-o2o-wbm::f, x, and detailsBasic3DVector::z.

220  {
221  auto z = x * x;
222  return x * ((-10142.439453125f) + z * 2002.0908203125f);
223 }
float float float z
float x
template<>
constexpr float approx_atan2s_P< 5 > ( float  x)

Definition at line 226 of file approx_atan2.h.

References validate-o2o-wbm::f, x, and detailsBasic3DVector::z.

226  {
227  auto z = x * x;
228  return x * ((-10381.9609375f) + z * ((3011.1513671875f) + z * (-827.538330078125f)));
229 }
float float float z
float x
template<>
constexpr float approx_atan2s_P< 7 > ( float  x)

Definition at line 232 of file approx_atan2.h.

References validate-o2o-wbm::f, x, and detailsBasic3DVector::z.

232  {
233  auto z = x * x;
234  return x * ((-10422.177734375f) + z * (3349.97412109375f + z * ((-1525.589599609375f) + z * 406.64190673828125f)));
235 }
float float float z
float x
template<>
constexpr float approx_atan2s_P< 9 > ( float  x)

Definition at line 238 of file approx_atan2.h.

References validate-o2o-wbm::f, x, and detailsBasic3DVector::z.

238  {
239  auto z = x * x;
240  return x * ((-10428.984375f) + z * (3445.20654296875f + z * ((-1879.137939453125f) +
241  z * (888.22314453125f + z * (-217.42669677734375f)))));
242 }
float float float z
float x
constexpr double int2dphi ( int  x)

Definition at line 275 of file approx_atan2.h.

References mkfit::LL, M_PI, and SiStripPI::max.

275  {
276  constexpr double i2p = M_PI / ((long long)(std::numeric_limits<int>::max()) + 1LL);
277  return x * i2p;
278 }
constexpr Matriplex::idx_t LL
Definition: Matrix.h:45
#define M_PI
float x
constexpr float int2phi ( int  x)

Definition at line 270 of file approx_atan2.h.

References mkfit::LL, M_PI, and SiStripPI::max.

270  {
271  constexpr float i2p = M_PI / ((long long)(std::numeric_limits<int>::max()) + 1LL);
272  return float(x) * i2p;
273 }
constexpr Matriplex::idx_t LL
Definition: Matrix.h:45
#define M_PI
float x
constexpr int phi2int ( float  x)

Definition at line 265 of file approx_atan2.h.

References mkfit::LL, M_PI, and SiStripPI::max.

265  {
266  constexpr float p2i = ((long long)(std::numeric_limits<int>::max()) + 1LL) / M_PI;
267  return std::round(x * p2i);
268 }
constexpr Matriplex::idx_t LL
Definition: Matrix.h:45
#define M_PI
float x
constexpr short phi2short ( float  x)

Definition at line 280 of file approx_atan2.h.

References M_PI, and SiStripPI::max.

280  {
281  constexpr float p2i = ((int)(std::numeric_limits<short>::max()) + 1) / M_PI;
282  return std::round(x * p2i);
283 }
#define M_PI
float x
template<int DEGREE>
constexpr float safe_atan2f ( float  y,
float  x 
)

Definition at line 123 of file approx_atan2.h.

References validate-o2o-wbm::f, and detailsBasic3DVector::y.

123  {
124  return unsafe_atan2f_impl<DEGREE>(y, ((y == 0.f) & (x == 0.f)) ? 0.2f : x);
125  // return (y==0.f)&(x==0.f) ? 0.f : unsafe_atan2f_impl<DEGREE>( y, x);
126 }
float x
constexpr float short2phi ( short  x)

Definition at line 285 of file approx_atan2.h.

References M_PI, and SiStripPI::max.

Referenced by SiPixelPhase1MonitorRecHitsSoA::analyze(), and gpuPixelDoublets::for().

285  {
286  constexpr float i2p = M_PI / ((int)(std::numeric_limits<short>::max()) + 1);
287  return float(x) * i2p;
288 }
#define M_PI
float x
template<int DEGREE>
constexpr float unsafe_atan2f ( float  y,
float  x 
)

Definition at line 118 of file approx_atan2.h.

References x, and detailsBasic3DVector::y.

118  {
119  return unsafe_atan2f_impl<DEGREE>(y, x);
120 }
float x
template<int DEGREE>
constexpr float unsafe_atan2f_impl ( float  y,
float  x 
)

Definition at line 103 of file approx_atan2.h.

References funct::abs(), angle(), and alignCSCRings::r.

103  {
104  constexpr float pi4f = 3.1415926535897932384626434 / 4;
105  constexpr float pi34f = 3.1415926535897932384626434 * 3 / 4;
106 
107  auto r = (std::abs(x) - std::abs(y)) / (std::abs(x) + std::abs(y));
108  if (x < 0)
109  r = -r;
110 
111  auto angle = (x >= 0) ? pi4f : pi34f;
112  angle += approx_atan2f_P<DEGREE>(r);
113 
114  return ((y < 0)) ? -angle : angle;
115 }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
float x
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11
template<int DEGREE>
constexpr int unsafe_atan2i ( float  y,
float  x 
)

Definition at line 209 of file approx_atan2.h.

References x, and detailsBasic3DVector::y.

209  {
210  return unsafe_atan2i_impl<DEGREE>(y, x);
211 }
float x
template<int DEGREE>
constexpr int unsafe_atan2i_impl ( float  y,
float  x 
)

Definition at line 192 of file approx_atan2.h.

References funct::abs(), angle(), mkfit::LL, SiStripPI::max, and alignCSCRings::r.

192  {
193  constexpr long long maxint = (long long)(std::numeric_limits<int>::max()) + 1LL;
194  constexpr int pi4 = int(maxint / 4LL);
195  constexpr int pi34 = int(3LL * maxint / 4LL);
196 
197  auto r = (std::abs(x) - std::abs(y)) / (std::abs(x) + std::abs(y));
198  if (x < 0)
199  r = -r;
200 
201  auto angle = (x >= 0) ? pi4 : pi34;
202  angle += int(approx_atan2i_P<DEGREE>(r));
203  // angle += int(std::round(approx_atan2i_P<DEGREE>(r)));
204 
205  return (y < 0) ? -angle : angle;
206 }
constexpr Matriplex::idx_t LL
Definition: Matrix.h:45
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
float x
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11
template<int DEGREE>
constexpr short unsafe_atan2s ( float  y,
float  x 
)

Definition at line 261 of file approx_atan2.h.

References x, and detailsBasic3DVector::y.

261  {
262  return unsafe_atan2s_impl<DEGREE>(y, x);
263 }
float x
template<int DEGREE>
constexpr short unsafe_atan2s_impl ( float  y,
float  x 
)

Definition at line 245 of file approx_atan2.h.

References funct::abs(), angle(), SiStripPI::max, and alignCSCRings::r.

245  {
246  constexpr int maxshort = (int)(std::numeric_limits<short>::max()) + 1;
247  constexpr short pi4 = short(maxshort / 4);
248  constexpr short pi34 = short(3 * maxshort / 4);
249 
250  auto r = (std::abs(x) - std::abs(y)) / (std::abs(x) + std::abs(y));
251  if (x < 0)
252  r = -r;
253 
254  auto angle = (x >= 0) ? pi4 : pi34;
255  angle += short(approx_atan2s_P<DEGREE>(r));
256 
257  return (y < 0) ? -angle : angle;
258 }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
float x
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11