CMS 3D CMS Logo

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 69 of file approx_atan2.h.

References objects.autophobj::float, genVertex_cff::x, globals_cff::x1, and detailsBasic3DVector::z.

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

Definition at line 75 of file approx_atan2.h.

References objects.autophobj::float, genVertex_cff::x, globals_cff::x1, globals_cff::x2, and detailsBasic3DVector::z.

75  {
76  auto z = x*x;
77  return x * (float(-0xf.fffbep-4) + z * (float(0x5.54adp-4) + z * (float(-0x3.2b4df8p-4) + z * (float(0x2.1df79p-4) + z * (float(-0x1.46081p-4) + z * (float(0x8.99028p-8) + z * float(-0x1.be0bc4p-8))))))) ;
78 }
float float float z
template<>
constexpr float approx_atan2f_P< 15 > ( float  x)

Definition at line 81 of file approx_atan2.h.

References objects.autophobj::float, genVertex_cff::x, globals_cff::x1, globals_cff::x2, and detailsBasic3DVector::z.

81  {
82  auto z = x*x;
83  return x * (float(-0xf.ffff4p-4) + z * (float(0x5.552f9p-4 + z * (float(-0x3.30f728p-4) + z * (float(0x2.39826p-4) + z * (float(-0x1.8a880cp-4) + z * (float(0xe.484d6p-8) + z * (float(-0x5.93d5p-8) + z * float(0x1.0875dcp-8)))))))));
84 }
float float float z
template<>
constexpr float approx_atan2f_P< 3 > ( float  x)

Definition at line 46 of file approx_atan2.h.

References objects.autophobj::float, and genVertex_cff::x.

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

Definition at line 51 of file approx_atan2.h.

References objects.autophobj::float, genVertex_cff::x, globals_cff::x1, and detailsBasic3DVector::z.

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

Definition at line 57 of file approx_atan2.h.

References objects.autophobj::float, genVertex_cff::x, globals_cff::x2, and detailsBasic3DVector::z.

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

Definition at line 63 of file approx_atan2.h.

References objects.autophobj::float, genVertex_cff::x, globals_cff::x1, globals_cff::x2, and detailsBasic3DVector::z.

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

Referenced by safe_atan2f().

template<>
constexpr float approx_atan2i_P< 11 > ( float  x)

Definition at line 154 of file approx_atan2.h.

References genVertex_cff::x, and detailsBasic3DVector::z.

154  {
155  auto z = x*x;
156  return x * (-683549696.f + z * (227369312.f + z * (-132297008.f + z * (79584144.f + z * (-35987016.f + z * 8010488.f)))));
157 }
float float float z
template<>
constexpr float approx_atan2i_P< 13 > ( float  x)

Definition at line 160 of file approx_atan2.h.

References genVertex_cff::x, and detailsBasic3DVector::z.

160  {
161  auto z = x*x;
162  return x * (-683562624.f + z * (227746080.f + z * (-135400128.f + z * (90460848.f + z * (-54431464.f + z * (22973256.f + z * (-4657049.f)))))));
163 }
float float float z
template<>
constexpr float approx_atan2i_P< 15 > ( float  x)

Definition at line 165 of file approx_atan2.h.

References genVertex_cff::x, and detailsBasic3DVector::z.

165  {
166  auto z = x*x;
167  return x * (-683562624.f + z * (227746080.f + z * (-135400128.f + z * (90460848.f + z * (-54431464.f + z * (22973256.f + z * (-4657049.f)))))));
168 }
float float float z
template<>
constexpr float approx_atan2i_P< 3 > ( float  x)

Definition at line 130 of file approx_atan2.h.

References genVertex_cff::x, and detailsBasic3DVector::z.

130  {
131  auto z = x*x;
132  return x * (-664694912.f + z * 131209024.f);
133 }
float float float z
template<>
constexpr float approx_atan2i_P< 5 > ( float  x)

Definition at line 136 of file approx_atan2.h.

References genVertex_cff::x, and detailsBasic3DVector::z.

136  {
137  auto z = x*x;
138  return x * (-680392064.f + z * (197338400.f + z * (-54233256.f)));
139 }
float float float z
template<>
constexpr float approx_atan2i_P< 7 > ( float  x)

Definition at line 142 of file approx_atan2.h.

References genVertex_cff::x, and detailsBasic3DVector::z.

142  {
143  auto z = x*x;
144  return x * (-683027840.f + z * (219543904.f + z * (-99981040.f + z * 26649684.f)));
145 }
float float float z
template<>
constexpr float approx_atan2i_P< 9 > ( float  x)

Definition at line 148 of file approx_atan2.h.

References genVertex_cff::x, and detailsBasic3DVector::z.

148  {
149  auto z = x*x;
150  return x * (-683473920.f + z * (225785056.f + z * (-123151184.f + z * (58210592.f + z * (-14249276.f)))));
151 }
float float float z
template<int DEGREE>
constexpr float approx_atan2s_P ( float  x)

Referenced by unsafe_atan2i().

template<>
constexpr float approx_atan2s_P< 3 > ( float  x)

Definition at line 206 of file approx_atan2.h.

References f, genVertex_cff::x, and detailsBasic3DVector::z.

206  {
207  auto z = x*x;
208  return x * ((-10142.439453125f) + z * 2002.0908203125f);
209 }
float float float z
double f[11][100]
template<>
constexpr float approx_atan2s_P< 5 > ( float  x)

Definition at line 211 of file approx_atan2.h.

References f, genVertex_cff::x, and detailsBasic3DVector::z.

211  {
212  auto z = x*x;
213  return x * ((-10381.9609375f) + z * ((3011.1513671875f) + z * (-827.538330078125f)));
214 }
float float float z
double f[11][100]
template<>
constexpr float approx_atan2s_P< 7 > ( float  x)

