19 #include <mpc/mpc_types.h> 33 static mpc_inline mpc_int32_t mpc_lrintf(
float fVal)
36 tmp.f = fVal + 0x00FF8000;
37 return tmp.n - 0x4B7F8000;
40 #define mpc_round32 mpc_lrintf 41 #define mpc_nearbyintf mpc_lrintf 45 # define M_PI 3.1415926535897932384626433832795029 // 4*atan(1) 46 # define M_PIl 3.1415926535897932384626433832795029L 47 # define M_LN2 0.6931471805599453094172321214581766 // ln(2) 48 # define M_LN2l 0.6931471805599453094172321214581766L 49 # define M_LN10 2.3025850929940456840179914546843642 // ln 10 */ 50 # define M_LN10l 2.3025850929940456840179914546843642L 54 #if defined(__GNUC__) && !defined(__APPLE__) 55 # define SIN(x) sinf ((float)(x)) 56 # define COS(x) cosf ((float)(x)) 57 # define ATAN2(x,y) atan2f ((float)(x), (float)(y)) 58 # define SQRT(x) sqrtf ((float)(x)) 59 # define LOG(x) logf ((float)(x)) 60 # define LOG10(x) log10f ((float)(x)) 61 # define POW(x,y) expf (logf(x) * (y)) 62 # define POW10(x) expf (M_LN10 * (x)) 63 # define FLOOR(x) floorf ((float)(x)) 64 # define IFLOOR(x) (int) floorf ((float)(x)) 65 # define FABS(x) fabsf ((float)(x)) 67 # define SIN(x) (float) sin (x) 68 # define COS(x) (float) cos (x) 69 # define ATAN2(x,y) (float) atan2 (x, y) 70 # define SQRT(x) (float) sqrt (x) 71 # define LOG(x) (float) log (x) 72 # define LOG10(x) (float) log10 (x) 73 # define POW(x,y) (float) pow (x,y) 74 # define POW10(x) (float) pow (10., (x)) 75 # define FLOOR(x) (float) floor (x) 76 # define IFLOOR(x) (int) floor (x) 77 # define FABS(x) (float) fabs (x) 80 #define SQRTF(x) SQRT (x) 83 # define COSF(x) my_cos ((float)(x)) 84 # define ATAN2F(x,y) my_atan2 ((float)(x), (float)(y)) 85 # define IFLOORF(x) my_ifloor ((float)(x)) 87 void Init_FastMath (
void );
88 extern const float tabatan2 [] [2];
89 extern const float tabcos [] [2];
90 extern const float tabsqrt_ex [];
91 extern const float tabsqrt_m [] [2];
93 static mpc_inline
float my_atan2 (
float x,
float y )
99 if ( (mx.n & 0x7FFFFFFF) < (my.n & 0x7FFFFFFF) ) {
100 i = mpc_round32 (t = TABSTEP * (mx.f / my.f));
101 ret = tabatan2 [1*TABSTEP+i][0] + tabatan2 [1*TABSTEP+i][1] * (t-i);
103 ret = (float)(ret - M_PI);
105 else if ( mx.n < 0 ) {
106 i = mpc_round32 (t = TABSTEP * (my.f / mx.f));
107 ret = - M_PI/2 - tabatan2 [1*TABSTEP+i][0] + tabatan2 [1*TABSTEP+i][1] * (i-t);
109 else if ( mx.n > 0 ) {
110 i = mpc_round32 (t = TABSTEP * (my.f / mx.f));
111 ret = + M_PI/2 - tabatan2 [1*TABSTEP+i][0] + tabatan2 [1*TABSTEP+i][1] * (i-t);
120 static mpc_inline
float my_cos (
float x )
123 i = mpc_round32 (t = TABSTEP * x);
124 ret = tabcos [13*TABSTEP+i][0] + tabcos [13*TABSTEP+i][1] * (t-i);
129 static mpc_inline
int my_ifloor (
float x )
132 mx.f = (float) (x + (0x0C00000L + 0.500000001));
133 return mx.n - 1262485505;
137 static mpc_inline
float my_sqrt (
float x )
142 mx.n = (mx.n & 0x7FFFFF) | 0x42800000;
143 i = mpc_round32 (mx.f);
144 ret = tabsqrt_m [i-TABSTEP][0] + tabsqrt_m [i-TABSTEP][1] * (mx.f-i);
145 ret *= tabsqrt_ex [ex];
149 # define COSF(x) COS (x) 150 # define ATAN2F(x,y) ATAN2 (x,y) 151 # define IFLOORF(x) IFLOOR (x)