Initial Commit
This commit is contained in:
262
common/MATH.HPP
Normal file
262
common/MATH.HPP
Normal file
@@ -0,0 +1,262 @@
|
||||
#ifndef _COMMON_MATH_HPP_
|
||||
#define _COMMON_MATH_HPP_
|
||||
#include <math.h>
|
||||
#ifdef _MSC_VER
|
||||
#if defined(min)
|
||||
#undef min
|
||||
#endif
|
||||
#if defined(max)
|
||||
#undef max
|
||||
#endif
|
||||
#endif
|
||||
class Math
|
||||
{
|
||||
public:
|
||||
Math(void);
|
||||
virtual ~Math();
|
||||
static int round(double someDouble);
|
||||
static int truncate(double someDouble);
|
||||
static float fraction(double someDouble);
|
||||
static float square(float someFloat);
|
||||
static int square(int someInt);
|
||||
static float radians(float someAngleDegrees);
|
||||
static float degrees(float someAngleRadians);
|
||||
static float cosDegrees(float someAngleDegrees);
|
||||
static float sinDegrees(float someAngleDegrees);
|
||||
static float tanDegrees(float someAngleDegrees);
|
||||
static double cos(double angleRadians);
|
||||
static double sin(double angleRadians);
|
||||
static double tan(double angleRadians);
|
||||
static float power(float powerBase,int exponent);
|
||||
static double power(double powerBase,double exponent);
|
||||
static int power(int powerBase,int exponent);
|
||||
static float log(float someFloat);
|
||||
static float exp10(float someFloat);
|
||||
static float sign(float someFloat);
|
||||
static int sign(int someInt);
|
||||
static int sqrt(int someInt);
|
||||
static float sqrt(float someFloat);
|
||||
static double sqrt(double someDouble);
|
||||
static float min(float floatOne,float floatTwo);
|
||||
static float max(float floatOne,float floatTwo);
|
||||
static float min(float floatOne,float floatTwo,float floatThree);
|
||||
static float max(float floatOne,float floatTwo,float floatThree);
|
||||
static float min(float floatOne,float floatTwo,float floatThree,float floatFour);
|
||||
static float max(float floatOne,float floatTwo,float floatThree,float floatFour);
|
||||
static long factorial(long nDegree);
|
||||
static float pi(void);
|
||||
static float pi2(void);
|
||||
static double piOver180();
|
||||
static int abs(int value);
|
||||
private:
|
||||
static const double mscPI;
|
||||
static const double msc2PI;
|
||||
static const double mscLN10;
|
||||
static const double mscOneOverLN10;
|
||||
static const double mscPIOver180;
|
||||
static const double mscPIUnder180;
|
||||
};
|
||||
|
||||
inline
|
||||
Math::Math(void)
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
Math::~Math()
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
int Math::round(double someDouble)
|
||||
{
|
||||
return (int)(someDouble+0.5);
|
||||
}
|
||||
|
||||
inline
|
||||
int Math::truncate(double someDouble)
|
||||
{
|
||||
return (int)someDouble;
|
||||
}
|
||||
|
||||
inline
|
||||
float Math::fraction(double someDouble)
|
||||
{
|
||||
int wholeNumber((int)someDouble);
|
||||
return someDouble-(float)wholeNumber;
|
||||
}
|
||||
|
||||
inline
|
||||
float Math::square(float someFloat)
|
||||
{
|
||||
return someFloat*someFloat;
|
||||
}
|
||||
|
||||
inline
|
||||
int Math::square(int someInt)
|
||||
{
|
||||
return someInt*someInt;
|
||||
}
|
||||
|
||||
inline
|
||||
float Math::radians(float someAngleDegrees)
|
||||
{
|
||||
return (someAngleDegrees*mscPIOver180);
|
||||
}
|
||||
|
||||
inline
|
||||
float Math::degrees(float someAngleRadians)
|
||||
{
|
||||
return (someAngleRadians*mscPIUnder180);
|
||||
}
|
||||
|
||||
inline
|
||||
float Math::cosDegrees(float someAngleDegrees)
|
||||
{
|
||||
return (::cos(radians(someAngleDegrees)));
|
||||
}
|
||||
|
||||
inline
|
||||
float Math::sinDegrees(float someAngleDegrees)
|
||||
{
|
||||
return (::sin(radians(someAngleDegrees)));
|
||||
}
|
||||
|
||||
inline
|
||||
float Math::tanDegrees(float someAngleDegrees)
|
||||
{
|
||||
return (::tan(radians(someAngleDegrees)));
|
||||
}
|
||||
|
||||
inline
|
||||
float Math::log(float someFloat)
|
||||
{
|
||||
return (::log(someFloat)*mscOneOverLN10);
|
||||
}
|
||||
|
||||
inline
|
||||
float Math::exp10(float someFloat)
|
||||
{
|
||||
return (::exp(someFloat*mscLN10));
|
||||
}
|
||||
|
||||
inline
|
||||
float Math::sign(float someFloat)
|
||||
{
|
||||
if(0.00>someFloat)return -1.00;
|
||||
else if(1.00<someFloat)return 1.00;
|
||||
return 0.00;
|
||||
}
|
||||
|
||||
inline
|
||||
int Math::sign(int someInt)
|
||||
{
|
||||
if(0>someInt)return -1;
|
||||
else if(1<someInt)return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline
|
||||
int Math::power(int powerBase,int exponent)
|
||||
{
|
||||
if(!exponent)return 1;
|
||||
return (powerBase*power(powerBase,exponent-1));
|
||||
}
|
||||
|
||||
inline
|
||||
double Math::power(double powerBase,double exponent)
|
||||
{
|
||||
if(!exponent)return 1.00;
|
||||
return ::pow(powerBase,exponent);
|
||||
}
|
||||
|
||||
inline
|
||||
float Math::min(float floatOne,float floatTwo)
|
||||
{
|
||||
return (floatOne<floatTwo?floatOne:floatTwo);
|
||||
}
|
||||
|
||||
inline
|
||||
float Math::max(float floatOne,float floatTwo)
|
||||
{
|
||||
return (floatOne<floatTwo?floatTwo:floatOne);
|
||||
}
|
||||
|
||||
inline
|
||||
float Math::min(float floatOne,float floatTwo,float floatThree)
|
||||
{
|
||||
return min(min(floatOne,floatTwo),floatThree);
|
||||
}
|
||||
|
||||
inline
|
||||
float Math::max(float floatOne,float floatTwo,float floatThree)
|
||||
{
|
||||
return max(max(floatOne,floatTwo),floatThree);
|
||||
}
|
||||
|
||||
inline
|
||||
float Math::min(float floatOne,float floatTwo,float floatThree,float floatFour)
|
||||
{
|
||||
return min(min(floatOne,floatTwo,floatThree),floatFour);
|
||||
}
|
||||
|
||||
inline
|
||||
float Math::max(float floatOne,float floatTwo,float floatThree,float floatFour)
|
||||
{
|
||||
return max(max(floatOne,floatTwo,floatThree),floatFour);
|
||||
}
|
||||
|
||||
inline
|
||||
double Math::cos(double angleRadians)
|
||||
{
|
||||
return ::cos(angleRadians);
|
||||
}
|
||||
|
||||
inline
|
||||
double Math::sin(double angleRadians)
|
||||
{
|
||||
return ::sin(angleRadians);
|
||||
}
|
||||
|
||||
inline
|
||||
double Math::tan(double angleRadians)
|
||||
{
|
||||
return ::tan(angleRadians);
|
||||
}
|
||||
|
||||
inline
|
||||
double Math::sqrt(double someDouble)
|
||||
{
|
||||
return ::sqrt(someDouble);
|
||||
}
|
||||
|
||||
inline
|
||||
float Math::sqrt(float someFloat)
|
||||
{
|
||||
return ::sqrt(someFloat);
|
||||
}
|
||||
|
||||
inline
|
||||
int Math::abs(int value)
|
||||
{
|
||||
return (value<0?-value:value);
|
||||
}
|
||||
|
||||
inline
|
||||
float Math::pi(void)
|
||||
{
|
||||
return mscPI;
|
||||
}
|
||||
|
||||
inline
|
||||
float Math::pi2(void)
|
||||
{
|
||||
return msc2PI;
|
||||
}
|
||||
|
||||
inline
|
||||
double Math::piOver180()
|
||||
{
|
||||
return mscPIOver180;
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user