I am currently writing a calculation program for the Windows Phone. One of the calculations if to find the tangent of a number the user enters times another number the user enters.
The problem is when I typed in 1*tan(45) (which is 1) it returns 1.6…. I ran this through the debugger a couple of times. I can see 45 going into Math.Tan, and the output is 1.6.
Please help me identify the cause of this problem. Code below.
double result;
double multiplying = Convert.ToDouble(txtMultTan.Text);
double tangent = Convert.ToDouble(txtTan.Text);
result = multiplying * (Math.Tan(tangent));
txtResult.Text = "Answer= " + result;
I’m sure, if you read the documentation, you’ll discover that the trig functions expect the input to be in radians. To convert from degrees to radians, multiply by
pi/180.0, using whatever pre-defined constant ofpiyour math library offers.