Documentation


numerics.h

Go to the documentation of this file.
00001 #ifndef ANIMAL_TRAITS_NUMERICS_H
00002 #define ANIMAL_TRAITS_NUMERICS_H
00003 
00004 #include <math.h>
00005 #include <float.h>
00006 
00007 
00008 
00009 namespace animal {
00010 
00012 template <class T> inline T pow2(const T &f) { return f * f; }
00013 
00015 template <class T> inline T pow3(const T &f) { return f * f * f; }
00016 
00018 template <class T> inline T pow4(const T &f) { return f * f * f * f; }
00019 
00021 typedef unsigned int Natural;
00022 
00023 // -------------------------------------------------------
00025 
00026 //template<class T>
00027 //struct Value
00028 //{
00029 //  static inline T zero(){ return 0; }
00030 //};
00031 
00032 // -------------------------------------------------------
00033 //  
00034 //  Numerics class.
00048 //  
00049 // -------------------------------------------------------
00050 template <class Number> class Numerics
00051 {
00052 
00053 public:
00054   
00056     typedef int Boolean;
00057 
00059     typedef double Real;
00060 
00063     
00065     static inline Real PI()
00066         { return 3.141592653589793238462643383;}
00067         
00070     static inline Real CONV_RAD_TO_DEG()
00071         { return 1.0/2.0/PI()*360.0; }
00072                 
00075     static inline Real CONV_DEG_TO_RAD()
00076         { return 2.0*PI()/360.0; }
00077     
00079     static inline Real E()
00080         { return 2.7182818284590452354; }
00081     
00083     
00086 
00088     static Number fpabs(Number k) { return k<0 ? -k : k ; };
00089 
00091     static Real sqroot(Number k) { return sqrt(k); };
00092 
00094     static Real sine(Number k) { return sin(k); };
00095 
00097     static Real asine(Number k) { return ::asinf(k); };
00098 
00100     static Real cosine(Number k) { return cos(k); };
00101 
00103     static Real acosine(Number k) { return acos(k); };
00104 
00106     static Real tan(Number k) { return ::tanf(k); };
00107 
00109     static Real atan(Number k) { return ::atanf(k); };
00110 
00112     static Real e(Number k) { return ::expf(k); };
00113 
00115     static Real ln(Number k) { return ::logf(k); };
00116 
00118     static Real power(Number k1,Number k2) { return ::powf(k1,k2); };
00119 
00121     static Real prev_integer(Number a) { return ::floorf(a); };
00122 
00124     static Real next_integer(Number a) { return ::ceilf(a); };
00125 
00127     static Boolean isfinite(Number k) { return true; };
00128 
00130     static Real numthreshold() { return 0; };
00131     
00133   
00134 }; // class Numerics<>
00135 
00136 
00137 // -------------------------------------------------------
00138 //  
00139 //  Numerics<float> class.
00147 //  
00148 // -------------------------------------------------------
00149 
00150 template <> 
00151 class Numerics<float>
00152 {
00153 public:
00154   
00156     typedef bool Boolean;
00157 
00159     typedef float Real;
00160 
00163     
00165     static inline Real PI()
00166         { return 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998;}
00167         
00170     static inline Real CONV_RAD_TO_DEG()
00171         { return 1.0/2.0/PI()*360.0; }
00172                 
00175     static inline Real CONV_DEG_TO_RAD()
00176         { return 2.0*PI()/360.0; }
00177     
00179     static inline Real E()
00180         { return 2.7182818284590452354; }
00181     
00183     
00186 
00188     static Real fpabs(Real k) { return ::fabsf(k); }
00189 
00191     static Real sqroot(Real k) { return ::sqrtf(k); }
00192 
00194     static Real sine(Real k) { return ::sinf(k); }
00195 
00197     static Real asine(Real k) { return ::asinf(k); }
00198 
00200     static Real cosine(Real k) { return ::cosf(k); }
00201 
00203     static Real acosine(Real k) { return ::acosf(k); }
00204 
00206     static Real tan(Real k) { return ::tanf(k); }
00207 
00209     static Real atan(Real k) { return ::atanf(k); }
00210 
00212     static Real e(Real k) { return ::expf(k); }
00213 
00215     static Real ln(Real k) { return ::logf(k); }
00216     
00218     static Real power(Real k1,Real k2) { return ::powf(k1,k2); }
00219     
00221     static Real prev_integer(Real a) { return ::floorf(a); };
00222 
00224     static Real next_integer(Real a) { return ::ceilf(a); };
00225     
00227     //static Boolean isfinite(Real k) { return ::finite( static_cast<double>(k) ); }
00228 
00230     //static Real numthreshold() { return FLT_EPSILON; }
00231 
00233     //static Real max() { return FLT_MAX; }
00234 
00236     //static Real min() { return FLT_MIN; }
00237     
00239   
00240 }; // class Numerics<float>
00241 
00242 
00243 
00244 // -------------------------------------------------------
00245 //  
00246 //  Numerics<double> class.
00253 //  
00254 // -------------------------------------------------------
00255 
00256 template <> class Numerics<double>
00257 {
00258 
00259 public:
00260 
00262     typedef bool Boolean;
00263 
00265     typedef double Real;
00266     
00267     
00270     
00272     static inline Real PI()
00273         { return 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998;}
00274         
00277     static inline Real CONV_RAD_TO_DEG()
00278         { return 1.0/2.0/PI()*360.0; }
00279                 
00282     static inline Real CONV_DEG_TO_RAD()
00283         { return 2.0*PI()/360.0; }
00284     
00286     static inline Real E()
00287         { return 2.7182818284590452354; }
00288     
00290     
00293 
00295     static Real fpabs(Real k) { return ::fabs(k); }
00296 
00298     static Real sqroot(Real k) { return ::sqrt(k); }
00299 
00301     static Real sine(Real k) { return ::sin(k); }
00302 
00304     static Real asine(Real k) { return ::asinf(k); }
00305 
00307     static Real cosine(Real k) { return ::cos(k); }
00308 
00310     static Real acosine(Real k) { return ::acos(k); }
00311 
00313     static Real tan(Real k) { return ::tan(k); }
00314 
00316     static Real atan(Real k) { return ::atan(k); }
00317 
00319     static Real e(Real k) { return ::exp(k); }
00320 
00322     static Real ln(Real k) { return ::log(k); }
00323     
00325     static Real power(Real k1,Real k2) { return ::pow(k1,k2); }
00326     
00328     static Real prev_integer(Real a) { return ::floor(a); };
00329 
00331     static Real next_integer(Real a) { return ::ceil(a); };
00332     
00334     //static Boolean isfinite(Real k) { return ::finite(k); }
00335 
00337     //static Real numthreshold() { return DBL_EPSILON; }
00338 
00340     //static Real max() { return DBL_MAX; }
00341 
00343     //static Real min() { return DBL_MIN; }
00344     //
00346   
00347 }; // class Numerics<double>
00348 
00349 
00350 } // namespace animal 
00351 
00352 
00353 
00354 #endif // ANIMAL_TRAITS_NUMERICS_H

Generated on Thu Dec 23 13:52:26 2004 by doxygen 1.3.6