#ifndef COMMON_MATH_LIBRARY_H #define COMMON_MATH_LIBRARY_H #define TAYLOR_SERIES_DEGREE 34 const float PI = 3.1415926535897932384626433f; /** * Compute the factorial of parameter x. * This function only properly works on natural numbers. * The implementation is an iterative one and is only limited by the size * of the type used in the calculation. * @param x the factorial of x or 1 if x < 0 * @return the factorial for x */ long long fac(long long x); /** * Truncates the parameter x. * In other words this function will cut of the fraction part of the number x. * @param x * @return trunc(x) */ inline float trunc(float x); /** * Computes the fraction of x. * In other words this function will only keep the fractional part and cut of the integral. * @param x * @return fract(x) */ inline float fract(float x); /** * Computes the floor of x. * In other words this function will round x towards negative infinity. * This is effectively the same as trunc(x) * @param x * @return floor(x) */ inline float floor(float x); /** * Computes the ceil of x. * In other words this function will round x towards positive infinity * @param x * @return ceil(x) */ inline float ceil(float x); /** * Round the number x. * In other words this function will round x towards negative infinity if x the fraction of x is smaller than 0.5 and else * towards positive infinity * @param x * @return round(x) */ inline float round(float x); /** * Compute the modulo division of x and y. * @param x * @param y * @return mod(x,y) */ float mod(float x, float y); /** * Computes the result of e raised to the power of x. * This function only performs an approximation based on the famous taylor series for e^x. * @param x the exponent of e^x * @return approximation of e^x */ float exp(float x); /** * Computes the sine of x. * @param x * @return sin(x) */ float sin(float x); /** * Computes the cosine of x. * @param x * @return cos(x) */ float cos(float x); /** * Computes the tangent of x. * @param x * @return tan(x) */ float tan(float x); #endif //COMMON_MATH_LIBRARY_H