Changeset 333 for libmpc/trunk/include
- Timestamp:
- 06/09/07 17:43:34 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libmpc/trunk/include/mpc/mpcmath.h
r156 r333 18 18 19 19 #include <mpc/mpc_types.h> 20 21 typedef union mpc_floatint 22 { 23 float f; 24 mpc_int32_t n; 25 } mpc_floatint; 26 27 static mpc_inline mpc_int32_t mpc_lrintf(float fVal) 28 { 29 mpc_floatint tmp; 30 tmp.f = fVal + 0x00FF8000; 31 return tmp.n - 0x4B7F8000; 32 } 33 34 #define mpc_round32 mpc_lrintf 35 #define mpc_nearbyintf mpc_lrintf 36 20 37 21 38 #ifndef M_PI … … 55 72 #endif 56 73 57 #define SQRTF(x) SQRT (x) 58 #define COSF(x) COS (x) 59 #define ATAN2F(x,y) ATAN2 (x,y) 60 #define IFLOORF(x) IFLOOR (x) 74 #define SQRTF(x) SQRT (x) 75 #ifdef FAST_MATH 76 # define TABSTEP 64 77 # define COSF(x) my_cos ((float)(x)) 78 # define ATAN2F(x,y) my_atan2 ((float)(x), (float)(y)) 79 # define IFLOORF(x) my_ifloor ((float)(x)) 61 80 62 typedef union mpc_floatint 81 void Init_FastMath ( void ); 82 extern const float tabatan2 [] [2]; 83 extern const float tabcos [] [2]; 84 extern const float tabsqrt_ex []; 85 extern const float tabsqrt_m [] [2]; 86 87 static mpc_inline float my_atan2 ( float x, float y ) 63 88 { 64 float f; 65 mpc_int32_t n; 66 } mpc_floatint; 89 float t, ret; int i; mpc_floatint mx, my; 67 90 68 static mpc_inline mpc_int32_t mpc_lrintf(float fVal) 69 { 70 mpc_floatint tmp; 71 tmp.f = fVal + 0x00FF8000; 72 return tmp.n - 0x4B7F8000; 91 mx.f = x; 92 my.f = y; 93 if ( (mx.n & 0x7FFFFFFF) < (my.n & 0x7FFFFFFF) ) { 94 i = mpc_round32 (t = TABSTEP * (mx.f / my.f)); 95 ret = tabatan2 [1*TABSTEP+i][0] + tabatan2 [1*TABSTEP+i][1] * (t-i); 96 if ( my.n < 0 ) 97 ret = (float)(ret - M_PI); 98 } 99 else if ( mx.n < 0 ) { 100 i = mpc_round32 (t = TABSTEP * (my.f / mx.f)); 101 ret = - M_PI/2 - tabatan2 [1*TABSTEP+i][0] + tabatan2 [1*TABSTEP+i][1] * (i-t); 102 } 103 else if ( mx.n > 0 ) { 104 i = mpc_round32 (t = TABSTEP * (my.f / mx.f)); 105 ret = + M_PI/2 - tabatan2 [1*TABSTEP+i][0] + tabatan2 [1*TABSTEP+i][1] * (i-t); 106 } 107 else { 108 ret = 0.; 109 } 110 return ret; 73 111 } 74 112 75 static mpc_inline float mpc_nearbyintf(float fVal) 113 114 static mpc_inline float my_cos ( float x ) 76 115 { 77 return (float) mpc_lrintf(fVal); 116 float t, ret; int i; 117 i = mpc_round32 (t = TABSTEP * x); 118 ret = tabcos [13*TABSTEP+i][0] + tabcos [13*TABSTEP+i][1] * (t-i); 119 return ret; 78 120 } 79 121 122 123 static mpc_inline int my_ifloor ( float x ) 124 { 125 mpc_floatint mx; 126 mx.f = (float) (x + (0x0C00000L + 0.500000001)); 127 return mx.n - 1262485505; 128 } 129 130 131 static mpc_inline float my_sqrt ( float x ) 132 { 133 float ret; int i, ex; mpc_floatint mx; 134 mx.f = x; 135 ex = mx.n >> 23; // get the exponent 136 mx.n = (mx.n & 0x7FFFFF) | 0x42800000; // delete the exponent 137 i = mpc_round32 (mx.f); // Integer-part of the mantissa (round ????????????) 138 ret = tabsqrt_m [i-TABSTEP][0] + tabsqrt_m [i-TABSTEP][1] * (mx.f-i); // calculate value 139 ret *= tabsqrt_ex [ex]; 140 return ret; 141 } 142 #else 143 # define COSF(x) COS (x) 144 # define ATAN2F(x,y) ATAN2 (x,y) 145 # define IFLOORF(x) IFLOOR (x) 146 #endif 147
Note: See TracChangeset
for help on using the changeset viewer.