51 # define M_E 2.7182818284590452354 52 # define M_LOG2E 1.4426950408889634074 53 # define M_LOG10E 0.43429448190325182765 54 # define M_LN2 0.69314718055994530942 55 # define M_LN10 2.30258509299404568402 56 # define M_PI 3.14159265358979323846 57 # define M_PI_2 1.57079632679489661923 58 # define M_PI_4 0.78539816339744830962 59 # define M_1_PI 0.31830988618379067154 60 # define M_2_PI 0.63661977236758134308 61 # define M_2_SQRTPI 1.12837916709551257390 62 # define M_SQRT2 1.41421356237309504880 63 # define M_SQRT1_2 0.70710678118654752440 80 inline double Mod(
double a,
double b)
82 double c = fmod(a, b);
83 return c >= 0 ? c : c + b;
88 inline double Mod(
double a,
int b)
90 return Mod(a,
double(b));
95 inline int Mod(
int a,
int b)
98 return c >= 0 ? c : c + b;
103 inline long int Mod(
long int a,
long int b)
106 return c >= 0 ? c : c + b;
113 return a >= 0 ? 1 : -1;
118 inline int Sgn(
long double a)
120 return a >= 0 ? 1 : -1;
127 return a > 0 ? 1 : a < 0 ? -1 : 0;
134 return a > 0 ? 1 : a < 0 ? -1 : 0;
141 return a >= 0 ? 1 : -1;
148 return a > 0 ? 1 : a < 0 ? -1 : 0;
155 static double factor = 180 / M_PI;
163 static double factor = M_PI / 180;
170 return Mod(angle, 2*M_PI);
176 return Mod(angle + M_PI, 2*M_PI) - M_PI;
184 return Mod(angle + 180, 360) - 180;
188 inline int Pow(
int a,
int b)
191 for (ret = 1; b > 0; --b)
196 inline double Round(
double value,
int precision = 0)
198 double fact = pow(1e1, precision);
199 return floor(((value*fact) + 0.5)) / fact;
203 inline double Ceil(
double value,
int precision = 0)
205 double fact = pow(1e1, precision);
206 return ceil(value*fact) / fact;
210 inline double Floor(
double value,
int precision = 0)
212 double fact = pow(1e1, precision);
213 return floor(value*fact) / fact;
217 inline int*
Add(
int *a,
int*b,
int size)
220 for (i = 0; i < size; i++)
226 inline int*
Sum(
int *a,
int*b,
int*c,
int size)
229 for (i = 0; i < size; i++)
235 inline int*
Div(
int* a,
int b,
int size)
238 for (i = 0; i < size; i++)
244 inline int*
Div(
int* a,
int b,
int*c,
int size)
247 for (i = 0; i < size; i++)
271 return float(rand()) / RAND_MAX;
280 return 2*float(rand()) / RAND_MAX - 1;
289 double r1 = (float((rand()) + 1) / (float(RAND_MAX) + 1));
290 double r2 = float(rand()) / RAND_MAX;
291 #ifdef MATH_USE_TABLE_LOOKUP 292 return variance*sqrt(-2*log(r1))*
FastSin(2*M_PI*r2);
294 return variance*sqrt(-2*log(r1))*sin(2*M_PI*r2);
308 inline int ipow(
int base,
int exponent)
317 for (
int i = 1; i <= exponent; i++)
358 inline void SinCos(
const double x,
double &sx,
double &cx)
360 #if defined _SYSTEM_LINUX_ && ! defined _SYSTEM_DARWIN_ 375 double increment = 2. * M_PI / double(
cTABLE_SIZE);
407 double table_index = ::floor(scaled_x);
408 double y1 = sin_cos_lookup_table.
Sin(
int(table_index));
409 double y2 = sin_cos_lookup_table.
Sin(
int(table_index) + 1);
410 return y1 + (y2 - y1) * (scaled_x - table_index);
416 double table_index = ::floor(scaled_x);
417 double y1 = sin_cos_lookup_table.
Cos(
int(table_index));
418 double y2 = sin_cos_lookup_table.
Cos(
int(table_index) + 1);
419 return y1 + (y2 - y1) * (scaled_x - table_index);
430 inline bool FloatIsEqual(
const double a,
const double b,
const double epsilon = 1e-10)
void SinCos(const double x, double &sx, double &cx)
double Ceil(double value, int precision=0)
int * Sum(int *a, int *b, int *c, int size)
tSinCosLookupTable sin_cos_lookup_table
double RandomUniformAbs()
int ipow(int base, int exponent)
An integer pow-function.
double Round(double value, int precision=0)
double NormalizeAngleUnsigned(const double angle)
int log8upw(int value)
calculates log_8, rounded upward
bool FloatIsEqual(const double a, const double b, const double epsilon=1e-10)
double m_cos_table[cTABLE_SIZE]
int * Div(int *a, int b, int size)
static const int cTABLE_SIZE
TFSIMD_FORCE_INLINE const tfScalar & x() const
int * Add(int *a, int *b, int size)
double NormalizeAngleSigned(const double angle)
static const int cTABLE_INDEX_MASK
double Mod(double a, double b)
static const double cSCALE_FACTOR
double NormalizeAngleInDegreeSigned(const double angle)
int log2upw(int value)
calculates log_2, rounded upward
double Floor(double value, int precision=0)
double m_sin_table[cTABLE_SIZE]
double RandomNormal(double variance)