C# Math Cos Different Values From Calculator - Stack Overflow PDF
C# Math Cos Different Values From Calculator - Stack Overflow PDF
xDismiss
JointheStackOverflowCommunity
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
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.
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