余弦浮点 [英] Cosine in floating point

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

问题描述

我想实现浮点正弦和余弦函数(但我没有浮点硬件)。

I am trying to implement the cosine and sine functions in floating point (but I have no floating point hardware).

由于我的处理器没有浮点硬件,也没有说明,我已经实现算法浮点乘法,除法,加法,减法,平方根。因此,这些都是我的工具已经提供给我实现正弦和余弦。

Since my processor has no floating-point hardware, nor instructions, I have already implemented algorithms for floating point multiplication, division, addition, subtraction, and square root. So those are the tools I have available to me to implement cosine and sine.

我用的方法CORDIC,在这个网站考虑
然而,我实现除法和平方根使用牛顿法,所以我希望用最有效的方法。

I was considering using the CORDIC method, at this site However, I implemented division and square root using newton's method, so I was hoping to use the most efficient method.

请不要告诉我只是去看看在一本书或纸上的存在,它们的存在不开玩笑。我要寻找的被称为是快速,高效的众所周知的算法的名称。

Please don't tell me to just go look in a book or that "paper's exist", no kidding they exist. I am looking for names of well known algorithms that are known to be fast and efficient.

推荐答案

首先,根据您的精度要求,这可能比你前面的问题相当fussier。

First off, depending on your accuracy requirements, this can be considerably fussier than your earlier questions.

现在,你已经被警告:你首先要减少的说法模PI / 2(或二皮音乐,或PI或π/ 4),以获得输入变成一个可管理的范围内。这是微妙的一部分。对于所涉及的问题一个很好的讨论,下载K.C.副本吴的的参数还原巨额参数:从优秀到最后一个比特的。 (在标题简单的谷歌搜索将让你的PDF)。这是非常可读的,确实说明为什么这是棘手的一项​​伟大的工作。

Now that you've been warned: you'll first want to reduce the argument modulo pi/2 (or 2pi, or pi, or pi/4) to get the input into a manageable range. This is the subtle part. For a nice discussion of the issues involved, download a copy of K.C. Ng's ARGUMENT REDUCTION FOR HUGE ARGUMENTS: Good to the Last Bit. (simple google search on the title will get you a pdf). It's very readable, and does a great job of describing why this is tricky.

这样做之后,你只需要在近似一个小范围在零附近,这是很容易通过多项式逼近完成的功能。泰勒级数会的工作,虽然它是低效的。截短的切比雪夫系列是容易计算和合理高效;计算极小极大近似更好。这是比较容易的部分。

After doing that, you only need to approximate the functions on a small range around zero, which is easily done via a polynomial approximation. A taylor series will work, though it is inefficient. A truncated chebyshev series is easy to compute and reasonably efficient; computing the minimax approximation is better still. This is the easy part.

我描述的那样,完全在整数,在过去已经实施的正弦和余弦准确(对不起,没有公开来源)。使用手动调整装配,结果在100次循环的邻里都在典型的处理器完全合理的。我不知道你有什么处理硬件(业绩大多会在你的硬件如何能迅速产生一个整数乘法的高位部分门)。

I have implemented sine and cosine exactly as described, entirely in integer, in the past (sorry, no public sources). Using hand-tuned assembly, results in the neighborhood of 100 cycles are entirely reasonable on "typical" processors. I don't know what hardware you're dealing with (the performance will mostly be gated on how quickly your hardware can produce the high part of an integer multiply).

这篇关于余弦浮点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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