没有合适的资源?快使用搜索试试~ 我知道了~
嵌入式系统中sin和cos的快速算法
4星 · 超过85%的资源 需积分: 15 90 下载量 183 浏览量
2009-05-07
08:21:31
上传
评论 1
收藏 3KB TXT 举报
温馨提示
试读
2页
嵌入式系统中CPU通常不能有计算一些数学函数的资本,本文提供了一种简洁的计算方法。
资源推荐
资源详情
资源评论
#define R1 -0.1666665668e+0
#define R2 0.8333025139e-2
#define R3 -0.1980741872e-3
#define R4 0.2601903036e-5
/****************************************************************************/
/* COS() - Cosine */
/* Based on the algorithm from "Software Manual for the Elementary
/* Functions", Cody and Waite, Prentice Hall 1980, chapter 8.
/* N = round(x / PI + 1/2) - 0.5 */
/* f = x - N * PI */
/* g = f * f */
/* R = polynomial expression */
/* result = f + f * R */
/* if N is even, result = - result */
/* This will return the wrong result for x >= MAXINT * PI
/****************************************************************************/
double cos(double x)
{
int sign; /* the sign of the result */
double xn, f, g, rg, result;
int n;
/**************************************************************************/
/* cos(x) = cos(-x)
/**************************************************************************/
x = fabs(x);
/**************************************************************************/
/* n = round(x/PI + 1/2) (can be rounded this way, since positive number) */
#define R2 0.8333025139e-2
#define R3 -0.1980741872e-3
#define R4 0.2601903036e-5
/****************************************************************************/
/* COS() - Cosine */
/* Based on the algorithm from "Software Manual for the Elementary
/* Functions", Cody and Waite, Prentice Hall 1980, chapter 8.
/* N = round(x / PI + 1/2) - 0.5 */
/* f = x - N * PI */
/* g = f * f */
/* R = polynomial expression */
/* result = f + f * R */
/* if N is even, result = - result */
/* This will return the wrong result for x >= MAXINT * PI
/****************************************************************************/
double cos(double x)
{
int sign; /* the sign of the result */
double xn, f, g, rg, result;
int n;
/**************************************************************************/
/* cos(x) = cos(-x)
/**************************************************************************/
x = fabs(x);
/**************************************************************************/
/* n = round(x/PI + 1/2) (can be rounded this way, since positive number) */
cococecil
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页