Why does the .Net Math.Cos function give me a different answer than a calculator?

I am so confused and I thought that my program was spelled incorrectly, but now I understood where the problem is.

I get two different values ​​for the cosine of a number.

For example, for this number 329.85

on the calculator I get 0.8647 .....

in my C # program, I get -0.99985159087810649 using this expression

double asnwer = Math.Cos(329.85);

Can someone explain what is happening? Or what am I doing wrong?

+4
source share
3 answers

In C # and the .NET Framework, trigonometric math methods are for radians.

http://msdn.microsoft.com/en-us/library/system.math.cos(v=vs.110).aspx

:

double DegreesToRadians(double degrees)
{
   return degrees * Math.PI / 180.0;
}

:

Math.Cos(DegreesToRadians(329.85));
+9

( ), Math.Cos # .

: Math.Cos(329.85*2*Math.PI/360)

+6

Your calculator accepts radians ... NET - degrees.

-2
source

Source: https://habr.com/ru/post/1527048/


All Articles