Using cosine, sine, tangent etc. in C++

Started by
12 comments, last by The Magical Pot 10 years, 8 months ago

ULTRA-PEDANT ALERT:

There is something called the inverse cosine, which is a multivalued function. The C++ function std::acos returns the principal value of this multivalued function (in C++98 this is only defined for real values between -1 and 1, but in C++11 there is a version that works for any complex number).

Similarly the square root is a multivalued function that is the inverse of the function that maps x to x2, and std::sqrt returns the principal value.

Advertisement

M_PI is not standard, so no, you can't assume it's there (indeed, in my system headers it's not present, at least not when I enable C99 mode). There's no option but to define pi manually.

Or to use a library that defines it. Ex: boost has a large number of mathematical constants defined.

M_PI is not standard, so no, you can't assume it's there (indeed, in my system headers it's not present, at least not when I enable C99 mode). There's no option but to define pi manually.

Or to use a library that defines it. Ex: boost has a large number of mathematical constants defined.

As an aside, and certainly not a question for the beginners forum, but...

How are the boost math libraries in this situation? Are they performant enough for real-time game usage?

Also, why the hell isn't performant a word? It really should be.

I asked a very simple question and I got the answer that I needed 5 minutes after posting. I know that you shouldn't ask stuff that you can easily find on google or whatever, but for some reason i did and someone was nice enough to answer my question. I'll gladly take delete this post if anyone says that I have to because I already got my answer.

This conversation is pointless.

This topic is closed to new replies.

Advertisement