Generative Fast Fourier Transforms (GFFT)  0.3
pseudometafunc.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2007-2014 by Vladimir Mirnyy *
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU General Public License as published by *
6  * the Free Software Foundation; either version 2 of the License, or *
7  * (at your option) any later version. *
8  * *
9  * This program is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12  * GNU General Public License for more details. *
13  ***************************************************************************/
14 
15 #ifndef __pseudometafunc_h
16 #define __pseudometafunc_h
17 
23 #include <cmath>
24 
25 #include "metapow.h"
26 
27 
29 
34 namespace MF {
35 
37 
64 template<unsigned M, unsigned N, unsigned B, unsigned A>
65 struct SinCosSeries {
66  static long double value() {
67  return 1-(A*M_PI/B)*(A*M_PI/B)/M/(M+1)
69  }
70 };
71 
72 template<unsigned N, unsigned B, unsigned A>
73 struct SinCosSeries<N,N,B,A> {
74  static long double value() { return 1.; }
75 };
76 
77 
78 
88 template<unsigned B, unsigned A, typename T=double>
89 struct Sin;
90 
91 template<unsigned B, unsigned A>
92 struct Sin<B,A,float> {
93  static float value() {
94  return (A*M_PI/B)*SinCosSeries<2,24,B,A>::value();
95  }
96 };
97 
98 template<unsigned B, unsigned A>
99 struct Sin<B,A,double> {
100  static double value() {
101  return (A*M_PI/B)*SinCosSeries<2,34,B,A>::value();
102  }
103 };
104 
105 template<unsigned B, unsigned A>
106 struct Sin<B,A,long double> {
107  static long double value() {
108  return (A*M_PI/B)*SinCosSeries<2,60,B,A>::value();
109  }
110 };
111 
121 template<unsigned B, unsigned A, typename T=double>
122 struct Cos;
123 
124 template<unsigned B, unsigned A>
125 struct Cos<B,A,float> {
126  static float value() {
128  }
129 };
130 
131 template<unsigned B, unsigned A>
132 struct Cos<B,A,double> {
133  static double value() {
134  return SinCosSeries<1,33,B,A>::value();
135  }
136 };
137 
138 template<unsigned B, unsigned A>
139 struct Cos<B,A,long double> {
140  static long double value() {
141  return SinCosSeries<1,59,B,A>::value();
142  }
143 };
144 
145 
146 template<unsigned N, unsigned I>
147 class SqrtSeries {
148 public:
149  static long double value() {
150  static const long double XI = SqrtSeries<N,I-1>::value();
151  return 0.5*(XI + N/XI);
152  }
153 };
154 
155 template<unsigned N>
156 class SqrtSeries<N,0> {
157  static const unsigned ND = NDigits<N, 2>::value;
158  static const unsigned X0 = IPow<2, ND/2>::value;
159 public:
160  static long double value() {
161  return 0.5*(X0 + N/static_cast<long double>(X0));
162  }
163 };
164 
165 template<unsigned N, typename T=double>
166 struct Sqrt;
167 
168 template<unsigned N>
169 struct Sqrt<N, float> {
170  static float value() {
171  return SqrtSeries<N,5>::value();
172  }
173 };
174 
175 template<unsigned N>
176 struct Sqrt<N, double> {
177  static double value() {
178  return SqrtSeries<N,6>::value();
179  }
180 };
181 
182 template<unsigned N>
183 struct Sqrt<N, long double> {
184  static long double value() {
185  return SqrtSeries<N,6>::value();
186  }
187 };
188 
189 
190 
191 template<int K = 10>
192 struct Pi
193 {
194  static const unsigned long P16 = IPow<16,K>::value;
195  static const int_t K1 = 8*K+1;
196  static const int_t K2 = 4*K+2;
197  static const int_t K3 = 8*K+5;
198  static const int_t K4 = 8*K+6;
199 
200  typedef double T;
201  static T value()
202  {
203  return (4./static_cast<T>(K1) - 2./static_cast<T>(K2) - 1./static_cast<T>(K3) - 1./static_cast<T>(K4))
204  /static_cast<T>(P16) + Pi<K-1>::value();
205  }
206 };
207 
208 template<>
209 struct Pi<0>
210 {
211  static double value() { return 47./15.; }
212 };
213 
214 } // namespace MF
215 
216 #endif /*__pseudometafunc_h*/

Generated on Mon Feb 10 2014 for Generative Fast Fourier Transforms (GFFT) by DoxyGen 1.8.3.1