Definition at line 216 of file approx_atan2.h.

References f, genVertex_cff::x, and detailsBasic3DVector::z.

216  {
217  auto z = x*x;
218  return x * ((-10422.177734375f) + z * (3349.97412109375f + z * ((-1525.589599609375f) + z * 406.64190673828125f))) ;
219 }
float float float z
double f[11][100]
template<>
constexpr float approx_atan2s_P< 9 > ( float  x)

Definition at line 221 of file approx_atan2.h.

References f, genVertex_cff::x, and detailsBasic3DVector::z.

221  {
222  auto z = x*x;
223  return x * ((-10428.984375f) + z * (3445.20654296875f + z * ((-1879.137939453125f) + z * (888.22314453125f + z * (-217.42669677734375f)))));
224 }
float float float z
double f[11][100]
constexpr double int2dphi ( int  x)

Definition at line 269 of file approx_atan2.h.

References constexpr, M_PI, and SiStripPI::max.

269  {
270  constexpr double i2p = M_PI/( (long long)(std::numeric_limits<int>::max())+1LL );
271  return x*i2p;
272 }
#define M_PI
#define constexpr
constexpr float int2phi ( int  x)

Definition at line 263 of file approx_atan2.h.

References constexpr, objects.autophobj::float, M_PI, and SiStripPI::max.

263  {
264  constexpr float i2p = M_PI/( (long long)(std::numeric_limits<int>::max())+1LL );
265  return float(x)*i2p;
266 }
#define M_PI
#define constexpr
constexpr int phi2int ( float  x)

Definition at line 257 of file approx_atan2.h.

References constexpr, M_PI, and SiStripPI::max.

257  {
258  constexpr float p2i = ( (long long)(std::numeric_limits<int>::max())+1LL )/M_PI;
259  return std::round(x*p2i);
260 }
#define M_PI
#define constexpr
constexpr short phi2short ( float  x)

Definition at line 276 of file approx_atan2.h.

References constexpr, createfilelist::int, M_PI, and SiStripPI::max.

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

Definition at line 112 of file approx_atan2.h.

References approx_atan2i_P(), constexpr, f, genVertex_cff::x, and detailsBasic3DVector::y.

112  {
113  return unsafe_atan2f_impl<DEGREE>( y, (y==0.f)&(x==0.f) ? 0.2f : x);
114  // return (y==0.f)&(x==0.f) ? 0.f : unsafe_atan2f_impl<DEGREE>( y, x);
115 }
double f[11][100]
constexpr float short2phi ( short  x)
template<int DEGREE>
constexpr float unsafe_atan2f ( float  y,
float  x 
)

Definition at line 105 of file approx_atan2.h.

References genVertex_cff::x, and detailsBasic3DVector::y.

105  {
106  return unsafe_atan2f_impl<DEGREE>(y,x);
107 
108 }
template<int DEGREE>
constexpr float unsafe_atan2f_impl ( float  y,
float  x 
)

Definition at line 88 of file approx_atan2.h.

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

88  {
89 
90  constexpr float pi4f = 3.1415926535897932384626434/4;
91  constexpr float pi34f = 3.1415926535897932384626434*3/4;
92 
93  auto r= (std::abs(x) - std::abs(y))/(std::abs(x) + std::abs(y));
94  if (x<0) r = -r;
95 
96  auto angle = (x>=0) ? pi4f : pi34f;
97  angle += approx_atan2f_P<DEGREE>(r);
98 
99 
100  return ( (y < 0)) ? - angle : angle ;
101 
102 }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define constexpr
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 193 of file approx_atan2.h.

References approx_atan2s_P(), constexpr, genVertex_cff::x, and detailsBasic3DVector::y.

193  {
194  return unsafe_atan2i_impl<DEGREE>(y,x);
195 
196 }
template<int DEGREE>
constexpr int unsafe_atan2i_impl ( float  y,
float  x 
)

Definition at line 172 of file approx_atan2.h.

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

172  {
173 
174 
175  constexpr long long maxint = (long long)(std::numeric_limits<int>::max())+1LL;
176  constexpr int pi4 = int(maxint/4LL);
177  constexpr int pi34 = int(3LL*maxint/4LL);
178 
179  auto r= (std::abs(x) - std::abs(y))/(std::abs(x) + std::abs(y));
180  if (x<0) r = -r;
181 
182  auto angle = (x>=0) ? pi4 : pi34;
183  angle += int(approx_atan2i_P<DEGREE>(r));
184  // angle += int(std::round(approx_atan2i_P<DEGREE>(r)));
185 
186 
187  return (y < 0) ? - angle : angle ;
188 
189 
190 }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define constexpr
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 247 of file approx_atan2.h.

References constexpr, genVertex_cff::x, and detailsBasic3DVector::y.

247  {
248  return unsafe_atan2s_impl<DEGREE>(y,x);
249 }
template<int DEGREE>
constexpr short unsafe_atan2s_impl ( float  y,
float  x 
)

Definition at line 228 of file approx_atan2.h.

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

228  {
229 
230 
231  constexpr int maxshort = (int)(std::numeric_limits<short>::max())+1;
232  constexpr short pi4 = short(maxshort/4);
233  constexpr short pi34 = short(3*maxshort/4);
234 
235  auto r= (std::abs(x) - std::abs(y))/(std::abs(x) + std::abs(y));
236  if (x<0) r = -r;
237 
238  auto angle = (x>=0) ? pi4 : pi34;
239  angle += short(approx_atan2s_P<DEGREE>(r));
240 
241 
242  return (y < 0) ? - angle : angle ;
243 
244 }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define constexpr
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11