00001 #ifndef INCLUDED_ALG_REMEZ_H
00002 #define INCLUDED_ALG_REMEZ_H
00003
00004 #include<config.h>
00005
00006 #ifdef GMP // If GMP is defined
00007
00008 #include <util/lattice.h>
00009 #include <util/smalloc.h>
00010 #include <util/pmalloc.h>
00011 #include <alg/common_arg.h>
00012 #include <alg/bigfloat.h>
00013 #include <alg/remez_arg.h>
00014 CPS_START_NAMESPACE
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #define JMAX 1000 //Maximum number of iterations of Newton's approximation
00029
00030 class AlgRemez
00031 {
00032 private:
00033 char *cname;
00034
00036 RemezArg *remez_arg;
00037
00038
00039 bigfloat *param, *roots, *poles;
00040 bigfloat norm;
00041
00042
00043 int n, d;
00044
00045
00046 bigfloat apstrt, apwidt, apend;
00047
00048
00049 unsigned long power_num;
00050 unsigned long power_den;
00051
00052
00053 int nd1, iter;
00054 bigfloat *xx, *mm, *step;
00055 bigfloat delta, spread, tolerance;
00056
00057 bigfloat delta_m;
00058
00059
00060 int neq;
00061
00062
00063 RationalApproxType approx_type;
00064
00065
00066 long prec;
00067
00068
00069 void initialGuess();
00070
00071
00072 void equations();
00073
00074
00075 void search(bigfloat *step);
00076
00077
00078 void stpini(bigfloat *step);
00079
00080
00081 int root();
00082
00083
00084 bigfloat polyEval(bigfloat x, bigfloat *poly, long size);
00085
00086
00087 bigfloat polyDiff(bigfloat x, bigfloat *poly, long size);
00088
00089
00090 bigfloat rtnewt(bigfloat *poly, long i, bigfloat x1, bigfloat x2, bigfloat xacc);
00091
00092
00093
00094
00095 void pfe(bigfloat *res, bigfloat* poles, bigfloat norm);
00096
00097
00098
00099 bigfloat approx(bigfloat x);
00100
00101
00102 bigfloat func(bigfloat x);
00103
00104
00105 bigfloat getErr(bigfloat x, int *sign);
00106
00107
00108 int simq(bigfloat *A, bigfloat *B, bigfloat *X, int n);
00109
00110 public:
00111
00112
00113 AlgRemez(RemezArg &);
00114
00115
00116 virtual ~AlgRemez();
00117
00118
00119 void generateApprox();
00120
00121
00122 int getPFE(Float *res, Float *pole, Float *norm);
00123
00124
00125 int getIPFE(Float *res, Float *pole, Float *norm);
00126
00127 };
00128 CPS_END_NAMESPACE
00129
00130 #else // If not defined GMP
00131
00132
00133 #include <alg/remez_arg.h>
00134 #include <util/error.h>
00135 #include <util/data_types.h>
00136 CPS_START_NAMESPACE
00137
00138
00139
00140
00141 class AlgRemez
00142 {
00143 private:
00144 char *cname;
00145
00146
00147 public:
00148
00149 AlgRemez(RemezArg&) {
00150 cname = "AlgRemez";
00151 char *fname = "AlgRemez(RemezArg&)";
00152 ERR.General(cname,fname,
00153 "AlgRemez cannot be instantiated without GMP installed\n");
00154 }
00155
00156 ~AlgRemez() {;}
00157
00158 Float generateApprox() {return 0.0;}
00159 int getPFE(Float *res, Float *pole, Float *norm) {return 0;}
00160 int getIPFE(Float *res, Float *pole, Float *norm) {return 0;}
00161
00162 };
00163 CPS_END_NAMESPACE
00164
00165 #endif // Ifdef GMP
00166
00167 #endif // Include guard
00168
00169
00170