Math.sin expects the input to be in radian, but you are expecting the result of 90 degree. Convert it to radian, like this
console.log(Math.sin(90 * Math.PI / 180.0));
# 1
As per the wikipedia's Radian to Degree conversion formula,
Angle in Radian = Angle in Degree * Math.PI / 180
Answer from thefourtheye on Stack OverflowWhat does Math.sin return in JavaScript?
Why does Math.sin(Math.PI) not return exactly 0?
What happens if I give a string to Math.sin?
Videos
Math.sin expects the input to be in radian, but you are expecting the result of 90 degree. Convert it to radian, like this
console.log(Math.sin(90 * Math.PI / 180.0));
# 1
As per the wikipedia's Radian to Degree conversion formula,
Angle in Radian = Angle in Degree * Math.PI / 180
The sin function in Javascript takes radians, not degrees. You need to convert 90 to radians to get the correct answer:
Math.sin(90 * (Math.PI / 180))
Should not
Math.sin(Math.PI));
be 0?
It returns 1.2246467991473532E-16
Parameters are assumed to be in radians, not degrees.
Try
Math.sin(Math.PI * (30/180));
A comment below notes that pre-computing the ratio π/180 is a good idea. One could add a companion to Math.sin that works on degrees this way:
Math.dsin = function() {
var piRatio = Math.PI / 180;
return function dsin(degrees) {
return Math.sin(degrees * piRatio);
};
}();
(Some people don't like extending built-in objects, but since one doesn't instantiate Math instances — at least, I don't — this doesn't seem terribly offensive.)
Math.sin works in radians, I guess your calculator is in degrees.