GteExp2Estimate.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #pragma once
9 
11 #include <cmath>
12 
13 // Minimax polynomial approximations to 2^x. The polynomial p(x) of
14 // degree D minimizes the quantity maximum{|2^x - p(x)| : x in [0,1]}
15 // over all polynomials of degree D.
16 
17 namespace gte
18 {
19 
20 template <typename Real>
22 {
23 public:
24  // The input constraint is x in [0,1]. For example,
25  // float x; // in [0,1]
26  // float result = Exp2Estimate<float>::Degree<3>(x);
27  template <int D>
28  inline static Real Degree(Real x);
29 
30  // The input x can be any real number. Range reduction is used to
31  // generate a value y in [0,1], call Degree(y), and combine the output
32  // with the proper exponent to obtain the approximation. For example,
33  // float x; // x >= 0
34  // float result = Exp2Estimate<float>::DegreeRR<3>(x);
35  template <int D>
36  inline static Real DegreeRR(Real x);
37 
38 private:
39  // Metaprogramming and private implementation to allow specialization of
40  // a template member function.
41  template <int D> struct degree {};
42  inline static Real Evaluate(degree<1>, Real t);
43  inline static Real Evaluate(degree<2>, Real t);
44  inline static Real Evaluate(degree<3>, Real t);
45  inline static Real Evaluate(degree<4>, Real t);
46  inline static Real Evaluate(degree<5>, Real t);
47  inline static Real Evaluate(degree<6>, Real t);
48  inline static Real Evaluate(degree<7>, Real t);
49 };
50 
51 
52 template <typename Real>
53 template <int D>
54 inline Real Exp2Estimate<Real>::Degree(Real x)
55 {
56  return Evaluate(degree<D>(), x);
57 }
58 
59 template <typename Real>
60 template <int D>
62 {
63  Real p = floor(x);
64  Real y = x - p;
65  Real poly = Degree<D>(y);
66  Real result = ldexp(poly, (int)p);
67  return result;
68 }
69 
70 template <typename Real>
72 {
73  Real poly;
74  poly = (Real)GTE_C_EXP2_DEG1_C1;
75  poly = (Real)GTE_C_EXP2_DEG1_C0 + poly * t;
76  return poly;
77 }
78 
79 template <typename Real>
81 {
82  Real poly;
83  poly = (Real)GTE_C_EXP2_DEG2_C2;
84  poly = (Real)GTE_C_EXP2_DEG2_C1 + poly * t;
85  poly = (Real)GTE_C_EXP2_DEG2_C0 + poly * t;
86  return poly;
87 }
88 
89 template <typename Real>
91 {
92  Real poly;
93  poly = (Real)GTE_C_EXP2_DEG3_C3;
94  poly = (Real)GTE_C_EXP2_DEG3_C2 + poly * t;
95  poly = (Real)GTE_C_EXP2_DEG3_C1 + poly * t;
96  poly = (Real)GTE_C_EXP2_DEG3_C0 + poly * t;
97  return poly;
98 }
99 
100 template <typename Real>
102 {
103  Real poly;
104  poly = (Real)GTE_C_EXP2_DEG4_C4;
105  poly = (Real)GTE_C_EXP2_DEG4_C3 + poly * t;
106  poly = (Real)GTE_C_EXP2_DEG4_C2 + poly * t;
107  poly = (Real)GTE_C_EXP2_DEG4_C1 + poly * t;
108  poly = (Real)GTE_C_EXP2_DEG4_C0 + poly * t;
109  return poly;
110 }
111 
112 template <typename Real>
114 {
115  Real poly;
116  poly = (Real)GTE_C_EXP2_DEG5_C5;
117  poly = (Real)GTE_C_EXP2_DEG5_C4 + poly * t;
118  poly = (Real)GTE_C_EXP2_DEG5_C3 + poly * t;
119  poly = (Real)GTE_C_EXP2_DEG5_C2 + poly * t;
120  poly = (Real)GTE_C_EXP2_DEG5_C1 + poly * t;
121  poly = (Real)GTE_C_EXP2_DEG5_C0 + poly * t;
122  return poly;
123 }
124 
125 template <typename Real>
127 {
128  Real poly;
129  poly = (Real)GTE_C_EXP2_DEG6_C6;
130  poly = (Real)GTE_C_EXP2_DEG6_C5 + poly * t;
131  poly = (Real)GTE_C_EXP2_DEG6_C4 + poly * t;
132  poly = (Real)GTE_C_EXP2_DEG6_C3 + poly * t;
133  poly = (Real)GTE_C_EXP2_DEG6_C2 + poly * t;
134  poly = (Real)GTE_C_EXP2_DEG6_C1 + poly * t;
135  poly = (Real)GTE_C_EXP2_DEG6_C0 + poly * t;
136  return poly;
137 }
138 
139 template <typename Real>
141 {
142  Real poly;
143  poly = (Real)GTE_C_EXP2_DEG7_C7;
144  poly = (Real)GTE_C_EXP2_DEG7_C6 + poly * t;
145  poly = (Real)GTE_C_EXP2_DEG7_C5 + poly * t;
146  poly = (Real)GTE_C_EXP2_DEG7_C4 + poly * t;
147  poly = (Real)GTE_C_EXP2_DEG7_C3 + poly * t;
148  poly = (Real)GTE_C_EXP2_DEG7_C2 + poly * t;
149  poly = (Real)GTE_C_EXP2_DEG7_C1 + poly * t;
150  poly = (Real)GTE_C_EXP2_DEG7_C0 + poly * t;
151  return poly;
152 }
153 
154 
155 }
#define GTE_C_EXP2_DEG5_C1
Definition: GteConstants.h:397
#define GTE_C_EXP2_DEG7_C7
Definition: GteConstants.h:420
#define GTE_C_EXP2_DEG2_C1
Definition: GteConstants.h:379
#define GTE_C_EXP2_DEG7_C3
Definition: GteConstants.h:416
#define GTE_C_EXP2_DEG3_C1
Definition: GteConstants.h:384
#define GTE_C_EXP2_DEG5_C3
Definition: GteConstants.h:399
static Real Evaluate(degree< 1 >, Real t)
#define GTE_C_EXP2_DEG6_C4
Definition: GteConstants.h:408
#define GTE_C_EXP2_DEG1_C1
Definition: GteConstants.h:375
#define GTE_C_EXP2_DEG4_C4
Definition: GteConstants.h:393
#define GTE_C_EXP2_DEG1_C0
Definition: GteConstants.h:374
#define GTE_C_EXP2_DEG6_C3
Definition: GteConstants.h:407
#define GTE_C_EXP2_DEG3_C0
Definition: GteConstants.h:383
#define GTE_C_EXP2_DEG4_C2
Definition: GteConstants.h:391
#define GTE_C_EXP2_DEG6_C5
Definition: GteConstants.h:409
#define GTE_C_EXP2_DEG7_C6
Definition: GteConstants.h:419
#define GTE_C_EXP2_DEG7_C2
Definition: GteConstants.h:415
#define GTE_C_EXP2_DEG7_C5
Definition: GteConstants.h:418
#define GTE_C_EXP2_DEG6_C0
Definition: GteConstants.h:404
GLint GLenum GLint x
Definition: glcorearb.h:404
#define GTE_C_EXP2_DEG2_C0
Definition: GteConstants.h:378
#define GTE_C_EXP2_DEG5_C4
Definition: GteConstants.h:400
#define GTE_C_EXP2_DEG6_C1
Definition: GteConstants.h:405
static Real Degree(Real x)
#define GTE_C_EXP2_DEG2_C2
Definition: GteConstants.h:380
#define GTE_C_EXP2_DEG5_C0
Definition: GteConstants.h:396
#define GTE_C_EXP2_DEG7_C4
Definition: GteConstants.h:417
#define GTE_C_EXP2_DEG4_C0
Definition: GteConstants.h:389
#define GTE_C_EXP2_DEG7_C1
Definition: GteConstants.h:414
#define GTE_C_EXP2_DEG7_C0
Definition: GteConstants.h:413
#define GTE_C_EXP2_DEG4_C1
Definition: GteConstants.h:390
GLdouble GLdouble t
Definition: glext.h:239
#define GTE_C_EXP2_DEG4_C3
Definition: GteConstants.h:392
#define GTE_C_EXP2_DEG6_C2
Definition: GteConstants.h:406
#define GTE_C_EXP2_DEG5_C5
Definition: GteConstants.h:401
#define GTE_C_EXP2_DEG3_C2
Definition: GteConstants.h:385
GLfloat GLfloat p
Definition: glext.h:11668
#define GTE_C_EXP2_DEG3_C3
Definition: GteConstants.h:386
GLuint64EXT * result
Definition: glext.h:10003
#define GTE_C_EXP2_DEG5_C2
Definition: GteConstants.h:398
GLint y
Definition: glcorearb.h:98
#define GTE_C_EXP2_DEG6_C6
Definition: GteConstants.h:410
static Real DegreeRR(Real x)


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:59