Public Group

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

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

## Recommended Posts

Hi!

I don't need to go into detail of what I'm doing to get an answer on this question. All I'm wondering is what function in the cmath.h header that corresponds to cos-1, sin-1, tan-1 on a calculator.

For example: if I want to calculate cos-1(200/100) to get the degree of an angle, which function do I use since functions cos(), sin(), tan() in C++ corresponds to cos, sin, tan on a calculator and not cos-1, sin-1, tan-1.

Hopefully, that was not a load of incohesive dribble, but let me know if you want me to explain some more if it was :)

##### Share on other sites
It should also be noted that using "cmath.h" is in general inadvisable when working with C++. C++ has the "cmath" header. Not only does it respect namespaces, it also has several useful overloads for types other than just doubles.

##### Share on other sites

Seriously it took 5 seconds to do a Yahoo search  using keywords "c++ arc cosine"  to find this info.

Everyone doesn't study math in english, I didn't know that "cos-1" was "arc cosine" in english.

Edited by The Magical Pot

##### Share on other sites

Seriously it took 5 seconds to do a Yahoo search  using keywords "c++ arc cosine"  to find this info.

Everyone doesn't study math in english, I didn't know that "cos-1" was "arc cosine" in english.

No, you don't get to play the foreigner card this time: Google finds relevant information using "C++ inverse cosine", "C++ inverse cos", "C++ cos^-1" and even "C++ cos-1".

##### Share on other sites

Not to mention you're taught that in math class...

That said:

EDIT: Oh, and pi is 3.14159... which is M_PI I think in math.h / . You can also use

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.

Also huh, selective quote will eat anything between < and >...

##### Share on other sites

Seriously it took 5 seconds to do a Yahoo search  using keywords "c++ arc cosine"  to find this info.

Everyone doesn't study math in english, I didn't know that "cos-1" was "arc cosine" in english.

No, you don't get to play the foreigner card this time: Google finds relevant information using "C++ inverse cosine", "C++ inverse cos", "C++ cos^-1" and even "C++ cos-1".

You don't even need to add any of the inverse variants, a plain reference page for sin or cos will often refer to the inverse functions, or, since he mentioned the relevant header, list the functions in said header to look through.

##### Share on other sites

The cosine function has no inverse! arccos(x) [a.k.a. acos(x), cos-1(x)] is the inverse of the restriction of the cosine function to a suitable range (in this case, [0, pi]). EDIT: You won't normally see an analysis textbook use cos-1 for that reason, they usually use arccos.

For a function to have an inverse it must be either strictly increasing or decreasing so there is a 1-1 mapping from the domain to the range.

Similarly sqrt(x) is not the inverse of f(x) = x2, since it only returns the positive square root.

• 21
• 12
• 9
• 17
• 13