1 2 #ifndef _global_h 3 # include "global.h" 4 #endif 5 #ifndef _real_h 6 # include "real.h" 7 #endif 8 9 #ifndef RealZero 10 const Real RealZero = 0.0; 11 #endif 12 13 FunTab(double (* fkt)(double),double from_in,double to_in,int step_in)14FunTab::FunTab( double (*fkt) (double), double from_in, double to_in, int step_in ) { 15 16 from = from_in; 17 to = to_in; 18 step = step_in; 19 interval = (to-from)/Real((double)step); 20 21 val = new Real [step+1]; 22 23 for (int i=0;i<=step;i++) { 24 val[i] = fkt( from+interval*(double)i ); 25 } 26 } 27 28 ~FunTab()29FunTab::~FunTab() { 30 if (val) delete [] val; 31 } 32 GetVal(const Real & in)33const Real &FunTab::GetVal( const Real &in ) const { 34 double m = fmod( in, 2.0*M_PI ); 35 while( m<0 ) m+= M_PI*2.0; 36 int ind = (int)((m-from)/interval+0.5); 37 return val[ind]; 38 } 39 GetRezVal(const Real & in)40Real FunTab::GetRezVal( const Real &in ) const { 41 int hi = step; 42 int lo = 0; 43 44 int mid = (hi+lo)/2; 45 46 while( mid!=lo ) { 47 if (val[mid]>in) hi=mid; 48 else lo=mid; 49 mid = (hi+lo)/2; 50 } 51 return (double)mid*interval+from; 52 } 53