1

To start I'm not that well versed in javascript and I'm trying to convert this complex excel formula to javascript without any luck.

=DEGREES(ASIN(SIN(RADIANS(59.036))*SIN(RADIANS(150))))/2

Here's what I have so far

var x = DEGREES(Math.asin(Math.sin(RADIANS(59.036))*Math.sin(RADIANS(150))))/2

Obviously, DEGREES and RADIANS are wrong and I can't figure what the javascript equivalent would be.

(BTW the correct answer is 5.831)

Xymostech
  • 9,710
  • 3
  • 34
  • 44
  • Take a look at [this](http://stackoverflow.com/questions/9705123/how-can-i-get-sin-cos-and-tan-to-return-degrees-instead-of-radians). – Boris the Spider Mar 23 '13 at 21:11

2 Answers2

1

Well, you could write your own DEGREES and RADIANS functions, which only involve a little math:

function degrees(x) { return x * 180 / Math.PI; }
function radians(x) { return x * Math.PI / 180; }

var x = degrees(Math.asin(Math.sin(radians(59.036))*Math.sin(radians(150))))/2;
Xymostech
  • 9,710
  • 3
  • 34
  • 44
1

Define both functions yourself. They are both trivial to implement.

function DEGREES(radians){
  return (radians * 180 / Math.PI);
}
function RADIANS(degrees){
  return (degrees / 180 * Math.PI);
}
Seth Battin
  • 2,811
  • 22
  • 36