0% found this document useful (0 votes)
191 views

C# Math Cos Different Values From Calculator - Stack Overflow PDF

The document discusses why values returned by Math.Cos in C# differ from those on calculators. Math.Cos takes angles in radians, not degrees, unlike most calculators. To get the correct value from Math.Cos, the angle must first be converted from degrees to radians by multiplying by Math.PI/180. Responses provide this explanation and an example of how to make the conversion.

Uploaded by

Davisson9
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
191 views

C# Math Cos Different Values From Calculator - Stack Overflow PDF

The document discusses why values returned by Math.Cos in C# differ from those on calculators. Math.Cos takes angles in radians, not degrees, unlike most calculators. To get the correct value from Math.Cos, the angle must first be converted from degrees to radians by multiplying by Math.PI/180. Responses provide this explanation and an example of how to make the conversion.

Uploaded by

Davisson9
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

signup login tour help

xDismiss

JointheStackOverflowCommunity

Stack Overflow is a community of 6.6 million


programmers, just like you, helping each other.
Join them it only takes a minute:

Signup

c#mathcosdifferentvaluesfromcalculator

Iamtryingtodoaprecisiontypeofprogramwhereiencounteredvaluestherewerewrongandhavebeenabletopinpointtheproblemarea.The
Math.cosvaluesdifferfromthecalculatorvaluesandhowcanicorrectthisforinstance

Math.Cos(28.545742)

givesthevalue0.963394351754924butonallothercalculatorsitgivesmeacorrectvalueof0.8784358937whichisperfectsinceitcompletes
theexpectedprogramoutput.HowcanIgetMath.CostogivemetheanswersIwant?andthisismyfirsttimemessingwithC#mathfunctions.

c# math

askedJan2'14at21:43
user1591668
537 1 6 21

4 Iwouldguessthat C# isworkinginradians,but"allothercalculators"areworkingindegrees.
TeepeemmJan2'14at21:46

1 Youneedtospecifytheangleinradians,notdegrees.BlorgbeardJan2'14at21:46

Theothercommentsarecorrect... google.com/#q=cosine+28.545742alsoshowsthe0.96..answer,using
radians.EricKingJan2'14at21:48

Thankseveryonethatsolvedtheanswer user1591668 Jan2'14at22:02

3Answers

Math.Cos() isusingradianswhileyourcalculatorisusingdegrees.Asimplewaytoconvertfrom
degreestoradiansisdegrees*(pi/180).

Incode:

Math.Cos(28.545742*(Math.PI/180))

editedJan2'14at21:52 answeredJan2'14at21:48
connor
35.5k 16 98 120

Youneedtospecifytheangleinradians,notdegrees.

Thereare 2*pi radiansinacircle,and360degrees.Sotoconvertdegreestoradians,divideby


360andmultiplyby 2*pi (simplified:multiplyby pi/180 ):

Math.Cos(28.545742*Math.PI/180f)

Willgiveyouthecorrectanswer.

answeredJan2'14at21:49
Blorgbeard
62.6k 31 160 222

Math.Cos functiontakesvaluesinradians.

HereisthedetailedexplanationonMSDNsiteaboutthefunction.

editedJan2'14at22:27 answeredJan2'14at21:54
Rakhi
134 4

EverylanguagethatIknowofFORTRAN,C,C++,Java,C#,Python,Javascriptallexpectanglesin
radians.duffymoJan2'14at22:09

You might also like