deepi
deepi

Reputation: 1081

how to find sinh value in degree in javascript

for sinh(30) i did

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

above one is giving value in radian correctly. For degree if do

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

but in scientific calculator for sinh(30)

sinh(30)=0.547853473888

what is the logic to find sinh value in javascript

Upvotes: 1

Views: 548

Answers (2)

epascarello
epascarello

Reputation: 207501

30 should be in radians, not degrees in the first one.

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);

Upvotes: 2

Alnitak
Alnitak

Reputation: 339816

The degrees to radians conversion needs to be applied to the input to the sinh expression, not its result.

Also, the conversion you have is from radians to degrees - you need the opposite:

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

Upvotes: 1

Related Questions