PhoenixGraph  01.0.0
Set of tools to simplify graph manipulation
Loading...
Searching...
No Matches
pstatic_computation.h
Go to the documentation of this file.
1
2/***************************************
3 Auteur : Pierre Aubert
4 Mail : pierre.aubert@lapp.in2p3.fr
5 Licence : CeCILL-C
6****************************************/
7
8#ifndef __PSTATIC_COMPUTATION_H__
9#define __PSTATIC_COMPUTATION_H__
10
12template<unsigned int N> struct pstatic_fact{
13 enum {Value = N * pstatic_fact<N - 1>::Value};
14};
15
16template<> struct pstatic_fact<0>{
17 enum {Value = 1};
18};
19
21template<unsigned int V, unsigned int N> struct PPower{
22 enum {Value = V * PPower<V, N - 1>::Value};
23};
24
25template<unsigned int V> struct PPower<V, 1>{
26 enum {Value = V};
27};
28
29template<unsigned int V> struct PPower<V, 0>{
30 enum {Value = 1};
31};
32
33/*
34 * Attention, cette version est 100% calculée à la compilation, elle ne servira donc qu'à calculer des constantes, et ne sera donc pas utilisée à l'exécution.
35 * Voici la même mais en version "fonction inline", ce qui nous permettra de renvoyer un double et donc de manipuler des nombres beaucoup plus grands (on est limité à 12! avec la version ci-dessus)
36*/
37
39
41template <unsigned int I> inline double pstatic_factd(){
42 return I * pstatic_factd<I - 1>();
43}
44
45
47template <> inline double pstatic_factd<0>(){
48 return 1.0;
49}
50
52
54template <unsigned int I> inline float pstatic_factf(){
55 return I * pstatic_factf<I - 1>();
56}
57
58
60template <> inline float pstatic_factf<0>(){
61 return 1.0f;
62}
63
65
67template <int N> inline double pstatic_powd(double x){
68 return x * pstatic_powd<N - 1>(x);
69}
70
71
73template <> inline double pstatic_powd<0>(double x){
74 return 1.0;
75}
76
78
80template <int N> inline float pstatic_powf(float x){
81 return x * pstatic_powf<N - 1>(x);
82}
83
84
86template <> inline float pstatic_powf<0>(float x){
87 return 1.0f;
88}
89
91
94template <int I> inline double pstatic_expd_part(double x){
95 return pstatic_expd_part<I - 1>(x) + pstatic_powd<I>(x) / pstatic_factd<I>();
96}
97
98
101template <> inline double pstatic_expd_part<0>(double x){
102 return 0.0;
103}
104
105
108template <int N> inline double pstatic_expd(double x){
109 return x < 0.0 ? 1.0 / pstatic_expd_part<N>(-x) : pstatic_expd_part<N>(x);
110}
111
113
116template <int I> inline float pstatic_expf_part(float x){
117 return pstatic_expf_part<I - 1>(x) + pstatic_powf<I>(x) / pstatic_factf<I>();
118}
119
120
122template <> inline float pstatic_expf_part<0>(float x){
123 return 0.0;
124}
125
126
129template <int N> inline float pstatic_expf(float x){
130 return x < 0.0 ? 1.0 / pstatic_expf_part<N>(-x) : pstatic_expf_part<N>(x);
131}
132
134
137template <int N> inline double pstatic_cosd(double x){
138 return pstatic_cosd<N - 1>(x) + (N % 2 ? -1 : 1) * pstatic_powd<2 * N>(x) / pstatic_factd<2 * N>();
139}
140
142
145template <> inline double pstatic_cosd<0>(double x){
146 return 1.0;
147}
148
150
153template <int N> inline float pstatic_cosf(float x){
154 return pstatic_cosf<N - 1>(x) + (N % 2 ? -1 : 1) * pstatic_powf<2 * N>(x) / pstatic_factf<2 * N>();
155}
156
158
161template <> inline float pstatic_cosf<0>(float x){
162 return 1.0f;
163}
164
166
169template <int I> inline double pstatic_atanhd(double x){
170 return pstatic_atanhd<I - 1>(x) + pstatic_powd<2 * I + 1>(x) / (2 * I + 1);
171}
172
174
176template <> inline double pstatic_atanhd<1>(double x){
177 return x;
178}
179
181
183template <> inline double pstatic_atanhd<0>(double x){
184 return 0.0;
185}
186
188
191template <int I> inline float pstatic_atanhf(float x){
192 return pstatic_atanhf<I - 1>(x) + pstatic_powf<2 * I + 1>(x) / (2 * I + 1);
193}
194
196
198template <> inline float pstatic_atanhf<1>(float x){
199 return x;
200}
201
203
205template <> inline float pstatic_atanhf<0>(float x){
206 return 0.0f;
207}
208
209/* Pour conclure cette partie, je tiens à vous signaler que ces fonctions ne sont encore pas optimisées à fond.
210 * En effet les fans de bricolage pourront s'en donner à cœur joie, pour notamment réduire la profondeur de récursion ou éliminer les branches de récursion inutiles.
211 * De même en remaniant les formules mathématiques utilisées pour les rendre plus sympathiques pour nos templates, il y a encore là matière à optimiser.
212*/
213
214#endif
215
216
float pstatic_powf(float x)
Compute power for float.
double pstatic_cosd(double x)
Compute cosine for double.
float pstatic_factf()
Compute factorial for float.
double pstatic_powd(double x)
Compute power for double.
float pstatic_cosf< 0 >(float x)
Compute cosine for float.
float pstatic_expf_part(float x)
Compute exponentiel for float.
double pstatic_expd_part(double x)
Compute exponentiel for double.
double pstatic_powd< 0 >(double x)
Compute power for double.
float pstatic_cosf(float x)
Compute cosine for float.
double pstatic_factd()
Compute factorial for double.
float pstatic_factf< 0 >()
Compute factorial for float.
double pstatic_expd_part< 0 >(double x)
Compute exponentiel for double.
double pstatic_atanhd(double x)
Compute hyperbolic arctangente for double.
float pstatic_atanhf< 1 >(float x)
Compute hyperbolic arctangente for float.
float pstatic_expf_part< 0 >(float x)
Compute exponentiel for float.
float pstatic_powf< 0 >(float x)
Compute power for float.
double pstatic_cosd< 0 >(double x)
Compute cosine for double.
double pstatic_atanhd< 1 >(double x)
Compute hyperbolic arctangente for double.
double pstatic_factd< 0 >()
Compute factorial for double.
double pstatic_atanhd< 0 >(double x)
Compute hyperbolic arctangente for double.
float pstatic_atanhf(float x)
Compute hyperbolic arctangente for float.
float pstatic_atanhf< 0 >(float x)
Compute hyperbolic arctangente for float.
float pstatic_expf(float x)
Compute exponentiel for float.
double pstatic_expd(double x)
Compute exponentiel for double.
Compute the power of an unsigned int statically.
Compute the factorial of an unsigned int statically.