3

I import "math.h".

I can use the cos function, but when I execute cos(0.321139585333178) the result is 0.948876

If I use the calculator in Mac or use a normal calculator, the result is 0.999984292347418

Can anyone help me to solve that problem?

Windows programmer
  • 7,871
  • 1
  • 22
  • 23
suk
  • 31
  • 2
  • since I consider radians the default, the right answer is 0.94887639....; trigonometric function usually take radians, but degrees versions can be easily implemented – ShinTakezou Jun 14 '10 at 07:45

1 Answers1

19

You're confusing degrees with radians.

cos(0.321139585333178 degrees) = 0.999984292

cos(0.321139585333178 radians) = 0.948876326

  • To convert from radians to degrees, multiply by 180/π.
  • To convert from degrees to radians, multiply by π/180.
Mark Byers
  • 811,555
  • 193
  • 1,581
  • 1,452
  • 1
    Backwards. It should be "multiply by 180/π", "divide by 180/π" – Matthew Flaschen Jun 14 '10 at 07:58
  • @Matthew Flaschen: +1 well spotted. It's amusing because I was going to work out the conversion myself but decided that there was a small risk I'd get it backwards so instead I decided to copy it from Wikipedia which is of course peer reviewed and for such a simple thing must be correct. http://en.wikipedia.org/wiki/Radian#Conversions . I will be more careful in future. ;) – Mark Byers Jun 14 '10 at 08:10
  • @Matthew Flaschen: I see you have now fixed it in Wikipedia. :) – Mark Byers Jun 14 '10 at 08:17
  • and warned the vandal, and semi-protected it. :) – Matthew Flaschen Jun 14 '10 at 08:25