论坛元老
- 积分
- 5246
- 金钱
- 5246
- 注册时间
- 2012-8-25
- 在线时间
- 1024 小时
|
[mw_shl_code=c,true]#define Pi 3.1415926535897932384626433832795
static inline double power_d( double x )
{
return ( x * x );
}
double sin_Taylor( double x)
{
double x_2= power_d(x);
// return (x*(1.0-x_2*(1.0/6-x_2*(1.0/120- x_2*(1.0/5040 )))));
//return (x*(1.0-x_2*(1.0/6-x_2*(1.0/120- x_2*(1.0/5040-x_2*(1.0/362880 ))))));
return (x*(1.0-x_2*(1.0/6-x_2*(1.0/120- x_2*(1.0/5040-x_2*(1.0/362880 -x_2/39916800 ))))));
}
double cos_Taylor( double x)
{
double x_2= power_d(x);
// return (1.0-x_2*(1.0/2-x_2*(1.0/24- x_2*(1.0/720-x_2*1.0/40320))));
return (1.0-x_2*(1.0/2-x_2*(1.0/24- x_2*(1.0/720-x_2*(1.0/40320 -x_2/3628800 )))));
}
double sin_q(double x) // 周期是 2*Pi
{
while(x> Pi) {x-=2*Pi;}
while(x<-Pi) {x+=2*Pi;}
int fuhao=1;
if(x<0)
{
x=-x;
fuhao=-1;
}
if(x>Pi/2)
{
x= Pi-x;
}
if(x< Pi*51/180)//Pi/4)
{
x= sin_Taylor(x);
}
else
{
x= cos_Taylor(x-Pi/2);
}
if(fuhao==-1)
{
x=-x;
}
return x;
}
double cos_q(double x)
{
return (sin_q(x + Pi/2) );
}
[/mw_shl_code]
|
|