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>
float approx_atan2f_P (float x)
 
template<>
float approx_atan2f_P< 11 > (float x)
 
template<>
float approx_atan2f_P< 13 > (float x)
 
template<>
float approx_atan2f_P< 15 > (float x)
 
template<>
float approx_atan2f_P< 3 > (float x)
 
template<>
float approx_atan2f_P< 5 > (float x)
 
template<>
float approx_atan2f_P< 7 > (float x)
 
template<>
float approx_atan2f_P< 9 > (float x)
 
template<int DEGREE>
float approx_atan2i_P (float x)
 
template<>
float approx_atan2i_P< 11 > (float x)
 
template<>
float approx_atan2i_P< 13 > (float x)
 
template<>
float approx_atan2i_P< 15 > (float x)
 
template<>
float approx_atan2i_P< 3 > (float x)
 
template<>
float approx_atan2i_P< 5 > (float x)
 
template<>
float approx_atan2i_P< 7 > (float x)
 
template<>
float approx_atan2i_P< 9 > (float x)
 
double int2dphi (int x)
 
float int2phi (int x)
 
int phi2int (float x)
 
short phi2short (float x)
 
template<int DEGREE>
float safe_atan2f (float y, float x)
 
float short2phi (short x)
 
template<int DEGREE>
float unsafe_atan2f (float y, float x)
 
template<int DEGREE>
float unsafe_atan2f_impl (float y, float x)
 
template<int DEGREE>
int unsafe_atan2i (float y, float x)
 
template<int DEGREE>
int unsafe_atan2i_impl (float y, float x)
 

Function Documentation

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

Definition at line 69 of file approx_atan2.h.

References objects.autophobj::float, vertices_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<>
float approx_atan2f_P< 13 > ( float  x)
inline

Definition at line 75 of file approx_atan2.h.

References objects.autophobj::float, vertices_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<>
float approx_atan2f_P< 15 > ( float  x)
inline

Definition at line 81 of file approx_atan2.h.

References objects.autophobj::float, vertices_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<>
float approx_atan2f_P< 3 > ( float  x)
inline

Definition at line 46 of file approx_atan2.h.

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

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

Definition at line 51 of file approx_atan2.h.

References objects.autophobj::float, vertices_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<>
float approx_atan2f_P< 7 > ( float  x)
inline

Definition at line 57 of file approx_atan2.h.

References objects.autophobj::float, vertices_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<>
float approx_atan2f_P< 9 > ( float  x)
inline

Definition at line 63 of file approx_atan2.h.

References objects.autophobj::float, vertices_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>
float approx_atan2i_P ( float  x)
inline

Referenced by safe_atan2f().

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

Definition at line 154 of file approx_atan2.h.

References vertices_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<>
float approx_atan2i_P< 13 > ( float  x)
inline

Definition at line 160 of file approx_atan2.h.

References vertices_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<>
float approx_atan2i_P< 15 > ( float  x)
inline

Definition at line 165 of file approx_atan2.h.

References vertices_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<>
float approx_atan2i_P< 3 > ( float  x)
inline

Definition at line 130 of file approx_atan2.h.

References vertices_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<>
float approx_atan2i_P< 5 > ( float  x)
inline

Definition at line 136 of file approx_atan2.h.

References vertices_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<>
float approx_atan2i_P< 7 > ( float  x)
inline

Definition at line 142 of file approx_atan2.h.

References vertices_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<>
float approx_atan2i_P< 9 > ( float  x)
inline

Definition at line 148 of file approx_atan2.h.

References vertices_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
double int2dphi ( int  x)
inline

Definition at line 211 of file approx_atan2.h.

References constexpr, M_PI, and SiStripPI::max.

211  {
212  constexpr double i2p = M_PI/( (long long)(std::numeric_limits<int>::max())+1LL );
213  return x*i2p;
214 }
#define constexpr
#define M_PI
float int2phi ( int  x)
inline

Definition at line 205 of file approx_atan2.h.

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

205  {
206  constexpr float i2p = M_PI/( (long long)(std::numeric_limits<int>::max())+1LL );
207  return float(x)*i2p;
208 }
#define constexpr
#define M_PI
int phi2int ( float  x)
inline

Definition at line 199 of file approx_atan2.h.

References constexpr, M_PI, and SiStripPI::max.

199  {
200  constexpr float p2i = ( (long long)(std::numeric_limits<int>::max())+1LL )/M_PI;
201  return std::round(x*p2i);
202 }
#define constexpr
#define M_PI
short phi2short ( float  x)
inline

Definition at line 218 of file approx_atan2.h.

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

218  {
219  constexpr float p2i = ( (int)(std::numeric_limits<short>::max())+1 )/M_PI;
220  return std::round(x*p2i);
221 }
#define constexpr
#define M_PI
template<int DEGREE>
float safe_atan2f ( float  y,
float  x 
)
inline

Definition at line 112 of file approx_atan2.h.

References approx_atan2i_P(), f, vertices_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]
float short2phi ( short  x)
inline

Definition at line 224 of file approx_atan2.h.

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

224  {
225  constexpr float i2p = M_PI/( (int)(std::numeric_limits<short>::max())+1 );
226  return float(x)*i2p;
227 }
#define constexpr
#define M_PI
template<int DEGREE>
float unsafe_atan2f ( float  y,
float  x 
)
inline

Definition at line 105 of file approx_atan2.h.

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

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

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 }
#define constexpr
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11
template<int DEGREE>
int unsafe_atan2i ( float  y,
float  x 
)
inline

Definition at line 193 of file approx_atan2.h.

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

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

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 }
#define constexpr
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11