10 #define PI (3.14159265358979324)
11 #define PI_f (3.14159265358979324f)
14 #define TWOPI (2.0 * PI)
17 #define FOURPI (4.0 * PI)
21 #define HALFPI (0.5 * PI)
24 #define _doublemagicroundeps (.5-1.4e-11) //almost .5f = .5f - 1e^(number of exp bit)
25 #if (defined(_WIN32) & !defined(_WIN64))
38 #define _doublemagic double (6755399441055744.0) //2^52 * 1.5, uses limited precision to floor
40 return ((
long*)&val)[0];
89 return (value < min) ? min : (value >
max) ? max : value;
95 if (value >= max)
return 1;
96 value = (value -
min)/(max-min);
97 return (value * value * (3 - 2 * value));
103 if (value >= 1)
return 1;
104 return (value * value * (3 - 2 * value));
109 int Mod(
const Type a,
const Type b)
113 if (r < 0) r += (int)b;
118 template <
class Type>
121 return deg *
static_cast<Type
>(0.017453292519943295769236907684886);
124 template <
class Type>
127 return rad *
static_cast<Type
>(57.2957795130823208767981548141052);
131 template <
class Type>
134 return (a > b ? a : b);
137 template <
class Type>
140 return Max(v[0],
Max(v[1], v[2]));
144 template <
class Type>
145 Type
Min(
const Type a,
const Type b)
147 return (a < b ? a : b);
150 template <
class Type>
153 return Min(v[0],
Min(v[1], v[2]));
158 template <
class Type>
164 template <
class Type>
167 return log(a) / log((Type)2);
170 template <
class Type>
173 return (x * (max - min) + min);
177 template <
class Type>
180 return (x >= min) && (x <=
max);
183 template <
class Type>
186 return (x - min) / (max -
min);
189 template <
class Type>
191 return (static_cast<int> (x)) - (x < 0 && (x != static_cast<int>(x)));
194 template <
class Type>
197 return ((
int)x) + (x > 0 && (x != (int) x));
200 template <
class Type>
203 return (r > 0.0) ?
Floor(r + 0.5) :
Ceil(r - 0.5);
210 template <
class T> T
Lerp (
const double f,
const T a,
const T b)
212 const double g = 1.0 - f;
213 return T( a * g + b * f );
216 template <
class T>
void Swap (T &a, T &b)
227 inline double xztoh (
const double x,
const double z)
235 inline void xyztohp (
const double x,
const double y,
const double z,
double &h,
double &p)
238 p = atan2(y, sqrt (
Sqr(x) +
Sqr(z)));
243 return (a > static_cast<T>(0)) ?
static_cast<T
>(1) : static_cast<T>(-1);
248 #endif // LWPP_MATH_H