5#define EHS_LOW_WORD(x) *((int*)&x) + 1
12 static float Sqrt_AVX(
const float from);
14 static double Sqrt_AVX(
const double from);
16 static float Sqrt_SSE(
const float from);
18 static double Sqrt_SSE2(
const double from);
20 static float Sqrt_VFP4(
const float from);
22 static double Sqrt_VFP4(
const double from);
25 constexpr static float fltEpsilon = 1e-7f;
26 constexpr static double dblEpsilon = 1e-16;
29 static bool AbsCmp(
float a,
float b);
32 static bool AbsCmp(
double a,
double b);
35 static bool RelCmp(
float a,
float b);
38 static bool RelCmp(
double a,
double b);
41 static bool ComCmp(
float a,
float b);
44 static bool ComCmp(
double a,
double b);
46 template<
typename T =
float>
47 static T
Max(
const T a,
const T b)
52 template<
typename T =
float>
53 static T
Min(
const T a,
const T b)
58 template<
typename T =
float>
59 static T
Clamp(
const T value,
const T min,
const T max)
69 template<
typename T =
float>
70 static T
Abs(
const T from)
72 return from < 0 ? -from : from;
78 template<
typename T =
float>
79 static constexpr T
Pi()
81 return (T)3.141592653589793238462643383279502884L;
88 template<
typename T =
float>
89 static T
Rads(
const T from)
91 return from * 0.01745329251994329576923690768489;
98 template<
typename T =
float>
99 static T
Degr(
const T from)
101 return from * 57.295779513082320876798154814105;
104 template <
typename T =
float>
110 for (
int n = 1; n <= 20; ++n)
119 template <
typename T =
float>
123 T term = (x - 1) / (x + 1);
124 T term_squared = term * term;
126 T current_term = term;
128 for (
int n = 0; n < 100; ++n)
130 result += current_term / denominator;
131 current_term *= term_squared;
138 template <
typename T =
float>
160 T result = Ln_Taylor<T>(x);
161 result += exp * Ln_Taylor<T>(2);
172 template<
typename T =
float,
typename I =
float>
173 static T
Pow(
const T base,
const I exponent)
176 return (exponent == 0) ? 1 : 0;
181 SSize intExp = (SSize)exponent;
182 bool isInteger = exponent == intExp;
183 bool isNeg = base < 0;
185 if (isNeg && isInteger)
187 T result = Exp<T>(exponent * Ln<T>(-base));
188 if ((SSize)exponent % 2)
194 if (isNeg && !isInteger)
196 T magnitude = Exp<T>(exponent * Ln<T>(-base));
197 T angle = exponent * Pi<T>();
198 T realPart = magnitude * Cos<T>(angle);
199 T imagPart = magnitude * Sin<T>(angle);
204 return Exp<T>(exponent * Ln<T>(base));
207 template <
typename T =
float>
210 return Ln<T>(x) / Ln<T>(10);
213 static float Near(
const float from);
215 static double Near(
const double from);
217 static float Floor(
const float from);
219 static double Floor(
const double from);
221 static float Ceil(
const float from);
223 static double Ceil(
const double from);
225 static float Trunc(
const float from);
227 static double Trunc(
const double from);
229 static float Mod(
const float from,
const float divisor);
231 static double Mod(
const double from,
const double divisor);
237 template<
typename T =
float>
243 while (result != temp)
246 result = (from / temp + temp) / 2;
252 static double Sqrt(
const double from);
254 static float Sqrt(
const float from);
256 template<
typename R =
float>
257 static R
Sin(
const R angle,
const R precision = 0.001)
262 for (UInt_64 i = 1; Abs<R>(term) >= precision; ++i)
264 term *= -angle * angle / (R)((2 * i + 1) * (2 * i));
280 template<
typename R =
float,
typename T = UInt_64>
281 static R
ASin(
const R yPos,
const T precision = 10)
285 for (T n = 0; n < precision; ++n)
286 sum += (R)Fact<T>(2 * n) / (Pow<R>(4, n) * Pow<R>((R)Fact<T>(n), 2) * (2 * n + 1)) * Pow<R>(yPos, 2 * n + 1);
297 template<
typename R =
float>
298 static R
Cos(
const R angle,
const R precision = 0.001)
303 for (UInt_64 i = 2; Abs<R>(term) >= precision; i += 2)
305 term *= -angle * angle / (R)(i * (i - 1));
327 template<
typename R =
float,
typename T = UInt_64>
328 static R
ACos(
const R xPos,
const T precision = 10)
330 return Pi<R>() / 2 - ASin<R, T>(xPos, precision);
333 template<
typename R =
float>
334 static R
Tan(
const R angle,
const R precision = 0.001)
344 return Sin<R>(angle) / Cos<R>(angle);
347 template<
typename R =
float,
typename T = UInt_64>
348 static R
ATan(
const R x,
const T precision = 1)
352 for (T n = 0; n < precision; ++n)
353 sum += Pow<R>(-1, n) / (2 * n + 1) * Pow<R>(x, 2 * n + 1);
358 template<
typename R =
float>
359 static R
Cot(
const R x,
const R precision = 0.001)
361 return 1 / Tan<R>(x, precision);
364 template<
typename T = UInt_64>
370 return n * Fact<T>(n - 1);
373 template<
typename R =
float,
typename T = UInt_64>
377 return (R)Fact<T>(n) / (R)(Fact<T>(n - k) * Fact<T>(k));
382 template<
typename R =
float,
typename T = UInt_64>
383 static R
B(
const T n)
388 for (T k = 0; k <= n; ++k)
390 for (T r = 0; r <= k; ++r)
391 innerSum += Pow<R, T>(-1, r) * Combination<R, T>(k, r) * Pow<R, T>(r, n);
393 outerSum += 1 / ((R)k + 1) * innerSum;
static T Max(const T a, const T b)
Definition: Math.h:47
static T Clamp(const T value, const T min, const T max)
Definition: Math.h:59
static R Combination(const T n, const T k)
Definition: Math.h:374
static double Floor(const double from)
static R ATan(const R x, const T precision=1)
Definition: Math.h:348
static constexpr T Pi()
Definition: Math.h:79
static T Min(const T a, const T b)
Definition: Math.h:53
static T Pow(const T base, const I exponent)
Definition: Math.h:173
static T Degr(const T from)
Definition: Math.h:99
static T Rads(const T from)
Definition: Math.h:89
static R Sin(const R angle, const R precision=0.001)
Definition: Math.h:257
static float Trunc(const float from)
static R Cot(const R x, const R precision=0.001)
Definition: Math.h:359
static T Ln_Taylor(T x)
Definition: Math.h:120
static double Near(const double from)
static R Cos(const R angle, const R precision=0.001)
Definition: Math.h:298
static T Ln(T x)
Definition: Math.h:139
static float Ceil(const float from)
static R B(const T n)
Definition: Math.h:383
static T Fact(const T n)
Definition: Math.h:365
static R ACos(const R xPos, const T precision=10)
Definition: Math.h:328
static T Log10(const T x)
Definition: Math.h:208
static R Tan(const R angle, const R precision=0.001)
Definition: Math.h:334
static float Floor(const float from)
static T Abs(const T from)
Definition: Math.h:70
static float Near(const float from)
static T Exp(const T x)
Definition: Math.h:105
static T Sqrt(const T from)
Definition: Math.h:238
static double Ceil(const double from)
static double Trunc(const double from)
static R ASin(const R yPos, const T precision=10)
Definition: Math.h:281