Why are sinf() or cosf() functions slow?
If the library implementation that you use doesn't map sinf and cosf to the FPU instructions whenever available, your best solution is to get yourself a better library implementation from the web.
Depending on the compiler, you may have the option to automatically replace calls to sinf() and related functions directly with FPU calls. For example, with MSVC you should be able to specify /Oi /Og to get the trigonometric intrinsics.
Quote:Original post by SiCrane
Depending on the compiler, you may have the option to automatically replace calls to sinf() and related functions directly with FPU calls. For example, with MSVC you should be able to specify /Oi /Og to get the trigonometric intrinsics.
Oh I didnt know that. Is there any preprocessor directive for this?
Quote:Original post by Great_WhiteQuote:Original post by SiCrane
Depending on the compiler, you may have the option to automatically replace calls to sinf() and related functions directly with FPU calls. For example, with MSVC you should be able to specify /Oi /Og to get the trigonometric intrinsics.
Oh I didnt know that. Is there any preprocessor directive for this?
Compiler optimizations are in your project settings.
Right click on your project name in the project tree.
edit: Note I'm talking about Visual Studio.
When you say "they are slow" and ask why:
1) how did you come to the conclusion that they are slow?
2) exactly how slow do you think they are?
3) is it really a problem?
1) how did you come to the conclusion that they are slow?
2) exactly how slow do you think they are?
3) is it really a problem?
Quote:Original post by ViperG
If you use visual studio 6 they are slow. Especially sqrt function, super slow.
On the other hand, using Visual Studio 6 is just begging for trouble...
They are slow because they are complex to compute. Simple as that.
If I ask you to compute 1 + 1 and sin(1) on paper you quickly realize that the latter just isn't trivial to write down. And neither is it for a computer. In fact computing a sine or cosine consists of many additions and multiplications. Just look at the Taylor series expansion.
When you don't need the exact result there are fast approximations though: Fast and accurate sine/cosine.
If I ask you to compute 1 + 1 and sin(1) on paper you quickly realize that the latter just isn't trivial to write down. And neither is it for a computer. In fact computing a sine or cosine consists of many additions and multiplications. Just look at the Taylor series expansion.
When you don't need the exact result there are fast approximations though: Fast and accurate sine/cosine.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement