触发函数的计算成本 [英] Computational cost of trig functions

查看:53
本文介绍了触发函数的计算成本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
三角函数如何工作?

Possible Duplicate:
How do Trigonometric functions work?

Sin,Cos,Tan和Atan等触发函数的计算实际上是什么?

What actually goes into the computation of trig functions like Sin, Cos, Tan and Atan?

我认为我在代码中找到了一个优化,可以避免使用这些函数中的任何一个,而使问题围绕坡度而不是角度.因此,这意味着要执行几次除法运算,以代替上面的trig函数.但是我想更多地了解这些触发函数所包含的内容,以便可以比较我的新代码(从基本数学运算的角度来看).或者,也许我只是发现一种更circuit回的方式来做同一件事,或者更糟糕的是,引入了一种效率更低的方法.

I think I've found an optimization in my code where I can avoid using any of these functions and base the problem around slope instead of angles. So that means a couple division operations in place of the above trig functions. But I'd like to know more about what goes into those trig functions so that I can compare my new code (from the perspective of number of basic math ops). Or maybe I've just found a more circuitous way of doing the same thing, or worse, introduced a less efficient method.

使用C ++和Python,但我想它们与语言无关,数学运算的成本相对于最原始的运算而言.

Using C++ and Python but I imagine these is fairly language agnostic with math operation cost being relative to the most primitive operations.

推荐答案

现代的x86处理器在其指令集中包含了trig函数,但是执行它们需要很多周期.因此, if 您使用的是这样的处理器,并且如果您的代码中没有依赖项(即,您不需要一次sin计算的结果即可启动下一个sin),那么您可能不会比直接使用sin和cos快得多,因为它们将完全流水线化,达到每个周期1的有效速率.

Modern x86 processors include trig functions in their instruction set, but they take many cycles to execute. So if you're on such a processor, and if you have no dependencies in your code (i.e. you don't need the result of one sin computation in order to start the next one), then you probably won't get much faster than using sin and cos directly, as they will be fully pipelined, achieving an effective rate of 1 per cycle.

这篇关于触发函数的计算成本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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