Reputation: 25928
How do I perform the following math problem in Javascript:
Tan(x) = 450/120;
x = 75;
// In my calculator I use tan^-1(450/120) to find the answer
// How do I perform tan^-1 in javascript???
My javascript code is outputting incorrect results:
var x = Math.atan(450/120);
alert(x); // says x = 1.3101939350475555
// Maybe I am meant to do any of the following...
var x = Math.atan(450/120) * (Math.PI/2); // still wrong answer
var x = Math.tan(450/120); // still wrong answer
Upvotes: 3
Views: 7200
Reputation: 838
var x = Math.atan(450/120);
Gives the answer 75 degrees in radians, which is: 1.3101939350475555
To get the correct answer just convert to degrees:
var x = Math.atan(450/120) * (180/Math.PI);
alert(x); // says x is 75.06858282186245
Upvotes: 10