仿照TI的IQMATH 定点数学库,自己写了个定点的数学库,方便在ARM7/9,DSP,CORTEX-M3上使用。
使用例子:float temp6=fix2float(arctan(float2fix(1),float2fix(1)));
int32_t arctan( int32_t y, int32_t x )
{
const int32_t ONEQTR_PI = float2fix(M_PI / 4.0);
const int32_t THRQTR_PI = float2fix(3.0 * M_PI / 4.0);
const int32_t OP1 =float2fix(0.1963f);
const int32_t OP2 =float2fix(0.9817f);
const int32_t LEF =float2fix(1e-10f);
int32_t r, angle;
int32_t abs_y = abs(y)+LEF; // kludge to prevent 0/0 condition
if ( x < 0 )
{
r = fixdiv((x + abs_y) , (abs_y - x));
angle = THRQTR_PI;
}
else
{
r = fixdiv((x - abs_y) , (x + abs_y));
angle = ONEQTR_PI;
}
//angle =angle + (0.1963f * r * r - 0.9817f) * r;
angle += fixmulf( (fixmulf(OP1,fixmulf(r,r))- OP2), r);
if ( y < 0 )
return( -angle ); // negate if in quad III or IV
else
return( angle );
}