C ++(和数学):三角函数的快速逼近 [英] C++ (and maths) : fast approximation of a trigonometric function

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

问题描述

我知道这是一个反复出现的问题,但是我还没有真正找到有用的答案。我基本上是在寻找C ++中函数 acos 的快速近似值,我想知道我是否可以大大超越标准函数。

I know this is a recurring question, but I haven't really found a useful answer yet. I'm basically looking for a fast approximation of the function acos in C++, I'd like to know if I can significantly beat the standard one.

但是你们中的一些人可能对我的特定问题有深刻的见解:我正在写一个科学程序,我需要非常快。主要算法的复杂性归结为以下表达式的计算(多次使用不同的参数):

But some of you might have insights on my specific problem: I'm writing a scientific program which I need to be very fast. The complexity of the main algorithm boils down to computing the following expression (many times with different parameters):

sin( acos(t_1) + acos(t_2) + ... + acos(t_n) )

其中 t_i 是已知的实数(双数), n 很小(例如小于6)。我需要至少1e-10的精度。我目前正在使用标准 sin acos C ++函数。

where the t_i are known real (double) numbers, and n is very small (like smaller than 6). I need a precision of at least 1e-10. I'm currently using the standard sin and acos C++ functions.

您认为我可以以某种方式显着提高速度吗?对于那些了解一些数学的人,您认为扩展该正弦值以得到 t_i (仅涉及平方根)的代数表达式是否明智? )?

Do you think I can significantly gain speed somehow? For those of you who know some maths, do you think it would be smart to expand that sine in order to get an algebraic expression in terms of the t_i (only involving square roots)?

谢谢您的回答。

推荐答案

如乔纳斯Wielicki在评论中提到,您无法进行很多精确的权衡。

As Jonas Wielicki mentions in the comments, there isn't much precision trade-offs you can make.

您最好的选择是尝试使用处理器内在函数(如果您的编译器尚未执行此操作),并使用一些数学运算来减少所需的计算量。

Your best bet is to try and use the processor intrinsics for the functions (if your compiler doesn't do this already) and using some math to reduce the amount of calculations necessary.

同样重要的是,将所有内容保持为CPU友好格式,确保没有缓存丢失等。

Also very important is to keep everything in a CPU-friendly format, make sure there are few cache misses, etc.

如果要计算大量功能,例如 acos 可能正在移动您可以选择使用GPU?

If you are calculating large amounts of functions like acos perhaps moving to the GPU is an option for you?

这篇关于C ++(和数学):三角函数的快速逼近的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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