快速的sincos例程 [英] Fast sincos routine

查看:117
本文介绍了快速的sincos例程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


有没有人建议在哪里找到一个好的sincos

例程(即计算罪和cos的例程) a / b
给出的参数)写在c?


谢谢,

Oc ********** @ yahoo.com

解决方案

< blockquote> OcelotIguana写道:


您好,

有没有人建议在哪里找到一个好的sincos
例程(即计算的例程)用c写的一个论证的罪和cos是用吗?

谢谢,

Oc ********** @ yahoo.com




你有数学吗?可以使用协处理器还是必须是软件?

如果是前者,它们大多都具有内置功能,所以你最好用汇编程序来完成它。

如果你想完全用高级别的话来做el C,使用以下方案:


1.将角度x减小到范围(0,pi / 2)


2。设z = tan(x / 2),

然后sin(x)= 2 * z /(1 + z * z),cos(x)=(1-z * z)/( 1 + z * z)。


3.使用连续分数表示计算z,w = u * u:


tan( u)= u /(1-w /(3-w /(5-w /(7 -...))))

连续分数的唯一问题是每一步都需要

a分区,Pentia比分数慢得多。


如果你的系统已经有tan(u),你就可以免费回家了:计算tan(x / 2)

,然后是正弦和余弦,有2格,2次乘法和2次加法。

相对于评估切线,算术的时间可以忽略不计。

-

Julian V. Noble

物理荣誉教授
jv *@lessspamformother.virginia.edu

^^^^^^^^^^^^^^^^^^
http://galileo.phys.virginia.edu/~jvn/


上帝不愿意做任何事情,从而带走我们的免费wiil

以及那些合法属于我们自己的荣耀。

- N. Machiavelli,The Prince。


OcelotIguana写道:


有没有人有建议在哪里找到一个好的sincos
例程(即一个用c计算用来计算给定参数的sin和cos的例程?




void sincos(const double x,double * sinval,double * cosval)

{

* sinval = sin(x);

* cosval = sqrt(1.0 - * sinval * * sinval);

}


-

Chuck F(cb********@yahoo.com)(cb ********@worldnet.att.net)

可用于咨询/临时嵌入式和系统。

< http://cbfalconer.home。 att.net>使用worldnet地址!


文章< 40 *************** @ yahoo.com> ;, CBFalconer写道:

OcelotIguana写道:


有没有人建议在哪里找到一个好的sincos
例程(即计算两者的例程)用c语言写成的论证的罪行和cos?









{
* sinval = sin(x);
* cosval = sqrt(1.0 - * sinval * * sinval);
}




如果你需要完美的准确度,并且/或者你的计算机具有良好的浮动点硬件,这个例程很难被击败。仅仅好的

精度,并且只使用整数硬件,你需要一个CORDIC算法,

,它通常不是标准库的一部分。我已经使用了

Ken Turkowski的副本,他已经发布了
http://www.worldserver.com/turk/opensource/Cordic.c.txt

它不需要许多变化[*]让它用它来编译

gcc -std = c99 -pedantic -W -Wall -Wredundant-decls -Wpointer-arith \

-Wcast -qual -Wshadow -O2

对于使用StrongARM的嵌入式工作,这为我节省了一桶CPU周期。


- Larry

[*]如果你想要我的补丁副本,请给我发电子邮件。


Hello,

Does anyone have any suggestions for where to find a good sincos
routine (i.e. a routine that calculates both the sin and cos of a
given argument) written in c?

Thanks,

Oc**********@yahoo.com

解决方案

OcelotIguana wrote:


Hello,

Does anyone have any suggestions for where to find a good sincos
routine (i.e. a routine that calculates both the sin and cos of a
given argument) written in c?

Thanks,

Oc**********@yahoo.com



Do you have a math co-processor available or does it have to be software?
If the former, they mostly have the function built in, so you had best
do it in assembler.

If you want to do it entirely in high-level C, use the following scheme:

1. Reduce the angle x to the range (0, pi/2)

2. Let z = tan(x/2),
then sin(x) = 2*z/(1+z*z), cos(x) = (1-z*z)/(1+z*z) .

3. Compute z using the continued fraction representation, with w = u*u :

tan(u) = u/(1-w/(3-w/(5-w/(7-...) ) ) )

The only problem with continued fractions is that each step requires
a division, which on Pentia is much slower than a multiply.

If your system already has tan(u), you are home free: compute tan(x/2)
and then sine and cosine with 2 divisions, 2 multiplications and 2 additions.
The arithmetic will take negligible time relative to evaluating the tangent.
--
Julian V. Noble
Professor Emeritus of Physics
jv*@lessspamformother.virginia.edu
^^^^^^^^^^^^^^^^^^
http://galileo.phys.virginia.edu/~jvn/

"God is not willing to do everything, and thereby take away our free wiil
and that share of glory that rightfully belongs to ourselves."
-- N. Machiavelli, "The Prince".


OcelotIguana wrote:


Does anyone have any suggestions for where to find a good sincos
routine (i.e. a routine that calculates both the sin and cos of a
given argument) written in c?



void sincos(const double x, double *sinval, double *cosval)
{
*sinval = sin(x);
*cosval = sqrt(1.0 - *sinval * *sinval);
}

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!


In article <40***************@yahoo.com>, CBFalconer wrote:

OcelotIguana wrote:


Does anyone have any suggestions for where to find a good sincos
routine (i.e. a routine that calculates both the sin and cos of a
given argument) written in c?



void sincos(const double x, double *sinval, double *cosval)
{
*sinval = sin(x);
*cosval = sqrt(1.0 - *sinval * *sinval);
}



If you need perfect accuracy, and/or your computer has good floating
point hardware, that routine will be hard to beat. For merely good
accuracy, and with integer-only hardware, you need a CORDIC algorithm,
which is not normally part of the standard library. I have used
Ken Turkowski''s copy, which he has posted at
http://www.worldserver.com/turk/opensource/Cordic.c.txt
It doesn''t take many changes[*] to get it to compile with
gcc -std=c99 -pedantic -W -Wall -Wredundant-decls -Wpointer-arith \
-Wcast-qual -Wshadow -O2
For embedded work with a StrongARM, this saved me a bucket of CPU cycles.

- Larry
[*] If you want a copy of my patches, e-mail me.


这篇关于快速的sincos例程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