![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsMath.hpp 00003 00004 Under TAPs namespace 00005 Defines a Math class for basic math. 00006 All member functions and data members are static. 00007 00008 SUKITTI PUNAK (09/05/2004) 00009 UPDATE (03/23/2006) 00010 ******************************************************************************/ 00011 #ifndef TAPs_MATH_HPP 00012 #define TAPs_MATH_HPP 00013 00014 #include "TAPsStdLib.hpp" 00015 00016 BEGIN_NAMESPACE_TAPs 00017 //============================================================================= 00018 template <typename T> 00019 class Math { 00020 public: 00021 //============================================================================= 00022 //========================================================================== 00023 // Constant Values 00024 //========================================================================== 00025 static const T ZERO; 00026 static const T ONE; 00027 static const T EPSILON; // the smallest difference b/w 1 & the next value > 1 00028 static const T INFINITY; // the value of positive infinity 00029 static T ThresholdZero; // threshold for zero value (should not be changed) 00030 //----------------------------------------------------------------------------- 00031 // max() and min() are defined as macros in numeric_limits from <limits>. 00032 // However, windows.h also has max(a,b) and min(a,b) as macro. 00033 // Therefore, if windows.h is included, then these two fns will not work properly. 00034 #ifndef _WINDOWS_ 00035 static const T MAX; // the maximum finite value 00036 static const T MIN; // the minimum finite value 00037 #endif 00038 static const T ROUND_ERROR; // the maximum rounding error 00039 static const T PI; // radians of 180 degrees 00040 static const T TWO_PI; // radians of 360 degrees 00041 static const T HALF_PI; // radians of 90 degrees 00042 static const T QUARTER_PI; // radians of 45 degrees 00043 static const T DEG_TO_RAD; // degrees to radians 00044 static const T RAD_TO_DEG; // radians to degrees 00045 //========================================================================== 00046 // Functions 00047 //========================================================================== 00048 //------------------------------------------------------------------------- 00049 // Absolute, Ceil, Floor, and Sign 00050 static inline T Abs ( T tValue ); 00051 static inline T Ceil ( T tValue ); 00052 static inline T Floor ( T tValue ); 00053 static inline T Sign ( T tValue ); 00054 //------------------------------------------------------------------------- 00055 // Trigonometric Functions 00056 static inline T Sin ( T tValue ); // sine 00057 static inline T Cos ( T tValue ); // cosine 00058 static inline T Tan ( T tValue ); // tangent 00059 static inline T Csc ( T tValue ); // cosecant 00060 static inline T Sec ( T tValue ); // secant 00061 static inline T Cot ( T tValue ); // cotangent 00062 //------------------------------------------------------------------------- 00063 // Inverse Trigonometric Functions 00064 static inline T ASin ( T tValue ); // arc sine 00065 static inline T ACos ( T tValue ); // arc cosine 00066 static inline T ATan ( T tValue ); // arc tangent 00067 static inline T ATan2 ( T tY, T tX ); 00068 //static inline T ACsc ( T tValue ); // arc cosecant 00069 //static inline T ASec ( T tValue ); // arc secant 00070 //static inline T ACot ( T tValue ); // arc cotangent 00071 //------------------------------------------------------------------------- 00072 // Exponential and Logarithmic Functions 00073 static inline T Exp ( T tValue ); // exponential 00074 static inline T Log ( T tValue ); // natural logarithmic 00075 static inline T Log10 ( T tValue ); // common (base10) logarithmic 00076 static inline T Pow ( T tBase, T tExponent ); // power 00077 static inline T Square ( T tValue ); // square 00078 static inline T Sqrt ( T tValue ); // square root 00079 //------------------------------------------------------------------------- 00080 // Random Numbers 00081 static inline T UnitRandom (); // between [0,1] 00082 static inline T SymmetricRandom (); // between [-1,1] 00083 //------------------------------------------------------------------------- 00084 //========================================================================== 00085 }; // END CLASS Math 00086 //============================================================================= 00088 typedef Math<int> Mathi; 00089 typedef Math<float> Mathf; 00090 typedef Math<double> Mathd; 00091 //============================================================================= 00092 END_NAMESPACE_TAPs 00093 //----------------------------------------------------------------------------- 00094 // Include definition if TAPs_USE_EXPORT is not defined 00095 #if !defined( TAPs_USE_EXPORT ) 00096 #include "TAPsMath.cpp" 00097 #endif 00098 //----------------------------------------------------------------------------- 00099 #endif 00100 //345678901234567890123456789012345678901234567890123456789012345678901234567890 00101 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8