1. 程式人生 > >Math.cos()和Math.sin()和Math.atan()

Math.cos()和Math.sin()和Math.atan()

數學上:

cos(60°) = 0.5

js:

Math.cos(Math.PI/180*60) = 0.5000000000000001

原因:

近似值,為什麼不直接為0.5 呢?因為Math.PI其實也只是PI的近似值,如果是PI的精確值的話,結果肯定是0.5了。

數學上:

tan(45°) = 1

js:

Math.atan(1)*180/Math.PI = 45//已知正切值,求角度