test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
approx_asin.h
Go to the documentation of this file.
1 #ifndef approx_asin_h
2 #define approx_asin_h
3 
4 #include<cmath>
5 template<int DEGREE>
6 inline float approx_asin_P(float z);
7 
8 
9  // degree = 3 => absolute accuracy is 8 bits
10 template<> inline float approx_asin_P< 3 >(float z){
11  return 1.f + z * 0.2133004963397979736328125f;
12 }
13  // degree = 5 => absolute accuracy is 11 bits
14 template<> inline float approx_asin_P< 5 >(float z){
15  return 1.f + z * (0.154711246490478515625f + z * 0.1322681009769439697265625f);
16 }
17  // degree = 7 => absolute accuracy is 15 bits
18 template<> inline float approx_asin_P< 7 >(float z){
19  return 1.f + z * (0.169519245624542236328125f + z * (4.9031913280487060546875e-2f + z * 0.10941398143768310546875));
20 }
21  // degree = 9 => absolute accuracy is 18 bits
22 template<> inline float approx_asin_P< 9 >(float z){
23  return 1.f + z * (0.166020572185516357421875f + z * (8.44048559665679931640625e-2f + z * (1.11602735705673694610595703125e-3f + z * 0.103476583957672119140625f)));
24 }
25  // degree = 11 => absolute accuracy is 21 bits
26 template<> inline float approx_asin_P< 11 >(float z){
27  return 1.f + z * (0.1668075025081634521484375f + z * (7.20207393169403076171875e-2f + z * (6.607978045940399169921875e-2f + z * ((-3.6048568785190582275390625e-2f) + z * 0.10574872791767120361328125f))));
28 }
29 
30 /*
31  // degree = 3 => absolute accuracy is 8 bits
32 template<> inline float approx_asin_P< 3 >(float z){
33  return 1.f + z * 0.2114248573780059814453125f;
34 }
35  // degree = 5 => absolute accuracy is 12 bits
36 template<> inline float approx_asin_P< 5 >(float z){
37  return 1.f + z * (0.1556626856327056884765625f + z * 0.1295671761035919189453125f);
38 }
39  // degree = 7 => absolute accuracy is 15 bits
40 template<> inline float approx_asin_P< 7 >(float z){
41  return 1.f + z * (0.1691854894161224365234375f + z * (5.1305986940860748291015625e-2f + z * 0.1058919131755828857421875f));
42 }
43  // degree = 9 => absolute accuracy is 18 bits
44 template<> inline float approx_asin_P< 9 >(float z){
45  return 1.f + z * (0.166119158267974853515625f + z * (8.322779834270477294921875e-2f + z * (5.28236292302608489990234375e-3f + z * 9.89462435245513916015625e-2f)));
46 }
47  // degree = 11 => absolute accuracy is 21 bits
48 template<> inline float approx_asin_P< 11 >(float z){
49  return 1.f + z * (0.1667812168598175048828125f + z * (7.249967753887176513671875e-2f + z * (6.321799755096435546875e-2f + z * ((-2.913488447666168212890625e-2f) + z * 9.9913299083709716796875e-2f))));
50 }
51 */
52 
53 
54 
55 // valid for |x|<0.71
56 template<int DEGREE>
57 inline float unsafe_asin07(float x) {
58  auto z=x*x;
59  return x*approx_asin_P<DEGREE>(z);
60 }
61 
62 template<int DEGREE>
63 inline float unsafe_acos07(float x) {
64  constexpr float pihalf = M_PI/2;
65  return pihalf - unsafe_asin07<DEGREE>(x);
66 }
67 
68 
69 // for |x|> 0.71 use slower
70 template<int DEGREE>
71 inline float unsafe_acos71(float x) {
72  constexpr float pi = M_PI;
73  auto z=1.f-x*x;
74  z= std::sqrt(z)*approx_asin_P<DEGREE>(z);
75  return x>0 ? z : pi-z;
76 }
77 
78 template<int DEGREE>
79 inline float unsafe_asin71(float x) {
80  constexpr float pihalf = M_PI/2;
81  return pihalf - unsafe_acos71<DEGREE>(x);
82 }
83 
84 template<int DEGREE>
85 inline float unsafe_asin(float x) {
86  return (std::abs(x)<0.71f) ? unsafe_asin07<DEGREE>(x) : unsafe_asin71<DEGREE>(x);
87 }
88 
89 template<int DEGREE>
90 inline float unsafe_acos(float x) {
91  return (std::abs(x)<0.71f) ? unsafe_acos07<DEGREE>(x) : unsafe_acos71<DEGREE>(x);
92 }
93 
94 
95 #endif
float approx_asin_P< 7 >(float z)
Definition: approx_asin.h:18
float approx_asin_P< 9 >(float z)
Definition: approx_asin.h:22
#define constexpr
float float float z
float unsafe_asin07(float x)
Definition: approx_asin.h:57
float unsafe_acos(float x)
Definition: approx_asin.h:90
const Double_t pi
float unsafe_asin(float x)
Definition: approx_asin.h:85
T x() const
Cartesian x coordinate.
T sqrt(T t)
Definition: SSEVec.h:18
float unsafe_asin71(float x)
Definition: approx_asin.h:79
float approx_asin_P< 5 >(float z)
Definition: approx_asin.h:14
float approx_asin_P< 11 >(float z)
Definition: approx_asin.h:26
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
float approx_asin_P< 3 >(float z)
Definition: approx_asin.h:10
#define M_PI
float unsafe_acos71(float x)
Definition: approx_asin.h:71
float unsafe_acos07(float x)
Definition: approx_asin.h:63
float approx_asin_P(float z)