如何在javascript中找到学位的sinh值

时间:2013-05-02 12:40:49

标签: javascript

对于sinh(30)我做了

var rad=(Math.exp(30) - Math.exp(-30)) / 2;

以上是正确给出弧度值。对于学位如果

 var deg=rad * (180/Math.PI);// giving 306144945697592.7  

但是在sinh的科学计算器中(30)

sinh(30)=0.547853473888

在javascript中找到sinh值的逻辑是什么

2 个答案:

答案 0 :(得分:2)

30应该是弧度,而不是第一个度数。

function deg2rad (radAngle) {
  return radAngle * .017453292519943295;
}
function sinh (arg) {
  return (Math.exp(arg) - Math.exp(-arg)) / 2;
}
var x = deg2rad(30);
var ans = sinh(x);
alert(ans);

答案 1 :(得分:1)

弧度转换的度数需要应用于输入sinh表达式,而不是结果。

此外,你所拥有的转换是从弧度到度数 - 你需要相反:

Math.sinh = function(x) { return (Math.exp(x) - Math.exp(-x)) / 2; }

Math.deg2rad = function(theta) { return theta * Math.PI / 180; }

> Math.sinh(Math.deg2rad(30))
0.5478534738880397