Jump to content
  • Advertisement
Sign in to follow this  
Great_White

Why are sinf() or cosf() functions slow?

This topic is 4065 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Quote:
Original post by Great_White
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?


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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!