00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef COMMON_MATH_H
00026 #define COMMON_MATH_H
00027
00028 #include "common/scummsys.h"
00029 #ifdef _MSC_VER
00030
00031
00032
00033
00034
00035
00036 #undef setjmp
00037 #undef longjmp
00038 #include <intrin.h>
00039
00040
00041
00042
00043
00044 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_setjmp
00045 #undef setjmp
00046 #define setjmp(a) FORBIDDEN_SYMBOL_REPLACEMENT
00047 #endif
00048
00049 #ifndef FORBIDDEN_SYMBOL_EXCEPTION_longjmp
00050 #undef longjmp
00051 #define longjmp(a,b) FORBIDDEN_SYMBOL_REPLACEMENT
00052 #endif
00053 #endif
00054
00055 #ifndef FLT_MIN
00056 #define FLT_MIN 1E-37
00057 #endif
00058
00059 #ifndef FLT_MAX
00060 #define FLT_MAX 1E+37
00061 #endif
00062
00063 namespace Common {
00064
00066 struct Complex {
00067 float re, im;
00068 };
00069
00070 #if GCC_ATLEAST(3, 4)
00071 inline int intLog2(uint32 v) {
00072
00073
00074
00075 if (v == 0)
00076 return -1;
00077 else
00078
00079
00080
00081 return (sizeof(unsigned int) * 8 - 1) - __builtin_clz(v);
00082 }
00083 #elif defined(_MSC_VER)
00084 inline int intLog2(uint32 v) {
00085 unsigned long result = 0;
00086 unsigned char nonZero = _BitScanReverse(&result, v);
00087
00088
00089 return nonZero ? result : -1;
00090 }
00091 #else
00092
00093 static const char LogTable256[256] = {
00094 #define LT(n) n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n
00095 -1, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
00096 LT(4), LT(5), LT(5), LT(6), LT(6), LT(6), LT(6),
00097 LT(7), LT(7), LT(7), LT(7), LT(7), LT(7), LT(7), LT(7)
00098 };
00099
00100 inline int intLog2(uint32 v) {
00101 uint32 t, tt;
00102
00103 if ((tt = v >> 16))
00104 return (t = tt >> 8) ? 24 + LogTable256[t] : 16 + LogTable256[tt];
00105 else
00106 return (t = v >> 8) ? 8 + LogTable256[t] : LogTable256[v];
00107 }
00108 #endif
00109
00110
00111
00112
00113 template<class InputT, class OutputT>
00114 inline OutputT rad2deg(InputT rad) {
00115 return (OutputT)( (float)rad * (float)57.2957795130823);
00116 }
00117
00118
00119 template<class OutputT>
00120 inline OutputT rad2deg(double rad) {
00121 return (OutputT)( rad * 57.2957795130823);
00122 }
00123
00124
00125
00126 template<class T>
00127 inline T rad2deg(T rad) {
00128 return rad2deg<T,T>(rad);
00129 }
00130
00131
00132
00133
00134 template<class InputT, class OutputT>
00135 inline OutputT deg2rad(InputT deg) {
00136 return (OutputT)( (float)deg * (float)0.0174532925199433);
00137 }
00138
00139
00140 template<class OutputT>
00141 inline OutputT deg2rad(double deg) {
00142 return (OutputT)( deg * 0.0174532925199433);
00143 }
00144
00145
00146
00147 template<class T>
00148 inline T deg2rad(T deg) {
00149 return deg2rad<T,T>(deg);
00150 }
00151
00152 }
00153
00154 #endif // COMMON_MATH_H