27 #include "common/scummsys.h" 43 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_setjmp 45 #define setjmp(a) FORBIDDEN_SYMBOL_REPLACEMENT 48 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_longjmp 50 #define longjmp(a,b) FORBIDDEN_SYMBOL_REPLACEMENT 55 #define FLT_MIN 1E-37f 59 #define FLT_MAX 1E+37f 65 inline int intLog2(uint32 v) {
75 return (
sizeof(
unsigned int) * 8 - 1) - __builtin_clz(v);
77 #elif defined(_MSC_VER) 78 inline int intLog2(uint32 v) {
79 unsigned long result = 0;
80 unsigned char nonZero = _BitScanReverse(&result, v);
83 return nonZero ? result : -1;
87 static const char LogTable256[256] = {
88 #define LT(n) n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n 89 -1, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
90 LT(4), LT(5), LT(5), LT(6), LT(6), LT(6), LT(6),
91 LT(7), LT(7), LT(7), LT(7), LT(7), LT(7), LT(7), LT(7)
95 inline int intLog2(uint32 v) {
99 return (t = tt >> 8) ? 24 + LogTable256[t] : 16 + LogTable256[tt];
101 return (t = v >> 8) ? 8 + LogTable256[t] : LogTable256[v];
107 template<
class InputT,
class OutputT>
108 inline OutputT trunc(InputT x) {
109 return (x > 0) ? floor(x) : ceil(x);
115 inline T trunc(T x) {
116 return trunc<T,T>(x);
122 template<
class InputT,
class OutputT>
123 inline OutputT rad2deg(InputT rad) {
124 return (OutputT)( (float)rad * (
float)57.2957795130823);
128 template<
class OutputT>
129 inline OutputT rad2deg(
double rad) {
130 return (OutputT)( rad * 57.2957795130823);
136 inline T rad2deg(T rad) {
137 return rad2deg<T,T>(rad);
143 template<
class InputT,
class OutputT>
144 inline OutputT deg2rad(InputT deg) {
145 return (OutputT)( (float)deg * (
float)0.0174532925199433);
149 template<
class OutputT>
150 inline OutputT deg2rad(
double deg) {
151 return (OutputT)( deg * 0.0174532925199433);
157 inline T deg2rad(T deg) {
158 return deg2rad<T,T>(deg);
162 inline T hypotenuse(T xv, T yv) {
163 return (T)sqrt((
double)(xv * xv + yv * yv));
168 #endif // COMMON_MATH_H Definition: algorithm.h:29