32 const float PI_ = 3.1415926535897932384626433832795028841972;
33 const float ONE_OVER_PI = (0.3183098861837906661338147750939f);
34 const float TWOPI = (6.2831853071795864769252867665590057683943f);
36 const float PI_2 = (1.5707963267948966192313216916397514420986f);
37 const float TWO_OVER_PI = (0.636619772367581332267629550188f);
38 const float LN2 = (0.6931471805599453094172321214581765680755f);
40 const float LN10 = (2.3025850929940456840179914546843642076011f);
47 const float ROOT2 = (1.4142135623730950488016887242096980785697f);
53 return (
float) sin((
double)x);
56 register float accumulator, xPower, xSquared;
57 register long evenIntPart = ((long)(0.5f*x + 1024.5) - 1024)<<1;
58 x -= (float)evenIntPart;
60 accumulator = 3.14159265358979f*x;
62 accumulator += -5.16731953364340f*xPower;
64 accumulator += 2.54620566822659f*xPower;
66 accumulator += -0.586027023087261f*xPower;
68 accumulator += 0.06554823491427f*xPower;
76 return (
float) cos((
double)x);
79 register float accumulator, xPower, xSquared;
81 register long evenIntPart = ((long)(0.5f*x + 1024.5f) - 1024)<<1;
82 x -= (float)evenIntPart;
85 accumulator = 1.57079632679490f*x;
87 accumulator += -0.64596406188166f*xPower;
89 accumulator += 0.07969158490912f*xPower;
91 accumulator += -0.00467687997706f*xPower;
93 accumulator += 0.00015303015470f*xPower;
94 return 1.0f - 2.0f*accumulator*accumulator;
100 #ifndef CLAM_OPTIMIZE
101 return (
float) atan((
double)x);
103 register float accumulator, xPower, xSquared, offset;
120 accumulator += 0.33288950512027f*xPower;
122 accumulator += -0.08467922817644f*xPower;
124 accumulator += 0.03252232640125f*xPower;
126 accumulator += -0.00749305860992f*xPower;
128 return offset + x/accumulator;
134 #ifndef CLAM_OPTIMIZE
135 return (
float) atan2((
double)Imag, (
double)Real);
137 if(Real==0 && Imag==0)
return 0.f;
138 register float accumulator, xPower, xSquared, offset, x;
147 else if (Imag > Real)
165 else if (Imag < -Real)
180 accumulator += 0.33288950512027f*xPower;
182 accumulator += -0.08467922817644f*xPower;
184 accumulator += 0.03252232640125f*xPower;
186 accumulator += -0.00749305860992f*xPower;
188 return offset + x/accumulator;
194 #ifndef CLAM_OPTIMIZE
195 return (
float) exp(
LN2*(
double)x);
199 register float accumulator, xPower;
200 register union {
float f;
long i;} xBits;
203 x -= (float)(xBits.i);
205 accumulator = 1.0f + 0.69303212081966f*x;
207 accumulator += 0.24137976293709f*xPower;
209 accumulator += 0.05203236900844f*xPower;
211 accumulator += 0.01355574723481f*xPower;
216 return accumulator * xBits.f;
227 #ifndef CLAM_OPTIMIZE
230 if (x > 5.877471754e-39f)
232 register float accumulator, xPower;
233 register long intPart;
235 register union {
float f;
long i;} xBits;
239 intPart = ((xBits.i)>>23);
242 x = (float)(xBits.i & 0x007FFFFF);
243 x *= 1.192092895507812e-07f;
245 accumulator = 1.44254494359510f*x;
247 accumulator += -0.71814525675041f*xPower;
249 accumulator += 0.45754919692582f*xPower;
251 accumulator += -0.27790534462866f*xPower;
253 accumulator += 0.12179791068782f*xPower;
255 accumulator += -0.02584144982967f*xPower;
257 return accumulator + (float)intPart;
268 #ifndef CLAM_OPTIMIZE
269 return (
float) pow((
double)x, (
double)y);
277 #ifndef CLAM_OPTIMIZE
278 return (
float) sqrt((
double)x);
280 if (x > 5.877471754e-39f)
282 register float accumulator, xPower;
283 register long intPart;
284 register union {
float f;
long i;} xBits;
288 intPart = ((xBits.i)>>23);
291 x = (float)(xBits.i & 0x007FFFFF);
292 x *= 1.192092895507812e-07f;
294 accumulator = 1.0f + 0.49959804148061f*x;
296 accumulator += -0.12047308243453f*xPower;
298 accumulator += 0.04585425015501f*xPower;
300 accumulator += -0.01076564682800f*xPower;
302 if (intPart & 0x00000001)
304 accumulator *=
ROOT2;
307 xBits.i = intPart >> 1;
311 return accumulator * xBits.f;
322 #ifndef CLAM_OPTIMIZE
323 return (
float) log((
double)x);
331 #ifndef CLAM_OPTIMIZE
332 return (
float) log10((
double)x);
340 #ifndef CLAM_OPTIMIZE
341 return (
float) 20*log10((
double)x);
349 #ifndef CLAM_OPTIMIZE
350 return (
float) exp((
double)x);
356 #if defined _MSC_VER && _MSC_VER < 1310 // MSVC++ 6
361 template <
typename T >
362 const T& max(
const T& a,
const T& b) {
363 return (a>=b)? a : b;
365 template <
typename T >
366 const T& min(
const T& a,
const T& b) {
367 return (a<=b)? a : b;
372 #if defined _MSC_VER // MSVC++7
375 template <
typename T>
378 return _isnan(data) == 1;
380 template <
typename T>
383 return _isnan(data) == 1;
391 {
return (floor(_X+0.5)); }
393 {
return (floorf(_X+0.5f)); }
395 #endif // __USE_ISOC99
405 return CLAM_exp( x * 0.1151292546497f );
416 return (((n - 1) & n) == 0);
442 template <
class T>
inline T
Abs(T value)
444 return ( value < 0 ) ? -value : value;
450 #define CLAM_DB_SCALING 20
452 inline double DB(
double linData,
int scaling=20)
457 inline double Lin(
double logData,
int scaling=20 )
459 return (
CLAM_pow(
double(10),(logData/scaling)) );
466 template<
class T>
inline
468 {
return (x < y ? y : x); }
470 template<
class T>
inline
472 {
return (x > y ? y : x); }
475 #endif // CLAM_Math.hxx