快速实现c ++的三角函数 [英] Fast implementation of trigonometric functions for c++

查看:186
本文介绍了快速实现c ++的三角函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简短版本:我想知道是否有比 math.h 中包含的更快的标准三角函数的实现。

Short version: I'd like to know whether there are implementations of the standard trigonometric functions that are faster than the ones included in math.h.

长版本:我有一个在数字上很重的程序(这是一个物理模拟),需要调用三角函数,主要是 sin cos ,很多。目前我只是使用 math.h 中包含的实现。分析表明,对这些函数的调用的成本比我预期的要高(希望)。

Long version: I got a program that's quite heavy on numerics (it's a physics simulation) and that needs to call trigonometric functions, mostly sin and cos, a lot. Currently I'm simply using the implementations included in math.h. Profiling shows that the calls to these functions cost more than I was expecting (hoping).

虽然在代码的其他部分有很多可以优化的空间,有更快的 sin cos 可能给我一些额外的百分比..所以,你们有什么建议吗? >
在另一个帖子中,建议使用自制查找表。但也许有替代品?

While there is most certainly plenty of room for optimization in other parts of the code, having faster sin and cos might give me some additional percent.. So, do you guys have any suggestions?
In another post the usage of self-made lookup tables is suggested. But maybe there are alternatives? Or ready-made and well tested lookup solutions in some libraries?

推荐答案

这里有一些关于如何做幂级数近似的好的幻灯片(不是泰勒系列)的trig函数: http://www.research.scea.com/ gdc2003 / fast-math-functions.html

Here are some good slides on how to do power series approximations (NOT Taylor series though) of trig functions: http://www.research.scea.com/gdc2003/fast-math-functions.html

它面向游戏程序员,这意味着准确性会因性能而牺牲,但您应该能够添加另一个

It's geared towards game programmers, which means accuracy gets sacrificed for performance, but you should be able to add another term or two to the approximations to get some of the accuracy back.

关于这一点的好处是,你也应该能够将其扩展到SIMD,以便你可以计算4个值的sin或cos在一个(2,如果你使用双精度)。

The nice thing about this is that you should also be able to extend it to SIMD easily, so that you could compute the sin or cos of 4 values at one (2 if you're using double precision).

希望有帮助...

这篇关于快速实现c ++的三角函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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