# cos() returning wrong result?

• 08-20-2002
rmullen3
cos() returning wrong result?
Okay... I'm a bit confused as to why cos(330) returns -0.991199 and using a calculator I find cos (330) returns 0.866025403784438646763723170752936 (0.866)

The result from the calculator is the one I want... why are these results different? What can I do to make cos() function differently?
• 08-20-2002
rmullen3
hehe.. Soon after posting I found that cos() accepts radians not degrees. So I have to multiply by pi divided by 180 to convert to degrees..

So my question has changed, is there any library which will return cos() in degrees so I don't have to perform this conversion every time?
• 08-20-2002
rmullen3
Sorry... I'm trying to go for max speed and I assumed there would be a library function that could do it better than I could
• 08-20-2002
MrWizard
Quote:

Originally posted by rmullen3
Sorry... I'm trying to go for max speed and I assumed there would be a library function that could do it better than I could
Nope, just make a macro that converts the number for you. This will make the conversion pretty fast. Also use cosf( ) if you do not need the double precision offered by cos( ). That will get you some extra speed. Also define them as intrisic if your compiler allows.
• 08-20-2002
Prelude
>Nope, just make a macro that converts the number for you.
Why use a macro in C++ when inline functions are just as good and far less cryptic?

-Prelude
• 08-20-2002
BMJ
... and when the function already does it?
• 08-21-2002
MrWizard
Quote:

Originally posted by Prelude
>Nope, just make a macro that converts the number for you.
Why use a macro in C++ when inline functions are just as good and far less cryptic?

-Prelude

Well I usually use them when I need a function to be typeless. Sure for this case you can use inline functions if you prefer.

>>... and when the function already does it?

Umm... the cos( ) and cosf( ) functions do not convert degrees to radians for you.