JavaScript - Trackback Math.cos (30)

Math.acos(Math.cos(30))will not return 30, but Math.acos(Math.cos(0.7))will return 0.7 ... How can I do it right?

+4
source share
2 answers

This is because the input / parameter of the function cosmust not be in degrees in radians .

From MDN docs :

Parameters

x: number indicated in units of radians .

So, before calling the function, convert the input to radians.

Use formula Radians = Degrees * ( Pi / 180)

+6
source

Convert 30 degrees to radians

var radians = 30 * Math.PI / 180;
document.write(radians);
var result = Math.cos(radians);
var andBackToRadians = Math.acos(result);

document.write('<p>'+result+'</p>');
document.write('<p>' + andBackToRadians + '</p>');
0
source

Source: https://habr.com/ru/post/1619646/


All Articles