Javascript Math.cos shows different answers compared to a scientific calculator

I created a program in javascript that calculates vector coordinates, everything was smooth, since I have the correct formula, but when I try to match cosine 143.1301 using Math.cos in javascript, it returns 0.1864 instead of 0.7999 from a scientific calculator why? can anyone explain me why? and also please give me a solution to this problem ... thanks in advance ... :) here, a sample of my code

function cyltoxec(a) { ans = Math.cos(a); return ans.toFixed(4); } var = x; return cyltoxec(x); 
+6
source share
2 answers

Trigonometric functions in JavaScript (and indeed in most mathematical expressions and programming) use radians as an angular block, not degrees.

There are 2 * Pi radians at 360 degrees. Thus, the cosine of degree a is

 Math.cos(a * Math.PI/180) 
+15
source

Math.cos expects its argument to be in radians, not degrees. Instead, try Math.cos(a * Math.PI/180) .

+5
source

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


All Articles